#Nick - subscription migration
1 messages ยท Page 1 of 1 (latest)
Good question. Can you provide the ID of a call you made that reset the billing cycle like that?
Because the metered price I'm trying to convert to is the same product as the licensed price, I have to first add a dummy price, delete the licensed price, and then update the dummy price to be the proper metered one.
So I imagine if I had just edited the existing price from licensed to metered it would have preserved the dates. That's not possible through the API though, you get an error
Thank you. I am unsure if this is possible, checking in to if/how you can do that
Thanks
Hey ๐ it'll take a little bit of work, but I think this use case of Subscription Schedules might be what you're looking for:
https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#resetting-anchor
Sorry, updated link to the exact scenario (Section 10 in case it doesn't jump you there)
Just finding it hard to see how this will help - could you maybe just give me plain text on what each of the schedule steps would look like?
My understanding would be
phase 1: Stay on current price until march 1
phase 2: Switch plan to metered and set the billing_cycle_anchor to that date
But I'm not seeing how I can bill the customer for the month of feb?
Apologies, let me clarify. My thought was:
- You update the subscription now with the new price (which will shift the billing cycle anchor)
- Create a subscription schedule for the sub, and set the
end_dateof the first phase to 1st of the next month. - Use the
billing_cycle_anchorparameter in the second phase to then shift the billing cycle anchor back to the desired date.
Ahh, that does sound promising. When an existing subscription is put into a schedule, can you still query the subscription from the API in the traditional way? Or do you have to get the subscription through the schedule object?
You can still access it the same way. The Subscription Schedule object is a separate entity that essentially just holds scheduled changes for the related Subscription.
Awesome. Ok, I will look into this. Thanks for the suggestion
Any time!
Quick clarification from the docs for sub schedules: https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-from_subscription
I'm going to need to use the from_subscription parameter, and it states To create a subscription schedule with other modifications, we recommend making two separate API calls.
Does this just mean, create the schedule, then update the schedule with the correct phases?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yup, exactly.
Great, thanks
So I'm creating the schedule with:
sub_schedule = stripe.SubscriptionSchedule.create(
from_subscription=subscription.id,
)
And that works. But when I try to update the schedule with:
phases = [
{
'items': [
{
'price': metered_price,
}
],
'end_date': first_of_next_month
},
{
'items': [
{
'price': metered_price,
}
],
'billing_cycle_anchor': 'phase_start'
},
]
stripe.SubscriptionSchedule.modify(
sub_schedule.id,
start_date="now",
phases=phases,
proration_behavior="none"
)
(exactly as it is in the example)
I get the error
The subscription schedule update is missing at least one phase with a `start_date` to anchor end dates to.
start_date isn't a valid parameter on the phase object. It's also not valid on the SubscriptionSchedule create because from_subscription is set
Format all messed up hard to read sorry
No worries, subscription schedules are tricky to read anyway (I always have to read them 2-3 times)
When you create the Subscription Schedule initially, catch phases[0].start_date in a variable. Then when you modify the schedule, pass that value back into phases[0].start_date. Right now all of the dates in that update are relative so the system doesn't know when the phases should be.
I get You can not modify the start date of the current phase.
Oh maybe I didn't echo it back exactly hold on
Yeah so I set:
'start_date': sub_schedule.phases[0].start_date,
On the first phase (sub_schedule is the result of the subscription schedule create call)
but I get Received unknown parameter: start_date
Apologies for the delay, running some tests to remember the exact flow for this.
Alright, so this is what I entered to get the request to succeed:
"sub_sched_12345",
phases=[{
'start_date': '1643727320', #same as current start_date for this phase
'end_date': '1646191471', # March 1st
'items': [{
'price': 'some_price'}],
},
{'start_date':'1646191471', # Also set to March 1st
'items': [{
'price': 'some_price'}],
'billing_cycle_anchor': 'phase_start'}],
end_behavior="release",
)```