I am using Stripe API and webhooks to link payments to my website. I have a webhook listener at https://mywebsite.com/hook.php
. When I send a test webhook through Stripe's developer dashboard, I receive my expected response of hello world
.
However, in my list of webhook attempts, this request was not logged (this request was sent ~2 hours after the last request on this list.
Here is my PHP webhook code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('/var/www/html/vendor/autoload.php');
\Stripe\Stripe::setApiKey("sk_test_CHANGEDFORTHISSOQUESTION"); //test
// Retrieve the request's body and parse it as JSON
$payload = @file_get_contents("php://input");
// Return a response to acknowledge receipt of the event
http_response_code(200);
echo("hello world");
$endpoint_secret = "whsec_CHANGEDFORTHISSOQUESTION"; //test
$sig_header = $_SERVER["HTTP_STRIPE_SIGNATURE"];
$event = null;
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
// Do something with $event_json
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400); // PHP 5.4 or greater
exit();
} catch(\Stripe\Error\SignatureVerification $e) {
// Invalid signature
http_response_code(400); // PHP 5.4 or greater
exit();
}