是否可以将自定义数据传递给条带化签出?
我正在遵循带有服务器集成的 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 回的结帐请求一起传递,以允许我查找订单并生成下载链接?