简体   繁体   English

Stripe——confirmCardPayment 后,如何将新卡附加给客户?

[英]Stripe -- after confirmCardPayment, how to attach the new card to the customer?

I am using a setupIntent to save a card to a customer for future use.我正在使用setupIntent将卡保存给客户以供将来使用。 I pass the client_secret from the setupIntent to the confirmCardSetup in js.我将 client_secret 从setupIntent给 js 中的confirmCardSetup

Later, I create a paymentIntent with that card.后来,我用那张卡创建了一个paymentIntent If it is declined and the status is requires_payment_method then I email the customer and give them a form to enter a new card, and subit that using confirmCardPayment in js.如果它被拒绝并且状态为requires_payment_method然后我 email 客户并给他们一个表格以输入新卡,并使用 js 中的confirmCardPayment提交。 This works well and the charge succeeds (or becomes requires_capture ).这很好用并且收费成功(或变为requires_capture )。

How do I then attach that new payment method to the customer?然后,我如何将新的付款方式附加给客户? If I do nothing, then their old saved card is still their primary payment method.如果我什么都不做,那么他们保存的旧卡仍然是他们的主要付款方式。

I only want to keep one card on file for each customer.我只想为每个客户保留一张卡片。 I know I can detach the old card and then attach the new one, but then it will not have been done using a setupIntent , which is apparently more appropriate if I'm going to be charging the card in the future off session.我知道我可以拆下旧卡然后连接新卡,但是它不会使用setupIntent完成,如果我将来要从 session 对卡充电,这显然更合适。

You can also save a card for future use during a payment using setup_future_usage=off_session by following this guide .您还可以按照本指南使用setup_future_usage=off_session保存卡片以供将来在付款期间使用。 The payment method will be automatically attached to the customer provided on the Payment Intent.付款方式将自动附加到付款意向中提供的客户。

Your existing flow can be used, you'd just extend it by:可以使用您现有的流程,您只需通过以下方式扩展它:

  1. Prior to confirming the Payment Intent again with the new payment details, update it to set the setup_future_usage option.在使用新的付款详细信息再次确认付款意图之前,请对其进行更新以设置setup_future_usage选项。
  2. After the payment succeeds, detach the old payment method like you mentioned and, if needed, update your internal reference to the payment method to use for that customer to be the new payment method id from the Payment Intent.付款成功后,像您提到的那样分离旧的付款方式,如果需要,更新您对付款方式的内部引用以供该客户使用,使其成为付款意图中的新付款方式 ID。

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

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