I'm new to Stripe and need to schedule a subscription downgrade so that the downgrade takes effect only after the current billing period ends.
I tried the following approach, which unfortunately downgraded the subscription immediately:
await stripe.subscriptions.update(user.stripeSubscriptionId, {
items: [{
id: currentSubscription.items.data[0].id,
price: prod_env,
}],
proration_behavior: 'none',
cancel_at_period_end: true,
metadata: {
plan: productName,
userId: userId.toString(),
},
});
await stripe.subscriptionSchedules.create({
customer: user.stripeCustomerId,
start_date: currentSubscription.current_period_end,
phases: [
{
items: [
{
price: prod_env,
quantity: 1,
},
],
metadata: {
plan: productName,
userId: userId.toString(),
}
},
],
});
Next, I attempted a different method:
await stripe.subscriptions.update(user.stripeSubscriptionId, {
items: [{
id: currentSubscription.items.data[0].id,
price: prod_env,
}],
proration_behavior: 'none',
metadata: {
current_plan: currentPlan,
scheduled_plan: productName,
userId: userId.toString(),
},
cancel_at_period_end: true
});
This approach doesn't apply the downgrade immediately, but I'm uncertain if it cancels the subscription entirely at the period's end or transitions to the new plan. Could someone confirm if scheduling the downgrade this way is correct? I've reviewed the Proration and Upgrading/Downgrading documentation, but haven't found a direct reference for this method.
Any help is appreciated. Have a great day!