#ivan-price-subscription

1 messages · Page 1 of 1 (latest)

tawdry anvil
#

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

finite ruin
#

ty I'll look into that

finite ruin
#

hey, so i've looked into it but I don't understand how I can move the current subcriptions

tawdry anvil
#

What don't you understand exactly?

finite ruin
#

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.',

tawdry anvil
#

how did you update, like what exact code did you pass?

finite ruin
#

I've tried many things

#

but can't seem to get it work

tawdry anvil
#

We're both developers. Just give us real code + a real error and we can help you

finite ruin
#

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.',

tawdry anvil
#

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

manic compass
#

Apologies all. Getting caught up. Let me know if you have any follow-up questions @limpid ocean

finite ruin
tawdry anvil
#

please read the example I gave you a link to

#

it clearly passes two phases and you need to do the same

finite ruin
#

Yes i did that

tawdry anvil
#

you look at the schedule, it already has a phase, you re-pass the same information and add a second phase

finite ruin
#

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

manic compass
#

I believe you need to pass a start_date along with the first phase, as the error indicated. Can you try that?

finite ruin
#

I've tried that

#

but let me try again

#

I get this 'You can not modify the start date of the current phase.',

manic compass
#

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?

finite ruin
#

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

manic compass
#

Okay, and did you specify a start_date on the new phase you created as well?

finite ruin
#

No

manic compass
#

Can you try specifying start_date: 'now' for the second phase?

finite ruin
#

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.',

floral venture
#

👋 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)?

finite ruin
#

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

finite ruin
floral venture
#

^^ 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

floral venture
#

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?

finite ruin
#

yes

#

I'll try it rn, ty

#

so for the trial i would need 3 phases?

floral venture
#

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

finite ruin
#

will the subscriptionid be the same after the phases?

floral venture
#

Yup!

finite ruin
#
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

floral venture
#

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

finite ruin
#

ok ty

#

that's it I think, you can archive the thread, again ty for your help with my issue