#bibek_code
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/1297864587093217283
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- bibek_api, 23 minutes ago, 23 messages
now it gives Received unknown parameter: phases[0][start_date]
hi! you'd two API calls, one to create the Schedule, and then in the second call you update it with the first phase the same, and the second phase with start_date=current_period_end and the items set to the monthly plan.
so i can't include the phases in the create api right ?
right
here is the updated code `subscriptionSchedule = stripe.SubscriptionSchedule.create({
from_subscription: current_subscription.id,
})
stripe.SubscriptionSchedule.update(
subscriptionSchedule.id,
phases=[
{
'start_date': 'now', # Start immediately with the current pricing
'end_date': current_subscription.current_period_end,
# Phase ends when the current billing cycle ends
},
{
'items': [
{
'price_data': {
'currency': price.currency.code_for_stripe,
'product': current_app.config['STRIPE_PRODUCTS']['tier-product'],
'recurring': {
'interval': interval # The new interval (e.g., monthly)
},
'unit_amount': price.price, # The new downgraded price
},
},
],
'start_date': current_subscription.current_period_end,
# Downgrade takes effect after the current period
'end_behavior': 'release', # No further phases after the downgrade
},
],
)` but it gives "NameError: name 'from_subscription' is not defined
"
shouldn't it be 'from_subscription': (in quotes) for python?
or from_subscription= as per the docs : https://docs.stripe.com/billing/subscriptions/subscription-schedules/use-cases?lang=python#existing-subscription
right, thanks for the help ๐
now , it gives stripe._error.AuthenticationError: Invalid API Key provided: {'from_s****************************************xk'}
yeah it's because you're passing things in {} for some reason
when you pass a dict like that we assume the first param is a key.
anyway, just do what the docs linked above have.
stripe.SubscriptionSchedule.create(from_subscription='sub_xxx')
okey
now, it gives TypeError: StripeObject.update() got an unexpected keyword argument 'phases'
what is the code that triggers that?
and what version of stripe-python are you using?
this is code stripe.SubscriptionSchedule.update( subscriptionSchedule.id, phases=[ { 'start_date': 'now', # Start immediately with the current pricing 'end_date': current_subscription.current_period_end, # Phase ends when the current billing cycle ends }, { 'items': [ { 'price_data': { 'currency': price.currency.code_for_stripe, 'product': current_app.config['STRIPE_PRODUCTS']['tier-product'], 'recurring': { 'interval': interval # The new interval (e.g., monthly) }, 'unit_amount': price.price, # The new downgraded price }, }, ], 'start_date': current_subscription.current_period_end, # Downgrade takes effect after the current period 'end_behavior': 'release', # No further phases after the downgrade }, ], ) and stripe version is 1.21.5
yeah that version is 9 years old and doesn't support the syntax in the docs
you should probably update, but otherwise the thing is you can not call stripe.SubscriptionSchedule.update "statically" in those old versions, instead you have to call mySubscriptionScheduleVariable.update(...) on an instance variable(returned from the create call) as far as I know
if i call instance variable should the arguments should be same ?
minus the ID but otherwise the same I think
yah, it works but it takes me to card info fill page when i submit my card info it charges for the downgraded plan instantly but requirement was to charge at the end of the current billing cycle.
what's the subscription ID sub_xxx where that happened?
sub_1QCIEZCACL6AzfJteYhNLyxk
hmm I'm slightly lost since all I see there is you created a subscription with Checkout, then you created a Schedule with from_subscription, and then you just cancelled the Schedule without ever updating phases
okey i will try with the new customer
yah, you were right it was canceled before, with new customer and this code `subscriptionSchedule = stripe.SubscriptionSchedule.create(
from_subscription = current_subscription.id,
)
subscriptionSchedule.update(
phases=[
{
'start_date': 'now', # Start immediately with the current pricing
'end_date': current_subscription.current_period_end,
# Phase ends when the current billing cycle ends
},
{
'items': [
{
'price_data': {
'currency': price.currency.code_for_stripe,
'product': current_app.config['STRIPE_PRODUCTS']['tier-product'],
'recurring': {
'interval': interval # The new interval (e.g., monthly)
},
'unit_amount': price.price, # The new downgraded price
},
},
],
'start_date': current_subscription.current_period_end,
# Downgrade takes effect after the current period
'end_behavior': 'release', # No further phases after the downgrade
},
],
)` i still get this error `TypeError: StripeObject.update() got an unexpected keyword argument 'phases'`
yeah I'm not sure sorry, I haven't used this old version of the SDK
can you update to the latest version and then it will be easier to follow the docs
now, i have installed 1.21.10, is it the latest one ?
You mean the latest Python Stripe SDK?
The latest version is v11.1.1
https://github.com/stripe/stripe-python/releases/tag/v11.1.1
Stripe cli
yah, the stripe sdk version is 11.1.1
i get this error Error Downgrading subscription item: Request req_VMI59pNWw69U2O: You cannot migrate a subscription that is already attached to a schedule: sub_sched_1QCJEPCACL6AzfJt16DiqwYN``
The error message, seems enough explicit
the subscription is already attached to a scheduler
i got this error TypeError: StripeObject.update() got an unexpected keyword argument 'phases' in this part of the code stripe.SubscriptionSchedule.update( subscriptionSchedule.id, phases=[ { 'start_date': 'now', # Start immediately with the current pricing 'end_date': current_subscription.current_period_end, # Phase ends when the current billing cycle ends }, { 'items': [ { 'price_data': { 'currency': price.currency.code_for_stripe, 'product': current_app.config['STRIPE_PRODUCTS']['tier-product'], 'recurring': { 'interval': interval # The new interval (e.g., monthly) }, 'unit_amount': price.price, # The new downgraded price }, }, ], 'start_date': current_subscription.current_period_end, # Downgrade takes effect after the current period 'end_behavior': 'release', # No further phases after the downgrade }, ], )
Can you share the requestId?