#ivan-price-subscription
1 messages · Page 1 of 1 (latest)
The best option is to create a new Price price_ABC and then you can use SubscriptionSchedule to plan the Price change for each customer
ty I'll look into that
hey, so i've looked into it but I don't understand how I can move the current subcriptions
What don't you understand exactly?
I've created the subcription schedules from the subscription
const schedule = await stripe.subscriptionSchedules.create({
from_subscription: 'sub_GB98WOvaRAWPl6'
});
using this
then I've tried to update it using the phases
but i get this error 'The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.',
how did you update, like what exact code did you pass?
We're both developers. Just give us real code + a real error and we can help you
await stripe.subscriptionSchedules.update(
'sub_sched_id',,
{
phases: [
{
items: [
{price: 'price_id', quantity: 1},
]
},
],
}
);
this is the error 'The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.',
cc @manic compass to take over, looks like you missed this thread
Your problem is that you are misunderstanding the whole API. You can not just pass the new phase. You have to pass both the current phase and the new one
it's exactly what we do on https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#upgrading-subscriptions with a clear example
Apologies all. Getting caught up. Let me know if you have any follow-up questions @limpid ocean
how can i pass the current phase?
please read the example I gave you a link to
it clearly passes two phases and you need to do the same
Yes i did that
you look at the schedule, it already has a phase, you re-pass the same information and add a second phase
await stripe.subscriptionSchedules.update(
'sub_sched_1LSOUdBvyoQdH1ijDfWUR3M4',//subscriptionSchedule.id,
{
phases: [
{
items: [
{price: 'price_1JpytcBvyoQdH1ijcWqZFhaR', quantity: 1},
],
iterations: 1
},
{
items: [
{price: 'price_1LQr8MBvyoQdH1ijWUjVwmnF', quantity: 1},
]
},
],
}
);
I tried with this
Still getting the previous error
I believe you need to pass a start_date along with the first phase, as the error indicated. Can you try that?
I've tried that
but let me try again
I get this 'You can not modify the start date of the current phase.',
Ah, right, because the subscription schedule already has a start_date for the first phase. Just to back up a little bit, what are you actually trying to do? What do you want to happen as a result of the update? Are you simply wanting to update a phase, or are you updating a phase in order to achieve some other goal?
So I want to update the price of the subscription for all my customers, starting from their next period, so they suggested me to use the subscription schedule, currently I'm trying to using creating a subscription schedule from a regular subscription using this
const schedule = await stripe.subscriptionSchedules.create({
from_subscription: 'sub_GB98WOvaRAWPl6'
});
and then I would like to add a phase to move the subscription to a new price
Okay, and did you specify a start_date on the new phase you created as well?
No
I used this
Can you try specifying start_date: 'now' for the second phase?
ok, but it should not start now
it should start at the end of the current period
await stripe.subscriptionSchedules.update(
'sub_sched_1LSOUdBvyoQdH1ijDfWUR3M4',//subscriptionSchedule.id,
{
phases: [
{
items: [
{price: 'price_1JpytcBvyoQdH1ijcWqZFhaR', quantity: 1},
],
iterations: 1
},
{
start_date: 'now',
items: [
{price: 'price_1LQr8MBvyoQdH1ijWUjVwmnF', quantity: 1},
]
},
],
}
);
I've changed my code to this, but i still get 'The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.',
👋 I'm hopping in to help
Can you clarify something really quick - at what point do you want the subscription to move from price A -> price B? Right now you have a trial set on the subscription, so do you want the price to move right after the trial? Or the cycle AFTER the trial (so three months after the trial ends)?
Ok so I got some subscriptions with trials and some without
I want all of them to move to the new price after they end the current period
If they got trial after trial they need to move to the new price, if they got normal subscription after the end of the current period they need to pay the new price the next time
Ah also after trial they have to pay the current price and then move to the new one
^^ So in the trialing case you don't want them to move on to the new price until AFTER they've paid for the current price for one period?
While i'm waiting for an answer to that let me give a bit more detail on what you need to do in your request
Yes
The issue here is that in your update request you need to be re-passing in the same information about the phases you want to keep in addition to the additional phase to switch to the new price. . So if you look at the creation request of the schedule sub_sched_1LSOUdBvyoQdH1ijDfWUR3M4 that you're trying to update - https://dashboard.stripe.com/logs/req_Bq4iaxE6BSscsQ - you can see that we generated some phases that have a lot of other information on them like start_date, end_date , trial_end, trial , etc. You need to include those phases in your update request and then add on the additional phases (remove the start_date: now) with the new price
Does that make sense?
Yup, for the trialing one you'll have three phases - first one is for the trial, second one is for the phase on the current price, third is for the phase on the new price
will the subscriptionid be the same after the phases?
Yup!
const convertSubscription = async subId => {
const subscriptionSchedule = await stripe.subscriptionSchedules.create({
from_subscription: subId,
});
const newPhases = subscriptionSchedule.phases.map(el => ({items: el.items, start_date: el.start_date, end_date: el.end_date, trial: el.trial}))
newPhases.push({items: [{ price: 'price_1LQr8MBvyoQdH1ijWUjVwmnF', quantity: 1 }]})
await stripe.subscriptionSchedules.update(
subscriptionSchedule.id,
{
phases: newPhases
}
);
console.log('success ', subscriptionSchedule.id);
}
I have made it this way, I hope everything will be fine
also i wanted to ask
I need to update all my customers, around 600
will I encounter some ratelimits if I try to update them all together
Yeah we have rate limits of 100 requests per second, so you should definitely account for this in your script and add some time in between reqeusts to make sure you don't hit out limits