1

I'm using stripe-react-native to handle payment, and I'm able to handle one-time payment via payment-sheet using PaymentIntent flow.

Now I'm stuck with creating subscription using the same payment sheet flow, has anyone tried this before? Or an advise how to use PaymentIntent in subscription?

Hani Ghazi
  • 100
  • 2
  • 14
  • When you create a subscription on your backend you can expand on `latest_invoice.payment_intent` and you can send the `client_secret` of that `PaymentIntent` to the payment-sheet the same way you did for a normal `PaymentIntent`. – Tarzan May 03 '22 at 10:27
  • The latest_invoice only seems to provide the invoice ID and is not an object @Tarzan – Ethan Crabb May 03 '22 at 16:42
  • @Tarzan can you convert your comment to an answer to accept it? and it would be lovely to provide some code examples. Thanks – Hani Ghazi May 06 '22 at 11:12
  • 1
    You need to pass `expand: ['latest_invoice. payment_intent']` in create subscription then you will be able to get the `client_secret` by `subscription.latest_invoice.payment_intent.client_secret` @EthanCrabb – Hani Ghazi May 06 '22 at 11:15

1 Answers1

3

You need to expand the subscription object with payment intent.

const subscription = await stripe.subscriptions.create({
  ...subscriptionSettings
  expand: ['latest_invoice.payment_intent']
});

You can then access it using:

const paymentIntent = subscription.latest_invoice.payment_intent
const clientSecret = subscription.latest_invoice.payment_intent.client_secret
Ethan Crabb
  • 302
  • 5
  • 14