#niteesh-Subscription
1 messages · Page 1 of 1 (latest)
Hi there, I'm reading your previous message and will be with you shortly.
For the existing subscription, you can update its cancel_at_period_end to true so it'll be cancelled automatically at the end of the current billing cycle.
Use the the subscription schedule to schedule the new subscription, set the start_date to the beginning timestamp of the next billing cycle.
Thank you for your response. Is there an alternative solution that would retain the same subscription id ?
Each subscription ID is unique and you cannot reuse a old ID
okay thank you.
function downgrade(customerId, currentSubsId, newPriceId) {
try {
const subscription = await stripe.subscriptions.update(currentSubsId, { cancel_at_period_end: true });
const schedule = await stripe.subscriptionSchedules.create({
customer: customerId,
start_date: subscription['current_period_end'],
end_behavior: 'release',
phases: [
{
items: [{ price: newPriceId, quantity: 1 }],
default_payment_method: subscription['default_payment_method'],
},
],
});
} catch (err) {
///
}
}
Can you check if this snippet is correct. Thank you.
Yup, your code looks good to me 🙂
okay thank you so much.
Is it possible to do this way too ?
function downgrade(currentSubsId, currentPriceId, newPriceId) {
try {
const schedule = await stripe.subscriptionSchedules.create({
from_subscription: currentSubsId
});
const updatedSchedule = await stripe.subscriptionSchedules.update(
schedule.id,
{
end_behavior: 'release',
phases: [
{
items: [{ price: currentPriceId, quantity: 1 }],
end_date: schedule['current_phase']['end_date'],
},
{
items: [{ price: newPriceId, quantity: 1 }],
start_date: schedule['current_phase']['end_date'],
},
],
},
);
} catch (err) {
//
}
}
you are creating two new subscriptions here with this schedule.
okay. what about this ?
function downgrade(currentSubsId, currentPriceId, newPriceId) {
try {
const schedule = await stripe.subscriptionSchedules.create({
from_subscription: currentSubsId
});
const updatedSchedule = await stripe.subscriptionSchedules.update(
schedule.id,
{
end_behavior: 'release',
phases: [
{
items: [{ price: newPriceId, quantity: 1 }],
start_date: schedule['current_phase']['end_date'],
},
],
},
);
} catch (err) {
//
}
}
Also when transitioning from one phase to another, new subscriptions are created or the existing subscription get updated ?
Hi! I'm taking over Jack Tan, please give me a few minutes to catch up.
okay. what about this ?
What exactly is your question?
Also when transitioning from one phase to another, new subscriptions are created or the existing subscription get updated ?
The same subscription gets updated. You can learn more about subscription schedules here: https://stripe.com/docs/billing/subscriptions/subscription-schedules
I'm trying to implement subscription with 3 plans STARTER, STANDARD and PLUS (specified in the increasing order of the price). What i Iwant to achieve is that when a customer downgrades his/her subscription plan ( for eg. PLUS to STANDARD), this change should happen only for the next billing cycle and not immediately.
Scenario eg. : On 1st jan a customer subscribes for the PLUS plan and on 15th jan he/she downgrades the plan to STANDARD, this change should not get reflected immediately, It should be reflected for the next billing cycle that is on 1st Feb.
Can I do it this way ?
function downgrade(currentSubsId, currentPriceId, newPriceId) {
try {
const schedule = await stripe.subscriptionSchedules.create({
from_subscription: currentSubsId
});
const updatedSchedule = await stripe.subscriptionSchedules.update(
schedule.id,
{
end_behavior: 'release',
phases: [
{
items: [{ price: newPriceId, quantity: 1 }],
start_date: schedule['current_phase']['end_date'],
},
],
},
);
} catch (err) {
//
}
}
Yes it should be possible to do something like this. However I would recommend to test your code directly, and if you see errors that you cannot solve then I'd be happy to help.
Another option would be to directly update the subscription (so no subscription schedule) and disable prorations. This way the user won't be charged when you do the update, and on the next billing cycle they will pay the price of the new plan.