Stripe 3d 安全订阅失败

Tho*_*ont 3 php stripe-payments

我对 Stripe 的测试环境有一个关于 3D 安全流程和订阅的问题。我担心在没有验证或解释问题的情况下将流程推向生产。

\n\n

我根据文档执行了所有 3d 安全和订阅过程。

\n\n

https://stripe.com/docs/sources/third-d-secure/subscriptions

\n\n

当我通过禁用试用期来激活订阅时,我所做的所有尝试都失败了。

\n\n

在此输入图像描述

\n\n

我正在使用需要 3D 安全的测试卡:4000 0000 0000 3063

\n\n

我的代码流程:

\n\n
<!DOCTYPE html>\n<html lang="fr">\n<head>\n    <meta charset="UTF-8">\n    <title>Source test Stripe</title>\n    <script src="https://js.stripe.com/v3/"></script>\n    <style>\n        .StripeElement {\n            background-color: white;\n            height: 40px;\n            padding: 10px 12px;\n            border-radius: 4px;\n            border: 1px solid transparent;\n            box-shadow: 0 1px 3px 0 #e6ebf1;\n            -webkit-transition: box-shadow 150ms ease;\n            transition: box-shadow 150ms ease;\n        }\n\n        .StripeElement--focus {\n            box-shadow: 0 1px 3px 0 #cfd7df;\n        }\n\n        .StripeElement--invalid {\n            border-color: #fa755a;\n        }\n\n        .StripeElement--webkit-autofill {\n            background-color: #fefde5 !important;\n        }\n    </style>\n\n</head>\n<body>\n<h1>create source</h1>\n\n<form action="javascript:charge()" method="post" id="payment-form">\n    <div class="form-row">\n        <label for="card-element">\n            Credit or debit card\n        </label>\n        <div id="card-element">\n        </div>\n        <div id="card-errors" role="alert"></div>\n    </div>\n    <button>Submit Payment</button>\n</form>\n\n</body>\n<script>\n    var stripe = Stripe(\'pk_test_xxxx\');\n    var elements = stripe.elements();\n    var style = {\n        base: {\n            color: \'#32325d\',\n            lineHeight: \'18px\',\n            fontFamily: \'"Helvetica Neue", Helvetica, sans-serif\',\n            fontSmoothing: \'antialiased\',\n            fontSize: \'16px\',\n            \'::placeholder\': {\n                color: \'#aab7c4\'\n            }\n        },\n        invalid: {\n            color: \'#fa755a\',\n            iconColor: \'#fa755a\'\n        }\n    };\n    var card = elements.create(\'card\', {style: style});\n    card.mount(\'#card-element\');\n\n    card.addEventListener(\'change\', function(event) {\n        var displayError = document.getElementById(\'card-errors\');\n        if (event.error) {\n            displayError.textContent = event.error.message;\n        } else {\n            displayError.textContent = \'\';\n        }\n    });\n\n    var form = document.getElementById(\'payment-form\');\n    form.addEventListener(\'submit\', function(event) {\n        event.preventDefault();\n\n        var ownerInfo = {\n            owner: {\n                name: \'Jenny Rosen\',\n                address: {\n                    line1: \'Nollendorfstra\xc3\x9fe 27\',\n                    city: \'Berlin\',\n                    postal_code: \'10777\',\n                    country: \'DE\',\n                },\n                email: \'jenny.rosen@example.com\'\n            },\n        };\n        stripe.createSource(card, ownerInfo).then(function(result) {\n            if (result.error) {\n                var errorElement = document.getElementById(\'card-errors\');\n                errorElement.textContent = result.error.message;\n            } else {\n                console.log(result.source.id)\n            }\n        });\n    });\n\n    function charge() {\n    }\n</script>\n</html>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我得到了源 ID src_xxxxx

\n\n

我放入我的 php 脚本:

\n\n
<?php\n\nrequire_once(\'stripe-php/init.php\');\n\nStripe\\Stripe::setApiKey(\n    \'sk_test_xxxxx\'\n);\n\n$sourceId = \'src_xxxxx\';\n\n$customer = Stripe\\Customer::create([\n    \'description\' => \'test desc\',\n    \'email\' => \'test@test.com\',\n    \'source\' => $sourceId,\n]);\n\n\n$param = [\n    "amount" => 2995,\n    "currency" => \'eur\',\n    "type" => "three_d_secure",\n    \'three_d_secure\' => [\n        \'card\' => $sourceId\n    ],\n    "redirect" => [\n        "return_url" => "http://localhost:8080/stripeProcess2.php?customerId=".$customer->id\n    ],\n];\n\n$source = Stripe\\Source::create($param);\n\n$customer->sources->create([\'source\' => $source->id]);\n\nvar_dump($source->redirect);\n
Run Code Online (Sandbox Code Playgroud)\n\n

在 var_dump 中,我得到了重定向 url

\n\n

我接受 3d 安全支付,重定向链接执行以下脚本:

\n\n
<?php\nrequire_once(\'stripe-php/init.php\');\n\nStripe\\Stripe::setApiKey(\n    \'sk_test_xxxx\'\n);\n\n$source = $_GET[\'source\'];\n$customerId = $_GET[\'customerId\'];\n\n$charges = \\Stripe\\Charge::create(array(\n    "amount" => 2995,\n    "currency" => "eur",\n    \'source\' => $source,\n    \'customer\' => $customerId,\n    "description" => "Charge for daniel.garcia@example.com"\n));\n\n\n$params = [\n    \'items\' => [\n        [\n            "plan" => "annual-basic",\n        ]\n    ],\n    \'customer\' => $customerId,\n    \'trial_end\' => strtotime(\'+1 day\')\n];\n\n\n$sub = \\Stripe\\Subscription::create($params);\n\nvar_dump($sub->id);\n
Run Code Online (Sandbox Code Playgroud)\n\n

通过订阅 Stripe id,我将立即激活订阅(这向客户收费)

\n\n
$subscription = \\Stripe\\Subscription::retrieve("sub_C7eVRi9WLynMdh");\n$subscription->trial_end = "now";\n$subscription->save();\n
Run Code Online (Sandbox Code Playgroud)\n\n

在这里,我通过 generic_decline 代码收到了失败的付款。

\n\n

我想知道在我的过程中是否执行了错误,是否需要等待月底为客户充值,或者 Stripe 测试卡是否无法用于此过程?

\n\n

提前致谢

\n

myg*_*gov 7

我认为拒绝的原因是因为测试卡4000000000003063(https://stripe.com/docs/sources/third-d-secure)仅适用于单次付款,并且必须完成3D Secure才能成功收费。(使用信用卡 4000000000003055 - “此卡支持 3D Secure,但不需要”。)

这意味着,如果客户附有此卡,您只能测试初始付款,而不能测试定期付款,因为您无法再次完成 3D Secure 程序。

您需要使用 stripe 默认程序 ( https://stripe.com/docs/sources/cards )存储原始信用卡来源,以便再次使用该来源进行持续的订阅付款。