#santos-schedule-phases
1 messages · Page 1 of 1 (latest)
santos-schedule-phases
@limber minnow The easiest is to try this in Test mode and see what happens. But fairly sure the dates have to be sequential
I confirmed that the phases have to be sequential @limber minnow
Yep, just verified this in test mode:
stripe.error.InvalidRequestError: Request req: There is a gap between phase 0 `(1672860538, 1704396538)` and phase 1 `(1736018938, 1767554938)`.
Any advice on removing phases in between subscription schedules? Does Stripe recommend this? The updating of start and end dates is not ideal since we'd want to correctly update them.
You should just be able to update the schedule and provide the new list of phases that you want. So if you want to remove a phase, you can just exclude it from the new list of phases when you make your update call
Does that make sense for your use case? If not can you tell me more about what you are trying to do here?
I think using the example from the beginning, I have 3 phases [1,2,3]. I want to remove the second phase and have the third phase start right after the first phase since the second phase was removed since the new phase list is now [1,3].
Here's the code I was using in test mode:
import time
from django.utils import timezone
import stripe
# create subscription schedule
schedule = stripe.SubscriptionSchedule.create(from_subscription="sub_1MMcdyELRGuFUMs64eSIMCdt")
print_phase = {"items": [{'plan': "plan_print_standard6999"}],"iterations": 1,'proration_behavior': 'none'}
now = int(time.mktime(timezone.now().timetuple()))
# grab existing phases from subscription schedule
phases_1 = [{'items': [{'plan': pl.plan} for pl in p.plans],'start_date': p.start_date,'end_date': p.end_date,'coupon': p.coupon if "coupon" in p else None,'proration_behavior': 'none',} for p in schedule.phases if p.end_date > now]
phases_1.append(print_phase)
# add new print phase
schedule = stripe.SubscriptionSchedule.modify(schedule.id, phases=phases_1, end_behavior='cancel')
premium_phase = {"items": [{'plan': "plan_premium_standard"}],"iterations": 1,'proration_behavior': 'none'}
now = int(time.mktime(timezone.now().timetuple()))
# grab existing phases from subscription schedule (now include print)
phases_2 = [{'items': [{'plan': pl.plan} for pl in p.plans],'start_date': p.start_date,'end_date': p.end_date,'coupon': p.coupon if "coupon" in p else None,'proration_behavior': 'none',} for p in schedule.phases if p.end_date > now]
phases_2.append(premium_phase)
# add new premium phase
schedule = stripe.SubscriptionSchedule.modify(schedule.id, phases=phases_2, end_behavior='cancel')
# remove print phase
del phases_2[1]
# stripe throws InvalidRequestError exception
stripe.SubscriptionSchedule.modify(schedule.id, phases=phases_2)
Oh gotcha, sorry I glossed over your error message before. So the error is basically that there is a gap between your first phase's end date and your third phase's start date?
I think the two ways this is typically done are
- Only define
start_dateorend_datefor each phase, the schedule will know to move on once it passes the end date of the current phase or the start date of the next phase - Edit your phase data so that the ends and starts line up for all three phases
Here's the new phase list data with start and end dates (there is a gap between them):
[
{
"end_date":1704396538,
"plans":[
{
"plan":"plan_digital_standard5999",
"price":"plan_digital_standard5999"
}
],
"start_date":1672860538
},
{
"end_date":1767554938,
"plans":[
{
"plan":"plan_premium_standard",
"price":"plan_premium_standard"
}
],
"start_date":1736018938
}
]
Are you saying I can keep the start date and pop off the end date data and Stripe will fix the gap under approach 1?
Yes, if you only provide a start date for the first phase or only provide an end date in the second phase, the API should be able to recognize the proper start and end times for each
I see. I popped off the end dates and got:
stripe.error.InvalidRequestError: Request req_uID2rJe4L9EHPK: Phase 0 is invalid. Each phase must specify either `iterations` (recommended) or `end_date` (advanced), unless it is the last phase and `end_behavior` is `release`.
Will try with iterations since it is recommended. Assuming Stripe will handled the dates here.
Whoops, my apologies. I think I somehow misremembered that last phase behavior as how all phases work.
Yes iterations can also be very helpful here. They will make sure the subscription goes through full cycles and transitions exactly at the end
Okay, it looks like I can leave start and end dates on the first phase and remove start and end dates from the phases after the first and make sure to add iterations key. See https://dashboard.stripe.com/test/logs/req_EuaXmAQz3FVojL
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
How does that sound?
That makes sense, the first phase would end, the second one would go for however many iterations, and then the next phase would happen if there is one, otherwise the schedule will trigger its end behavior. You can set the end behavior to either cancel the subscription or release it from the schedule and leave it as is
Thank you. I'll go ahead and continue testing that solution.