#Angus-subscription-schedules
1 messages · Page 1 of 1 (latest)
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?
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.
Apologies for the delay, I was testing out an approach locally looking for an easy approach.
Yeah I tried just setting one field but it shat itself
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.
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
Hm, that expand parameter has caught my eye, is that retrieve call completing successfully?
I'm doing my testing against our python library, but it didn't like when I tried to mimic that expand
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
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.
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.
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.
There is a free trial, no coupons
Do you have the error message that you were receiving handy? From when you were trying to update the sub sched.
One moment, I think it's actually working...
An example request I'd that hits an error would help, eg req_123
https://stripe.com/docs/api/request_ids
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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
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.
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.
@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',
Thanks for that info, taking a closer look, bear with me.
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
Haha, schedules are definitely tricky
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.
Understandable, I'm still combing through things trying to figure out where the concern is, apologies for the delays.
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!
Sorry, I couldn't be of more help 😦
https://dashboard.stripe.com/test/logs/req_pLPagWktzewgsZ because the schedule initially had other phases that ended soon after creation, so something weird might be happening with timing there