如何在客户端上创建 PaymentMethod 以在服务器上多次收费时处理 Stripe 3D Secure [英] How to handle Stripe 3D Secure when creating a PaymentMethod on the client for multiple charges on the server

查看:40
本文介绍了如何在客户端上创建 PaymentMethod 以在服务器上多次收费时处理 Stripe 3D Secure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的市场中,我有一个要求:

  • 让客户输入他们的卡详细信息
  • 提交卡详细信息后,在服务器端处理针对该卡的多次收费

我正在使用 stripe.js 并使用 stripe.createPaymentMethod() 在客户端创建一个 PaymentMethod

PaymentMethod 的 ID 被发布到服务器,然后服务器通过 PHP 的 Stripe API 库执行以下操作:

  • 使用发布的 ID 从 Stripe 中检索 PaymentMethod
  • 在 Stripe 上创建一个客户,指定payment_method"
  • 创建多个 PaymentIntent,指定payment_method"、customer"、save_payment_method"为真,confirm"为真.

我现在想要处理 Stripe 需要使用 3D Secure 的场景.

在向服务器发出请求之前,有什么方法可以在客户端上进行 3D 安全验证,同时使用 stripe.createPaymentMethod() 吗?

如果没有,我还有什么选择?

完成 3D Secure 步骤的用户似乎只返回 PaymentIntent.我不相信我可以用它来对卡进行多次收费.这就是首先在客户端上使用 createPaymentMethod() 的全部原因.

关于如何解决这个问题有什么想法吗?

解决方案

在向服务器发出请求之前,有什么方法可以在客户端上进行 3D 安全验证,同时使用 stripe.createPaymentMethod() 吗?

在客户端处理 3D 安全身份验证的方法是使用 Stripe.js 上的 confirmCardPayment [0] 或 handleCardAction [1] 方法.除非您有特定需求,否则您很可能希望使用 confirmCardPayment 并按照此处的指南进行操作:

https://stripe.com/docs/payments/accept-a-payment

我应该注意,这两种方法一次只能处理一笔付款.在您的情况下,您有多个付款意图,因此您需要在每笔交易中调用其中一种方法.也就是说,如果您有三个付款意向,则需要调用 confirmCardPayment 三次,并多次重复指南 [2] 中的最后一步.

这意味着您的用户可能需要多次进行身份验证才能处理他们的每笔付款,这在技术上是可能的(但不太可能).

不幸的是,确实没有解决方法.即使您要使用 SetupIntents [3] 设置用户卡并在以后在会话外向他们收费,您仍然需要将用户的会话带回会话以验证每个单独的付款意图.

综上所述,您的大多数用户可能不会遇到需要连续多次进行身份验证的情况.

唯一的另一种选择是创建涵盖您的产品/服务的全部成本的单一付款意向,这样您只需调用一次 confirmCardPayment.

[0] https://stripe.com/docs/js/payment_intents/confirm_card_payment

[1] https://stripe.com/docs/js/payment_intents/handle_card_action

[2] https://stripe.com/docs/payments/accept-a-payment#web-submit-payment

[3] https://stripe.com/docs/payments/save-和-重用

In my marketplace I have a requirement to:

  • Have a customer enter their card details
  • Once card details are submitted, process multiple charges against that card on the server side

I'm using stripe.js and creating a PaymentMethod on the client side using stripe.createPaymentMethod()

The ID of the PaymentMethod is posted to the server, which then does the following via the Stripe API library for PHP:

  • Retrieves the PaymentMethod from Stripe using the posted ID
  • Creates a Customer on Stripe, specifying the 'payment_method'
  • Creates multiple PaymentIntents, specifying the 'payment_method', the 'customer', 'save_payment_method' as true and 'confirm' as true.

I'm now wanting to handle scenarios where Stripe requires the use of 3D Secure.

Is there any way that 3D Secure verification can take place on the client, prior to the request to the server, whilst using stripe.createPaymentMethod() ?

If not, what alternative do I have?

It seems that a user completing the 3D Secure steps returns only a PaymentIntent. I don't believe I'm able to use this to make multiple charges against the card. This is whole reason for using createPaymentMethod() on the client in the first place.

Any ideas on how to go about this?

解决方案

Is there any way that 3D Secure verification can take place on the client, prior to the request to the server, whilst using stripe.createPaymentMethod() ?

The approach to handle 3D Secure authentication on the client is to either use the confirmCardPayment [0] or handleCardAction [1] methods on Stripe.js. Unless you have specific needs, you would most likely want to use confirmCardPayment and follow this guide here:

https://stripe.com/docs/payments/accept-a-payment

I should note, that both these methods only work to process one payment at a time. In your case, you have multiple payment intents, so you would need to call either of the methods once per transaction. That is, if you have three payment intents you would need to call confirmCardPayment three times, repeating the last step in the guide [2] that many times as well.

This means that it is technically possible (but unlikely) that your users may have to authenticate multiple times to process each of their payments.

Unfortunately, there are really no workarounds for this. Even if you were to setup a user's card with SetupIntents [3] and charge them off-session at a later date, there is still a risk that you would need to bring user's back on-session to authenticate each individual payment intent.

All this being said, the majority of your users probably won't run into a scenario where they would need to authenticate multiple times in a row.

The only other option would be to create a single payment intent that covers the full cost of your product/service, which would allow you to call confirmCardPayment just once.

[0] https://stripe.com/docs/js/payment_intents/confirm_card_payment

[1] https://stripe.com/docs/js/payment_intents/handle_card_action

[2] https://stripe.com/docs/payments/accept-a-payment#web-submit-payment

[3] https://stripe.com/docs/payments/save-and-reuse

这篇关于如何在客户端上创建 PaymentMethod 以在服务器上多次收费时处理 Stripe 3D Secure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆