简体   繁体   中英

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. I pass the client_secret from the setupIntent to the confirmCardSetup in js.

Later, I create a paymentIntent with that card. 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. This works well and the charge succeeds (or becomes 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.

You can also save a card for future use during a payment using setup_future_usage=off_session by following this guide . 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.
  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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