所以我是 Stripe 的新手,我正在尝试使用 webhook 获取结帐付款意图响应,
我的目的是将结帐响应发送到我的仪表板角度应用程序,以便我可以保存有关客户端的数据以及付款是否成功
所以我使用了这段代码:
<?php
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey('sk_test_xxx');
$payload = @file_get_contents('php://input');
$event = null;
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
}
$payload = @file_get_contents('php://input');
$event = null;
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
}
print_r($payload);
// Handle the event
switch ($event->type) {
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
echo 'success';
// Then define and call a method to handle the successful payment intent.
// handlePaymentIntentSucceeded($paymentIntent);
break;
case 'payment_intent.payment_failed':
$paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod
echo 'failed';
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handlePaymentMethodAttached($paymentMethod);
break;
// ... handle other event types
default:
// Unexpected event type
http_response_code(400);
exit();
}
http_response_code(200);
然后我运行结帐测试,完成并获得成功页面后,我尝试访问 www.website.com/webhooks.php 它总是给我一个 400 错误,
我不知道我在做什么是错的以及如何使用 webhook 我仍在研究它,所以有人可以告诉我该怎么做
ibeautiful
胡子哥哥