#santos-schedule-phases

1 messages · Page 1 of 1 (latest)

hollow moonBOT
manic crag
#

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

manic crag
#

I confirmed that the phases have to be sequential @limber minnow

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.

rough jungle
#

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?

limber minnow
#

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)
rough jungle
#

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

  1. Only define start_date or end_date for 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
  2. Edit your phase data so that the ends and starts line up for all three phases
limber minnow
#

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?

rough jungle
#

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

limber minnow
#

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.

rough jungle
#

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

limber minnow
#

How does that sound?

rough jungle
#

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

limber minnow
#

Thank you. I'll go ahead and continue testing that solution.