Tomaz_
Tomaz_

Reputation: 469

Stripe subscription always gives me "status: 'requires_confirmation'

I have a subscription route like this. My flow looks like this

  1. User select a plan.
  2. User enter card details through Stripe Card Element
  3. User click Subscribe button.

As per docs,

  1. I'm creating a customer.
  2. Then creating a subscription for this customer.

But, my dashboard says payment incomplete and response object on creating subscriptions shows status: 'requires_confirmation'. What I am doing wrong?


router.post('/subscription', auth, async (req, res) => {
    const { payment_method, price_id } = req.body;

    const customer = await Stripe.customers.create({
        email: '[email protected]',
        payment_method: payment_method,
        description: 'New Customer',
        invoice_settings: { default_payment_method: payment_method }
    });

    try {
        const subscription = await Stripe.subscriptions.create({
            customer: customer.id,
            items: [
                {
                    price: price_id
                }
            ],
            payment_behavior: 'default_incomplete',
            expand: ['latest_invoice.payment_intent']
        });

        res.send({
            status: subscription.latest_invoice.payment_intent.status,
            subscriptionId: subscription.id,
            
        });
    } catch (error) {
        return res.status(400).send({ error: { message: error.message } });
    }
});



[![Stripe dashboard][1]][1]


  [1]: https://i.sstatic.net/Sx0zN.png

Upvotes: 2

Views: 2971

Answers (1)

codename_duchess
codename_duchess

Reputation: 921

It sounds like you’re doing things a bit out of order from the way the Stripe docs suggest. In this guide, the subscription object is created prior to collecting the payment method. The reason your invoice isn’t automatically paid is because you are explicitly passing in a payment_behavior of default_incomplete, which tells Stripe not to pay the invoice and allows you to collect payment details client-side and confirm the payment. Since you have already collected payment details, don’t pass in a payment_bevavior of default_incomplete.

Upvotes: 4

Related Questions