Я использую Stripe API и webhooks для привязки платежей к своему веб-сайту. У меня есть слушатель webhook на https://mywebsite.com/hook.php
. Когда я отправляю тестовый веб-крючок через инструментальную панель разработчика Stripe, я получаю ожидаемый ответ hello world
.
Однако в моем списке попыток подключения к Интернету этот запрос не был зарегистрирован (этот запрос был отправлен через 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();
}