#alexzada-subscription

1 messages · Page 1 of 1 (latest)

austere jungle
#

Hi! How are you collecting the payment method information?

serene turtle
austere jungle
#

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

serene turtle
latent osprey
#

it doesn't, no

#

we might have a guide for the legacy way, let me look

#

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"]
});