我目前有一个Opayo (SagePay)服务器集成,在这里,我显然被这样一种功能所破坏:我可以简单地响应付款通知回调的错误状态,以便在完成订单时拒绝/取消事务。我认为,有某种自动授权然后捕获发生在幕后,只有当我的通知处理程序返回成功/确定状态时,才会捕获付款。
我正在研究如何使用Stripe签出集成(预编好的Checkout、带有web挂钩的PHP )来实现相同的功能,而且我似乎需要使用授权和手动捕获:
$session = \Stripe\Checkout\Session::create([
...
'payment_intent_data' => [
'capture_method' => 'manual',
],
]);在示例代码和文档中(这通常是很好的,但在这里我觉得不够),它展示了如何创建一个web钩子来处理结帐会话的完成:
// Handle the checkout.session.completed event
if ($event->type == 'checkout.session.completed') {
$session = $event->data->object;
// Fulfill the purchase...
fulfill_order($session);
}奇怪的是,没有检查事务的payment_status,该示例表明您只需在这里完成您的订单。我只能假设,如果您没有使用延迟支付方法,那么您可以假设付款在这一点上是成功的,尽管这似乎是一个危险的假设。
在文档中,在“处理延迟通知支付方法服务器端”下,我们有一个更完整的示例,在完成订单之前实际检查付款状态:
switch ($event->type) {
case 'checkout.session.completed':
$session = $event->data->object;
// Save an order in your database, marked as 'awaiting payment'
create_order($session);
// Check if the order is paid (e.g., from a card payment)
//
// A delayed notification payment will have an `unpaid` status, as
// you're still waiting for funds to be transferred from the customer's
// account.
if ($session->payment_status == 'paid') {
// Fulfill the purchase
fulfill_order($session);
}
...如果我使用的是手动捕获方法,那么应该如何使用/调整上面的代码呢?想必payment_status不会是paid,所以我要检查什么,以及如何访问PaymentIntent才能捕获它?这一切应该发生在checkout.session.completed事件中吗?
代码示例很好;不幸的是,文档中只有这个脚注:
要捕获未捕获的支付,可以使用仪表板或捕获端点。以编程方式捕获支付需要访问在Checkout会话期间创建的PaymentIntent,您可以从会话对象获得该访问。
我已经检查了在线代码示例,但是这个确切的场景还没有涵盖。
编辑:在下面添加我对所需流程的理解,并提出问题:
switch ($event->type) {
case 'checkout.session.completed':
$session = $event->data->object;
if ($session->payment_status == 'unpaid') {
// We need to capture the payment if we have arrived here?
// Is this the only scenario where we would end up here?
// How do we get the PaymentIntent, what status if any should we check on it?
// Attempt to fulfil the purchase here, if all good then
// capture the payment
} else if ($session->payment_status == 'paid') {
// Assume this was not an auth/capture type payment?
// There is no other scenario where we would end up here?
}
...发布于 2020-12-14 00:55:19
如果收到checkout.session.completed事件,则同步支付方法成功完成。
对于异步支付方法,还有其他活动:
checkout.session.async_payment_succeededcheckout.session.async_payment_failed我不知道为什么在这里使用auth和capture,因为付款在收到checkout.session.completed或checkout.session.async_payment_succeeded时都是成功的,但是如果需要,您可以设置这样的选项-- 这里,然后需要捕获支付意图关联的与结帐会话。
如果您需要确定该费用是否已被捕获,则需要检索支付意图并查看该费用的captured值:对象捕获
https://stackoverflow.com/questions/65281615
复制相似问题