javascriptnode.jsstripe-paymentspayment-gatewaystripes

Stripe Subscription Renewal Stuck in "Incomplete" Status, No Auto-Renewal or Payment Deduction


I'm using Stripe to handle subscriptions in my application. The initial subscription creation works perfectly, but I'm facing an issue with auto-renewals.

When it's time for the monthly subscription to renew, the status changes to "incomplete", and the payment is not deducted automatically. This results in the subscription not being renewed, and the user ends up with an incomplete status.


const createProduct = async (productName) => {
    const PRODUCT_TYPE = 'service'

    const product = await stripe.products.create({
        name: productName,
        type: PRODUCT_TYPE,
    });
    return product?.id
}

const createCustomer = async (email) => {
    const customer = await stripe.customers.create({
        email: email,
    })
    return customer.id
}

const createPrice = async (productId, amount, duration) => {
    const CURRENCY = "usd"
    const price = await stripe.prices.create({
        product: productId,
        unit_amount: Number(amount) * 100,
        currency: CURRENCY,
        recurring: { interval: 'day' }
    })

    return price?.id
}

const productId = await createProduct(productName)
    const customerId = customer_id ? customer_id : await createCustomer(email)
    const metaData = {
      duration,
      user_id,
      productId,
      amount,
      productName,
      ...req?.body
}

const subscription = await stripe.subscriptions.create({
  customer: customerId,
  items: [{ price: await createPrice(productId, amount, duration) }],
  payment_behavior: 'default_incomplete',
  expand: ['latest_invoice.payment_intent'],
  metadata: metaData,
});

I've used payment_behavior: 'default_incomplete' for the initial subscription creation, which works fine. However, when the subscription renews, it stays in the incomplete status, and no payment is processed.


Solution

  • A subscription requires a default payment method to be set to charge for future payments. The issue in your integration is likely because the payment method is not set as the default payment method of the subscription that no available payment method can be charged.

    In your code at subscription creation, payment_settings is missing to save the default payment method on the subscription:

    const subscription = await stripe.subscriptions.create({
      customer: customerId,
      items: [{
        price: priceId,
      }],
      payment_behavior: 'default_incomplete',
    
      // `payment_settings` should be added to save the payment method 
      // as the default of the subscription
      payment_settings: { save_default_payment_method: 'on_subscription' },
    
      expand: ['latest_invoice.payment_intent'],
    });
    

    Reference: https://docs.stripe.com/billing/subscriptions/build-subscriptions?platform=web&ui=elements#create-subscription