#bibek_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/1297839923340120125
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi, let me help you with this.
schedule the downgraded pricing in the end of the current cycle but it creates two subscription and both deducts amount for invoice.
How did you achieve this exactly?
Hello, this is the code i have implemented for downgraded plan.
stripe.SubscriptionSchedule.create(
customer=clinician.stripe_customer_id,
start_date=current_subscription.current_period_end,
# Downgrade takes effect at the end of the current billing cycle
end_behavior='release', # Release the schedule after the downgrade
phases=[
{
'items': [{
'price_data': {
'currency': price.currency.code_for_stripe,
'product': current_app.config['STRIPE_PRODUCTS']['tier-product'],
'recurring': {
'interval': interval
# Switch to monthly or yearly based on the downgrade
},
'unit_amount': price.price, # The new price after the downgrade
},
}],
'proration_behavior': 'none', # Prevent proration, no immediate charges
}
]
)
So you created a Subscription Schedule and kept the existing Subscription?
yah, my idea was just updating the pricing and interval of current subscription with the downgraded subscription and apply it in the end of the current billing cycle
Instead of creating a completely new Schedule, you can turn your existing Subscription into a Subscription Schedule. And then add a second phase to it that will define the downgrade.
can you provide some code structure for that?
The first step is in the section I shared. The next step is to update the Subscription Schedule to add another phase: https://docs.stripe.com/api/subscriptions/update.
Thanks for the info but when the interval is changed it charges immediately which i don't want, do you suggest anything to avoid this ?
The Subscription Schedule will execute the upgrade when you specify. You can instruct it to go until the end of the current period (yearly) and then charge at the start of the next one (monthly), so there's only one charge. Is this what you're trying to achieve?
yes, exactly.
๐ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!
should i add scedule to current subscription ? and how can i pass the downgraded pricing and interval to the schedule ?
you can start here https://docs.stripe.com/billing/subscriptions/subscription-schedules/use-cases#downgrading-subscriptions
but instead of creating the subscription from the start with 2 phases
you should create the schedule from the subscription https://docs.stripe.com/billing/subscriptions/subscription-schedules#:~:text=You can also create subscription schedules by passing a subscription ID%3A