#richard_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1354451520598315008
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there ๐ that's because changing the duration of a phase on a Subscription Schedule doesn't directly impact the billing periods of the associated Subscription.
It sounds like what you're trying to do is extend the current billing period of the Subscription, which would involve manipulating it's billing_cycle_anchor:
https://docs.stripe.com/billing/subscriptions/billing-cycle#changing
I'm pretty sure adding a trial period to the active Subscription is the only way to extend the amount of time before the customer is billed again, but am double checking that I'm not forgetting about an alternative approach.
Yeah, even with Subscription Schedules, the most you can do is set the billing cycle anchor to a given time when that time arrives. When updating Subscriptions directly this is done by setting billing_cycle_anchor to now, or when using Subscription Schedules you can tie it to phase_start
https://docs.stripe.com/billing/subscriptions/subscription-schedules/use-cases#resetting-anchor
But you can't arbitrarily set that date to some time in the future, that can only be done by introducing a trial period to the Subscription.
I'll take a look at that, but in theory, we could change the schedule (no proration), by adding in a zero-cost initial phase?
Sorry, I'm not quite sure what you're trying to ask there. What you're describing sounds like it's supported. For a Subscription Schedule that hasn't yet created a Subscription, that would change the behavior of the start of the Subscription. For a Subscription Schedule controlling an existing Subscription, updating the first phase (the current phase) would also cause an update to the underlying Subscription.
or let the current phase compete as normal, add the zero cost phase (of say 5 days), and then repeat the current phase setup?
OK - I think that should work, let me try it
FYI - this seems to do the trick,
import stripe
import datetime
days=5
sub = stripe.Subscription.retrieve('sub_1R6s7NQVwO1T4UtILYU2lIJk')
schedule = stripe.SubscriptionSchedule.retrieve(sub.schedule)
schedule_phases = schedule.phases
current_phase = schedule_phases[0]
next_phase = current_phase.copy()
next_phase.pop('start_date')
next_phase.pop('end_date')
free_price = stripe.Price.create(
currency=sub.currency,
unit_amount=0,
interval_count=days,
recurring={"interval": "day"},
product_data={"name": f"Free Extension: {days} days"},
)
free_phase = {
"items": [{"price": free_price.id}],
"iterations": 1,
}
# 1. grab just one iteration of the current phase
schedule_phases.insert(1, next_phase)
schedule_phases.insert(1, free_phase)
current_phase.iterations = 1
current_phase.end_date = None
stripe.SubscriptionSchedule.modify(schedule.id, phases=schedule.phases)