Charming Robot
Charming Robot

Reputation: 2660

Stripe Elements update subscriber payment method

How to enable users to update their subscription's payment method using Stripe Elements? I couldn't find any reference to this neither in the docs nor on Stackoverflow.

This is how I'm currently setting the default payment method when the user first subscribes to our service.

  1. Create a Stripe subscription object
  2. Render the React CardElement component.
  3. On submit, I call the browser's side Stripe library with stripe.confirmCardPayment(cardElement)
  4. This then triggers a invoice.payment_succeeded webhook event.
  5. In the webhook event, I get the payment intent ID which I use to retrieve the payment intent object which has the ID of the payment_method attached to it.
  6. I then update Stripe's subscription object to use the successful payment_method's ID as the default payment method.

Is there a way to update the subscription's payment method without making a payment_intent first? Link to docs would be appreciated.

Thank you

Upvotes: 2

Views: 2535

Answers (1)

alex
alex

Reputation: 2784

You can use SetupIntents to save a customer’s card without an initial payment : https://stripe.com/docs/payments/save-and-reuse-cards-only [until step 4]

Listen for the setup_intent.succeeded webhook event to know when the SetupIntent is successful since the customer could close the browser window or quit the app before the stripe.confirmPayment callback executes.

Update the Subscription to use the resulting PaymentMethod ID as the default payment method.

Alternatively, you could also make use of the Customer Portal to allow customers to update their payment method for a subscription : https://stripe.com/docs/billing/subscriptions/customer-portal

Upvotes: 2

Related Questions