#Angus-subscription-schedules

1 messages · Page 1 of 1 (latest)

grave siren
#

Hey there, just to make sure I'm understanding correctly, you already have some subscription schedules created and you're looking to make changes to those?

covert lake
#

Yeah that's right

#

stripe.subscriptionSchedules.update etc.

#

I am:
1) using a checkout session to create a subscription
2) immediately after, creating the subscription schedule from that subscription
3) immediately after, updating that subscription schedule to add a few more steps
All good so far
4) (this is where I'm having trouble) at some arbitrary point in the future, I need to update the quantity of the one item in each phase of the schedule.

It's a very simple use case, I want to change the number of seats in my upcoming subscription phases.

grave siren
#

Apologies for the delay, I was testing out an approach locally looking for an easy approach.

covert lake
#

Yeah I tried just setting one field but it shat itself

grave siren
#

What I tried that might work for you was using the stripe.SubscriptionSchedule.retrieve to pull the schedule, but I stored it in a variable. Then I pulled the phases out as their own object which could then be passed back into the update function after making changes.

covert lake
#

Yeah that's basically what I'm trying

#
const subs = await stripe.subscriptions.retrieve(org.licence.subscriptionId, {
    expand: ['schedule'],
});

await stripe.subscriptionSchedules.update(subs.schedule.id, {
    phases: subs.schedule.phases.map((phase) => ({
        items: phase.items.map((phaseItem) => ({
            price:
                typeof phaseItem.price === 'string'
                    ? phaseItem.price
                    : phaseItem.price.id,
            quantity: newQuantity,
        })),
        start_date: phase.start_date || undefined,
        trial_end: phase.trial_end || undefined,
        end_date: phase.end_date || undefined,
    })),
});
#

This is in js, hopefully you're familiar

#

You can see I'm just trying to make everything the same except for newQuantity

grave siren
#

Hm, that expand parameter has caught my eye, is that retrieve call completing successfully?

covert lake
#

oooooo

#

Good spot, I'll check

grave siren
#

I'm doing my testing against our python library, but it didn't like when I tried to mimic that expand

covert lake
#

I've been running this in the cli and assumed it would be the same:
stripe subscriptions retrieve sub_1Jf2g3IO91nskAnBEohXXXXX --expand schedule
That cli command does what you expect

grave siren
#

Ah, apologies, I just took a closer look and realized I overlooked a key difference. I've been retrieving the subscription schedule itself, rather than getting it from the subscription. Give me a moment to go through this again.

covert lake
#

Hey just a brief aside, I found a bug in the UI
This is taken from the manage schedules in the customer view

#

this is taken from the payments tab

#

The top one is incorrectly showing $0, and it is the same schedule from the same subscription.

grave siren
#

Hm, we would need to dig into that and make sure there isn't something like a free trial or a coupon changing those prices.

covert lake
#

There is a free trial, no coupons

grave siren
#

Do you have the error message that you were receiving handy? From when you were trying to update the sub sched.

covert lake
#

One moment, I think it's actually working...

tight belfry
covert lake
#

Let's take a step back

If you look at my last screenshot, that is showing a schedule doing exactly what I want it to be doing.

#

That screenshot there, is an example of the half broken update that I was trying to fix.

#

Let me run this scenario through again to make sure

covert lake
#

Yeah look, it's not working for me.

#

I'm going to keep hammering away and I'll comment here in a while if I still can't nut it out.

grave siren
#

I'm also still trying to programmatically step through this approach. If you hit another error please share it here, as that will likely help point us in the right direction.

covert lake
#

@grave siren

#

You're a hero

#

Can you explain this to me:

403 error StripeInvalidRequestError: You can not update a phase that has already ended. Trying to update phase 0.

#

requestId: 'req_pLPagWktzewgsZ',

grave siren
#

Thanks for that info, taking a closer look, bear with me.

covert lake
#

The end date of both phases is in the future

#

This showed something different if you have access to this stuff: stripe subscriptions retrieve sub_1Jf496IO91nskAnBPEHlI17d --expand schedule

#

FYI, I'm getting another error: 403 error StripeInvalidRequestError: You can not modify the start date of the current phase
requestId: 'req_H9B7NUXZoYFrDT'

#

Honestly, it is so fucking hard to update scheduled subscription quantities!

#

hahaha

grave siren
#

Haha, schedules are definitely tricky

covert lake
#

Because of how much logic is required to get them to work, I'm doing my best to avoid them as much as possible now. So I'm trying to restructure things a bit.

grave siren
#

Understandable, I'm still combing through things trying to figure out where the concern is, apologies for the delays.

covert lake
#

If I have max 2 phases, I can easily hard code them.
Because I will either have:

  • one live phase and one upcoming,
  • or the the schedule has completed and no longer exists.
#

Okay @grave siren thanks for your listening ear

#

See ya!

grave siren
#

Sorry, I couldn't be of more help 😦

tight belfry