【问题标题】:What to do when stripe returns requires_confirmation (php/js)当条带返回 requires_confirmation (php/js) 时该怎么办
【发布时间】:2022-08-17 01:09:29
【问题描述】:

我正在处理stripe.com/docs/.../upgrade-to-handle-actions(和stripe.com/docs/.../accept-a-payment-synchronously)上的STRIPE 支付意图示例,并且已经到达了他们的generateResponse() 代码中“任何其他状态都将是意外的,所以错误”的部分

function generateResponse($intent) {
    if ($intent->status == \'succeeded\') {
       // Handle post-payment fulfillment
       echo json_encode([\'success\' => true]);
    } elseif ($intent->status == \'requires_action\') {
       # Tell the client to handle the action
       echo json_encode([
               \'requiresAction\' => true,
               \'clientSecret\' => $intent->client_secret
       ]);
    } else {
       // Any other status would be unexpected, so error           <------------------
       echo json_encode([\'error\' => \'Invalid PaymentIntent status\']);
    }
}

但是我使用“资金不足”测试卡“4000008260003178”收到了“requires_confirmation”,我不确定我应该如何回应;我的代码可以在methodfish.com 上查看和运行。

    标签: stripe-payments


    【解决方案1】:

    如果由于资金不足而收到 requires_confirmation 状态,则 else 块将处理这种情况(因为资金不足被视为错误)。不过,如果您愿意,您可以改进错误消息以专门处理资金不足的情况。我建议看看Stripe's error handling docs

    【讨论】:

    • 在该页面上没有看到任何关于“requires_confirmation”或“资金不足”的讨论 - 您确定该页面是您的意思吗?
    • 是的,我只是想链接通用错误处理文档。特别是对于资金不足,这意味着重试付款可能不会成功。处理这种情况的方法是向客户显示一个错误,表明他们没有资金,指示他们提供不同的卡。您可以在 if-else 块中添加另一个检查来处理这种情况并返回适当的错误。
    【解决方案2】:

    好的 - 我认为代码变得混乱并且可能会反复调用自身 - 所以我重新排序了逻辑,以便完全通过客户端处理身份验证(在必要时使用 API 调用)。更正的 (?) 代码/沙盒可在 methodfish.com 上找到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-11
      • 1970-01-01
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多