#robert_api

1 messages ¡ Page 1 of 1 (latest)

merry solsticeBOT
#

👋 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/1280675723140403342

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

scenic egret
#

Hi there

inner slate
#

Idelally there's some sort of iterations property in the phases object, like the update/creation payloads. Just looking for the number.

And for context, I'm trying to update an existing phase in an existing Subscription Schedule to use a different price -- so if there's an easier way to do that, let me know :)

scenic egret
#

Hm, double checking but I think we just pivot over to using end_date and calculate this based on the # of iterations

#

Yep, looks like that's what we do

#

So there's no iterations property on the phase, you just need to look at end_date to determine when that phase will end and when the Subscription will transition to the next phase

#

update an existing phase in an existing Subscription Schedule to use a different price
Assuming you have that existing phase's end_date, you'll just need to pass the same end_date for that phase in your call to update the Schedule

inner slate
#

Makes sense if we can use end_date, stepping back: is this the right way of updating an existing phase of an existing schedule to a new price? (description & proration_behavior are the two fields we control in creation)

        const existingSchedule = await stripe.subscriptionSchedules.retrieve(<id>);

        const updatedPhase = {
          description: existingSchedule.phases[0].description,
          proration_behavior: existingSchedule.phases[0].proration_behavior,
          end_date: existingSchedule.phases[0].end_date,
          items: [{ price: stripePrice }],
        };

        await stripe.subscriptionSchedules.update(<id>,
          {
            phases: [updatedPhase],
            proration_behavior: 'none' as const,
          },
        );
merry solsticeBOT
north anchor
#

How many phases are there in your subscription schedule before the update? In your code, the update phases of subscription schedule will override your existing one and only have one phase left

inner slate
#

Oh sorry, should'e mentioned. We can guarantee there will only be one phase in these schedules

#

But I'd like not to override it, instead update if possible - this phase might have already had an iteration and you can't update the start date of it down the line in that case

north anchor
#

If there is only one phase, is there any reason why you can't update the subscription directly? Why is subscription schedule needed?

#

Could you share what you would like to achieve in an example, so that I can provide a solution that fits your use case?

inner slate
#

Sure-

I have a subscription schedule charging Price A, which is $10/month. It starts September 10th and runs for 12 months before cancelling

In November (3 months after it started), I want to update the subscription to instead use Price B and make the remaining iterations use it, but keep all the previous behavior (remaining # of iterations, etc)

I'm using schedules in the code here because that's what this block operates on, but if I should be updating the subscription that makes sense - all I have is the subscription schedule id and the id of the new price

north anchor
#

Thanks for sharing the information. This is very helpful

inner slate
#

Great! Let me verify this works, one min

#

Worked, thank you!