#alexzada-subscription
1 messages · Page 1 of 1 (latest)
Hi, I'm using stripe-react-native in my frontend. I use the CardField component to get the card details and createPaymentMethod({ PaymentMethodType: 'Card', } to send as a parameter to the backend route that creates the subscription
The recommended integration is to first create the subscription, using payment_behavior: "default_incomplete" so you don't get an error if there's no payment method. And then use the latest_invoice.payment_intent.client_secret of the subscription on the frontend to collect the payment details.
You can learn more about this flow in this guide: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
I'm using the finalization flow on the server, synchronously, does this guide work for this case too?
it doesn't, no
we might have a guide for the legacy way, let me look
yeah, https://stripe.com/docs/billing/subscriptions/fixed-price uses the old approach of sending the PaymentMethod to the backend, if that helps
basically though, you need to pass payment_method when creating the customer, and mark it default for the subscription.
let customer = await stripe.customers.create({
email: "test@example.com",
});
let pm = await stripe.paymentMethods.attach("pm_card_visa", {customer: customer.id});
let subscription = await stripe.subscriptions.create({
customer: customer.id,
default_payment_method : pm.id,
items: [
{
plan: "plan_DQYe83yUGgx1LE",
},
],
expand : ["latest_invoice"]
});