javascript - 带 3d 安全卡和 next_action null 的 Stripe 订阅

标签 javascript php stripe-payments 3d-secure

我们正在努力准备我们的 Stripe 订阅工作流程,以符合将于 2019 年 9 月 14 日生效的新 SCA 在线支付要求。我们在尝试调整 Javascript 和 PHP 代码以接受 3d 安全时遇到了一些问题创建订阅时使用信用卡。

我们已经尝试了指出的内容 here但没有运气。我们在服务器端创建订阅时发送了 enable_incomplete_payments = true,但是响应返回 next_action = null 虽然订阅的状态是 pending.

这是我们一步一步做的:

(客户端)我们开始元素

let stripe = window.Stripe(key);
let elements = stripe.elements();
[...]
let card = elements.create('card', {style: style});
[...]

(客户端)我们使用测试卡 4000000000003220(3d 安全)

(客户端)createToken() -> 向服务器发送 token

createToken(formId).then((result)=>{
    if (result.error) {
        //handle errors
    } else{
        //send result.token to backend
    }
})

(服务器)从客户端获取 token 并创建客户:

Customer::create([
    "description" => $user->name,
    "email" => $user->email,
    "source" => $token, // obtained with Stripe.js
]);

(服务器)创建订阅

    $response = Subscription::create([
            "customer" => $customerId,
            "items" => [
                ["plan" => $planId],
            ],
            "prorate" => false,
            "expand" => ["latest_invoice.payment_intent"],
            'enable_incomplete_payments' => true
        ]);

    if ($response->status == 'incomplete') {
        $payment_intent = $response->latest_invoice->payment_intent->client_secret;
        //send payment intent client secret to frontend to perform authorization
    }

这里我们应该将 status=requires_action 作为响应,但我们收到的是 status=null。在下一步中:

    stripe.handleCardPayment(paymentIntentSecret, element)

这里失败了(没有其他 Action 或弹出窗口),错误:

"error": {
    "charge": "ch_1EhvwjBqa3pLeb3ypVgXafhI",
    "code": "authentication_required",
    "decline_code": "authentication_required",
    "message": "Your card was declined. This transaction requires two-factor authentication.",
[...]

谢谢, 马可

最佳答案

这是因为您使用的是不完整状态存在之前的旧 API 版本。要使用此 SCA 就绪流程,您可以在创建订阅时通过传递 "enable_incomplete_payments"=> true 选择加入,或者使用 https://stripe.com/docs/api/versioning使用更新的 API 版本发出 API 请求。这里有详细的描述:

https://stripe.com/docs/billing/lifecycle#incomplete-opt-in

关于javascript - 带 3d 安全卡和 next_action null 的 Stripe 订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56459396/

相关文章:

stripe-payments - Stripe 充电多次

ruby-on-rails - Stripe "This API call cannot be made with a publishable API key. "给出了什么?

javascript - Webpack 配置连接 JS

javascript - html 表格到 javascript 中的 excel 工作表

javascript - 使用 nextSibling 从 HTML 表格中检索数据

javascript - 有没有办法给每个 div 一个唯一的 id 而不必每次都输入它?

php - PHP 会自动将数字转换为字符串吗?

javascript - 如何知道每 3 分钟的窗口 href 值

php - PHP 的 Postgres 连接速度很慢

ruby-on-rails - 如何通过 Stripe API 一次删除所有 Stripe 计划?