我正在使用Stripe API和webhooks将付款链接到我的网站。我在https://mywebsite.com/hook.php
有一个webhook侦听器。当我通过Stripe开发人员仪表板发送测试Webhook时,收到了预期的hello world
响应。
但是,在我的Webhook尝试列表中,未记录此请求(此请求在此列表中的最后一个请求之后约2小时发送。
这是我的PHP Webhook代码:
<?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();
}