#DanTheGoodman - Subscription Extensions
1 messages ยท Page 1 of 1 (latest)
Hello! Let me think about this a moment...
Either of those approaches should work. A third option is to adjust the trial period, but that may not work if the trial period gets too big, so I think adjusting the Subscription Schedule is probably best.
really want to avoid trials
@robust girder does the current_period_end reflect the index 0 item in the subscription schedule?
Meaning the current_period_end on the Subscription itself? If so, that only reflects the current state of the Subscription itself, it doesn't take into account the Subscription Schedule.
so if I made a schedule for an existing subscription, and then made a interval 6 100% of coupon period, that current_period_end would only show the end of the first interval?
If you're managing the Subscription with a Subscription Schedule could you add one phase for each extension?
yeah I guess I'd have to add before the last phase if one exists
so insert after index -2
Separate phases might makes things cleaner and easier to reason about vs. stacking extensions on a single phase.
when a phase ends, it is popped off the front of the list of current phases (response from the GET)?
I think so, but let me see if I can confirm that...
cool thanks
Okay, so it should show all the phases, even ones in the past. However, if you update a Subscription Schedule's phases when there are older phases already in the past your update may cause those already-passed phases to drop off.
hmm ok... seems tricky tbh
with chargebee it's a nice as just setting the next billing date :/, maybe there is a better way to handle this?
I guess I could replace with a new schedule? with the modified first and second phases if there is a first one that I need to extend
๐ Hopping in since @robust girder had to head out - give me a minute to catch up
thanks
How much have you worked with Schedules so far? This is something that you can definitely model w/ subscription schedule updates, and I wouldn't recommend going down the replace w/ a new schedule route because it's more api requests then you need
none so far
so if I just replace all the phases, does that just sort of upsert it?
I see
Note that past phases can be omitted.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
yeah it would basically be an upsert
ok so I can just simply call update (or create if one does not exist), and change the phases
and I just set the start date to now
well let's talk through what the phases should look like a bit more
when you say set the start date to now, what specific start date are you talking about? The start date of the schedule? The start date of the phase that will give them an extension?
the schedule
so basically there are going to be 3 cases:
- No schedule, first time giving 100% off coupon
- Current schedule, currently in 100% coupon, need to change the first phase to be the expiry + 30 days (and set schedule start to now)
- Current schedule, 100% is over, need to create a fresh one with 100% that starts now and ends in 30 days (and set schedule start to now)
So one thing I want to clarify first - if you want to create a Schedule for a Subscription you don't need to specify a start_date when you create it. You'd pass in the Subscription ID to from_subscription (see https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-from_subscription) and we'll automatically generate a Schedule that's already started and is tied to the subscription
Now going into the three use cases:
Actually before I go into the three flows - is your ideal behavior that the extension kicks in AFTER the current cycle is over, or should it kick in immediately and once the extension is over it finished out the rest of the cycle it was in the middle of. It'll be much cleaner to do this with the extension kicking in after the current cycle
i'd want it to kick in immediately
well I guess it could be after..
just want to prevent a renewal basically if the 100% off coupon is redeemed, and stack as needed
but what I can do to simplify the logic of how to check for if a schedule phase needs to be extended is probably just set it to start now, but make the first phase end after the current_period_end of the subscription + 30 days
Let's say you have a monthly subscription that started on August 1st. On August 15th they get a 30 day extension. There are two different flows you can have:
- Start the 30 day "free period" from August 15th - September 15th. Move back into the normal, not free period from Sept 15 - Oct 1.
- Let the current period finish from August 1 - Sept 1. Then move into the 30 day extension period from Sept 1 - Oct 1.
Option 1 is actually more difficult to model correctly with Schedules because what your describing (adding 30 days + current_period_end) will turn that whole time period from August 15- October 1 to a "free" period.
I can see why that is easier to start, but if we need to add a 30 day free period Nov 13th, that old schedule will show and we have to do some logic to figure out which period they are in and make a new schedule based on that, right?
What do you mean by "that old schedule will show"? In the above example, the extension phase would be done by Oct 1, and then the schedule should move back into a normal, non-extension phase
Ah, I see what you're getting at - you have concerns with having to add logic that determines what the actual current phase is, right?
yeah
So the Schedule itself does have current_phase as a top-level attribute which should tell you what the current phase is from the list (see https://stripe.com/docs/api/subscription_schedules/object#subscription_schedule_object-current_phase)
now when I sort of do this upsert, do I need to preserve the old phase array for any reason? Or can I just construct a new one?
For some cases I probably have to do a "start now" thing, like when extending a currently free phase
You don't have to preserve the old phases if it makes your logic/integration easier
How do I tell a phase to start at the end of hte current period?
When the subscription schedule starts. We recommend using now so that it starts the subscription immediately. You can also use a Unix timestamp to backdate the subscription so that it starts on a past date, or set a future date for the subscription to start on.
I guess I'd need to calculate that too anyway?
The way it would work is that you'd have a phase that represents the current period, and then you add an additional phase after that which will start as soon as the current period ends
ok, so start would still be now?
and you wouldn't need to set start_date at all - like I mentioned, if you're working with subscriptions you'd use from_subscription to generate the schedules and it'll start it immediately
yes - when you create the schedule with from_subscription that'll create a schedule that matches exactly what the subscription looks like at the time. The current phase of that schedule will match the current billing cycle as well
I need to head out soon, but does that cover a lot of the basics? Really I think the best way to get familiar with sub schedules is to start trying out a bunch of things in test mode to see how it works.
and if you haven't already, would definitely recommend reading through these:
Yeah this was great, thanks
๐ If you need anything else @low dock is around to help!
๐