简体   繁体   English

我怎么知道升级到 stripe.js 版本 3 后 3D Secure 2 身份验证有效

[英]How do I know that 3D Secure 2 authentication works after upgrading to stripe.js version 3

I have updated a site so it uses latest stripe-php (6.39.0) and it now loads stripe.js version 3. I've made all the necessary changes to my code so that my credit card fields are now displayed using Stripe Elements.我更新了一个站点,因此它使用最新的 stripe-php (6.39.0),现在加载了 stripe.js 版本 3。我对代码进行了所有必要的更改,以便我的信用卡字段现在使用 Stripe Elements 显示. Test transactions work and I have updated the live site and real payments are being excepted.测试交易有效,我已经更新了实时网站,实际付款除外。

The reason I made this update was because I was informed by stripe that I needed to upgrade the site so that its stripe integration will work with Strong Customer Authentication (SCA) which is required in the EU by September 2019.我进行此更新的原因是 Stripe 告知我需要升级站点,以便其 Stripe 集成能够与欧盟在 2019 年 9 月之前要求的强客户身份验证 (SCA) 配合使用。

Stripe has different credit card test numbers you can use to test things that arise when processing payments. Stripe 有不同的信用卡测试号码,您可以用来测试处理付款时出现的问题。 This numbers can be found here: https://stripe.com/docs/testing#cards这个数字可以在这里找到: https : //stripe.com/docs/testing#cards

4000000000003220 simulates a transactions where 3D Secure 2 authentication must be completed. 4000000000003220 模拟必须完成 3D Secure 2 身份验证的交易。 But when I use this code stripe turns down payment and returns the message:但是,当我使用此代码条带拒绝支付并返回消息时:

"Your card was declined. This transaction requires authentication. Please check your card details and try again." “您的卡被拒绝。此交易需要身份验证。请检查您的卡详细信息,然后重试。”

Does this mean that 3D Secure 2 is working or not?这是否意味着 3D Secure 2 有效?

In the real world it would open a window with an interface from the customer's card issuer.在现实世界中,它会打开一个窗口,其中包含来自客户发卡机构的界面。 So I not sure wether my integration is working or not.所以我不确定我的集成是否有效。 As said before payments are being excepted butI need to ready when Strong Customer Authentication is required in September.如前所述,付款被排除在外,但我需要在 9 月份需要强客户身份验证时做好准备。

It seems you have an integration problem with the JS part.看来您在 JS 部分存在集成问题。 For a simple charge (the following example does not work for subscription), this is the way you have to implement it:对于简单的收费(以下示例不适用于订阅),这是您必须实施的方式:

First you have to create a Payment intent (doc here: https://stripe.com/docs/api/payment_intents/create ):首先,您必须创建付款意图(此处的文档: https : //stripe.com/docs/api/payment_intents/create ):

\Stripe\PaymentIntent::create([
  "amount" => 2000,
  "currency" => "usd",
  "payment_method_types" => ["card"],
]);

Once your PaymentIntent response is returned, you will have a client_secret key (doc here : https://stripe.com/docs/api/payment_intents/object ).一旦您的 PaymentIntent 响应返回,您将拥有一个 client_secret 密钥(此处的文档: https ://stripe.com/docs/api/payment_intents/object)。 You can see that your payment status is "requires_payment_method"可以看到你的付款状态是“requires_payment_method”

{
  "id": "pi_1Dasb62eZvKYlo2CPsLtD0kn",
  "object": "payment_intent",
  "amount": 1000,
  "amount_capturable": 0,
  "amount_received": 0,
  ...
  "client_secret": "pi_1Dasb62eZvKYlo2CPsLtD0kn_secret_6aR6iII8CYaFCrwygLBnJW8js",
  ...
  "status": "requires_payment_method",
  ...
}

On your server side you have to save this object.在您的服务器端,您必须保存此对象。 You can now show your payment form with the JS part with the previous client_secret key (doc here : https://stripe.com/docs/payments/payment-intents/verifying-status ).您现在可以使用先前的 client_secret 密钥显示带有 JS 部分的付款表格(此处的文档: https : //stripe.com/docs/payments/payment-intents/verifying-status )。 The idea is that you have to call the Js function on click on the submit button but do not submit !这个想法是你必须在点击提交按钮时调用 Js 函数,但不要提交! Wait for the response to submit.等待响应提交。 With some jquery this should like this:使用一些 jquery 这应该是这样的:

var $mySubmitButton = $('#my-submit-button'),
    $myPaymentForm = $('#my-payment-form'),
    clientSecret = $cardButton.data('client-secret'); // put your client-secret somewhere

$mySubmitButton.on('click', function(e) {
  
    e.preventDefault();

    // Disable button to disallow multiple click
    $(this).attr("disabled", true);

    stripe.handleCardPayment(
        clientSecret,
        {
            payment_method: clientMethod, // if you have a clientMethod
        }
    ).then(function(result) {
        if (result.error) {
            // show error message
            // then enable button
            $mySubmitButton.attr("disabled", false);
        } else {
            // Submit form
            $myPaymentForm.submit();
        }
    });
});

If everything goes right, when you click your submit button, you will have a test 3D secure popin with the options to "success" or "fail" the security test.如果一切顺利,当您单击提交按钮时,您将获得一个测试 3D 安全弹出窗口,其中包含“成功”或“失败”安全测试的选项。 If you click on success button, your form is submitted and you have to wait for the webhook "charged.success" to confirm transaction.如果您点击成功按钮,您的表单将被提交,您必须等待网络钩子“charged.success”确认交易。

Once received, change you server object status and notify user about the transaction.收到后,更改您的服务器对象状态并通知用户有关交易的信息。

In my case, once the form submitted, I show a loader and check with ajax call every second to see if my payment intent status have changed (through the webhook).就我而言,一旦表单提交,我就会显示一个加载程序并每秒检查一次 ajax 调用,以查看我的付款意图状态是否已更改(通过 webhook)。 For your test environnement, you can use http://requestbin.net and Postman.对于您的测试环境,您可以使用http://requestbin.net和 Postman。

Beware: some cards referenced on this page will not work properly (you can't add them) https://stripe.com/docs/testing#cards (section 3D Secure test card numbers and tokens).请注意:此页面上引用的某些卡将无法正常工作(您无法添加它们) https://stripe.com/docs/testing#cards(3D安全测试卡号和令牌部分)。 Confirmed with their support.得到了他们的支持。

If you work with saved card, you can test only with these cards: https://stripe.com/docs/payments/cards/charging-saved-cards#testing如果您使用保存的卡,则只能使用这些卡进行测试: https : //stripe.com/docs/payments/cards/charging-saved-cards#testing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM