#bibek_api

1 messages ยท Page 1 of 1 (latest)

dusky remnantBOT
#

๐Ÿ‘‹ 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.

lapis cradle
#

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?

granite zealot
#

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
}
]
)

lapis cradle
#

So you created a Subscription Schedule and kept the existing Subscription?

granite zealot
#

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

lapis cradle
#

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.

granite zealot
#

can you provide some code structure for that?

lapis cradle
granite zealot
#

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 ?

dusky remnantBOT
lapis cradle
#

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?

granite zealot
#

yes, exactly.

fleet flare
#

๐Ÿ‘‹ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!

granite zealot
#

should i add scedule to current subscription ? and how can i pass the downgraded pricing and interval to the schedule ?

fleet flare
#

but instead of creating the subscription from the start with 2 phases

granite zealot
#

Thanks for the help. will try with these info and will connect if any issues and questions.

#

should i keep pricing and interval of downgraded plan in the first item of the phase or in the second item ?