#horlaarsco_schedule-downgrade

1 messages ยท Page 1 of 1 (latest)

pseudo orchidBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1243240431878275252

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

lone loom
#

horlaarsco_schedule-downgrade

hoary echo
#

Oh didnt know about that, checking out the docs

hoary echo
#

When i call generate invoice is there a proration behaviour i can pass that will return 0 if it looks like a downgrade or is it safe to assume if i am getting negative from generate invoice it is a downgrade

lone loom
#

I don't know what you mean by "generate Invoice" I'm sorry. You said you wanted to downgrade at the end of the period so there won't be no Invoice

hoary echo
#

Invoice would only be generated when the schedule takes effect right?

lone loom
#

I pay for $100/year on January 1st. On May 23 I ask you to switch me to $10/month. You decide that instead of crediting me, it's best if I use my full year first so you put me on a SubscriptionSchedule so that on January 1st 2025 I switch to $10/month. There will be no Invoice until that January 1st 2025 when I switch to monthly
Does that make sense?

pseudo orchidBOT
hoary echo
#

Yes that does what im confused about now is how to configure the phases

#

I try this:

const schedule = await this.stripe.subscriptionSchedules.create({
from_subscription: subscriptionId,
});

await this.stripe.subscriptionSchedules.update(schedule.id, {
  phases: [
    {
      start_date: schedule.phases[0].start_date,
      end_date: schedule.phases[0].end_date,
      items: [
        { price: schedule.phases[0].items[0].price as string, },
      ],
    },
    {
      start_date: schedule.phases[0].end_date,
      items: [{ price:newPrice, quantity:sameQuantity }],
    },
  ],
});

Getting: The last phase must specify either iterations (preferred) or end_date (advanced) if end_behavior is not `release

fluid beacon
#

Hi ๐Ÿ‘‹

I'm stepping in as my colleague needs to go. Can you outline the specific changes you want to make between the phases?

hoary echo
#

I just want to update the priceId to the new priceId at the end, quantity and everything else remains same

fluid beacon
hoary echo
#

I get this error though

The last phase must specify either iterations (preferred) or end_date (advanced) if end_behavior is not `release

fluid beacon
#

RIght, sorry. So you just want the subscription to make that one change and then continue like that unless canceled?

hoary echo
#

Yes, the current subscription would remain active unless cancelled but the downgrade should only happen at the end of the current billing period

fluid beacon
hoary echo
#

const schedule = await this.stripe.subscriptionSchedules.create({
from_subscription: subscriptionId,
});

await this.stripe.subscriptionSchedules.update(schedule.id, {
  phases: [
    {
      start_date: schedule.phases[0].start_date,
      end_date: schedule.phases[0].end_date,
      items: [{ price: schedule.phases[0].items[0].price as string }],
    },
    {
      start_date: schedule.phases[0].end_date,
      items: [{ price, quantity }],
      iterations: 1,
    },
  ],
  end_behavior: 'release',
});

This seems to work, but just to confirm here is the scenario I want. I have a yearly subscription that started Jan 1st 2024 and would end Dec 31st 2024. I then choose to downgrade to monthly today.

If i run the above code with the subscription and the monthly priceId. My subscription would remain as is till 31st December 2024 and then on Jan 1st 2025, I'll be active with a monthly subscription?

fluid beacon
#

I recommend you use Test Clocks to get a clear picture of exactly what changes will take place when. It's much easier than trying to reason through it just looking at your code