I have one product and 8 prices (4 monthly and 4 annual) When a user updates a subscription from one number to two, stripe creates an invoice and waits for the user to pay for it
And here are my two situations when I do not understand what to do
The user bought a subscription to one number - the user subscribes to the second number, but leaves at the time of payment - the subscription has been updated and switched to the past_due status and is waiting for payment (the invoice has been created) Now there are two options - the user again goes to the subscription update and wants to add another number -> adds a number -> an invoice is being created -> waiting for payment -> the user pays only for the third number and his subscription becomes active for 3 numbers, but there is an unpaid invoice for the second number (this is the second screen)
The user did everything the same, but after he left the payment in the second step, he still had an open invoice, when the user removes the number from the subscription (lowers the price back) - the stripe puts money on the balance for this number (which he did not pay ) - but at the same time he has an open invoice for the added number (second)
This is how I create/update a subscription - https://gist.github.com/0ceb4ec03f9e7818a140b6a60e20b238
async createSubscription(stripeCustomerId: string, subscriptionInfo: SubscriptionInfoT) {
return this.stripe.subscriptions.create({
customer: stripeCustomerId,
items: [
{
price: subscriptionInfo.priceId,
quantity: subscriptionInfo.quantity,
},
],
description: Object.values(subscriptionInfo.numbers)
.filter(n => n)
.join(', '),
metadata: subscriptionInfo.numbers,
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
expand: ['latest_invoice.payment_intent'],
});
}
async updateCustomerSubscription(subscriptionId: string, subscriptionInfo: SubscriptionInfoT) {
const subscription = await this.stripe.subscriptions.retrieve(subscriptionId);
return this.stripe.subscriptions.update(subscriptionId, {
payment_behavior: 'default_incomplete',
proration_behavior: 'always_invoice',
description: Object.values(subscriptionInfo.numbers)
.filter(n => n)
.join(', '),
items: [
{
id: subscription.items.data[0].id,
price: subscriptionInfo.priceId,
quantity: subscriptionInfo.quantity,
},
],
metadata: subscriptionInfo.numbers,
expand: ['latest_invoice.payment_intent'],
});
}