【发布时间】:2021-10-01 15:37:54
【问题描述】:
我正在关注带有服务器集成的 Stripe Checkout 文档:https://stripe.com/docs/payments/checkout/server
示例中的代码运行良好,但我遇到的问题是在购买完成后无法跟踪用户或他们的订单。
我有一个 webhook 设置,当付款完成时,Stripe 会 ping。但来自 Stripe 的响应会话除了名称、描述和图像外,不包含有关订购产品的信息。我可以使用产品名称来查询数据库,但我更喜欢 ID 或 slug 之类的。
$app->post("/stripe-pingback", function(Request $request, Response $response, array $args) {
\Stripe\Stripe::setApiKey("xxxxx");
// You can find your endpoint's secret in your webhook settings
$endpoint_secret = 'xxxxx';
$payload = $request->getBody();
$sig_header = isset($_SERVER['HTTP_STRIPE_SIGNATURE']) ? $_SERVER['HTTP_STRIPE_SIGNATURE'] : null;
$event = null;
try {
$event = \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret);
} 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();
}
// Handle the checkout.session.completed event
if ($event->type == 'checkout.session.completed') {
$session = $event->data->object;
var_dump($session);
// Possible to get custom data from session?
$customer = $session->customer;
$customerEmail = $session->customer_email;
// Fulfill the purchase...
$this->db->insertAudioPurchase();
}
http_response_code(200); // PHP 5.4 or greater
});
是否可以将 ID 与 Stripe 可以 ping 回的结帐请求一起传递以允许我查找订单并生成下载链接?
【问题讨论】:
-
说真的,我不明白为什么您希望从结帐会话中知道的最重要的数据,例如“我的用户支付了什么费用”,却留给了 Stripe 的其他流程或解决方法。
标签: php stripe-payments