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.