#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/1298141219271999560
๐ 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_code, 16 hours ago, 41 messages
- bibek_api, 18 hours ago, 23 messages
Hi there, you need include all information, including the items of the existing phase(s), when updating a subscription schedule.
this is the code "subscriptionschedule = stripe.SubscriptionSchedule.create(
from_subscription=current_subscription.id,
)
stripe.SubscriptionSchedule.modify(
subscriptionschedule.id,
phases=[
{
'start_date': 'now',
'end_date': current_subscription.current_period_end,
},
{
'items': [
{
'price_data': {
'currency': price.currency.code_for_stripe,
'product': current_app.config['STRIPE_PRODUCTS']['tier-product'],
'recurring': {
'interval': interval
},
'unit_amount': price.price,
},
},
],
'start_date': current_subscription.current_period_end,
'end_behavior': 'release',
},
],
)"
but while adding subscription schedule for existing subscription there were no phases added.
initially
Hmm, I don't think you can create a schedule without a phase
but this is how stripe team suggested me yesterday.
Why do you want to create a schedule without a phase?
yesterday stripe team suggested me to " first add a subscription schedule for existing plan and than update the schedule with the phases and in the second item of the phase should incude the downgraded pricing and intervel "
You can create a schedule from an existing subscription https://docs.stripe.com/api/subscription_schedules/create#create_subscription_schedule-from_subscription, and the resulting schedule would include an initial phase.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Anyway, as I mentioned earlier, when you update a schedule, you need to include the information of existing phase(s).
but instead of creating a new subscriptionSchedule we need to add subscriptionSchedule for existing plan right for my requirement ?
You mean creating a new schedule and attach a existing subscription to it? No I don't think you can do it and I don't understand why you want to do it this way.
This way was recommended by stripe developers team yesterday. what will be the ideal way for this requirement?
There must be a misunderstanding. Can I suggest to you follow the link that I shared earlier to create a schedule from an existing subscription?
Sure, i will look into it.
now this is the updated code stripe.Subscriptionschedule.create( from_subscription=current_subscription.id, phases=[ { 'items': { 'price': subscription_item.price.id, }, 'start_date': 'now', # You may want to calculate this properly using timestamps 'end_date': current_subscription.current_period_end, }, { '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, 'end_behavior': 'release', }, ], ) but it gives this error module 'stripe' has no attribute 'Subscriptionschedule'
How did you import stripe?
just like this import stripe
it's SubscriptionSchedule, not Subscriptionschedule
ohh yah, my bad.
This is the updated code :
stripe.SubscriptionSchedule.create( from_subscription=current_subscription.id, start_date='now', phases=[ { 'items': { 'price': subscription_item.price.id, }, 'end_date': current_subscription.current_period_end, }, { '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 }, }, ], 'end_behavior': 'release', }, ], )
but gives this error Request req_stgwH1QJMSqho4: Invalid array
You can check the error message to understand why the request failed. phases[0][items] expects an array, but you passed in an object
As in my understanding, isn't the first object of phases is the current billing cycle for my requirement so just adding end_date for the first object of phases without items info would work ?
No, as I repeated many times, you still need to include the existing content of the existing phases when updating the schedule.
okey
This is the updated code as you suggested stripe.SubscriptionSchedule.create( from_subscription=current_subscription.id, phases=[ { 'items': [ { 'price': subscription_item.price.id, }, ], 'end_date': current_subscription.current_period_end, }, { '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 }, }, ], }, ], ) but now it gives this error Request req_w0mLM6khbnsvRE: You cannot set phasesiffrom_subscription is set.
FYI : my requirement was if customer wants to downgrade from yealy plan to monthly plan and apply the downgraded monthly plan in the end of the current billing cycle and continue with the downgraded plan how to achieve this ?
You have to do it in 2 separate steps:
- Create a Subscription Schedule with from_subscription parameter.
- Update the Schedule with the new phase.
okey
This is the update code:
`schedule = stripe.SubscriptionSchedule.create(
from_subscription=current_subscription.id,
)
# Update the schedule with the new phase
stripe.SubscriptionSchedule.modify(
schedule.id,
phases=[
{
'items': [{
'price': schedule.phases[0].items[0].price,
'quantity': schedule.phases[0].items[0].quantity,
}],
'start_date': schedule.phases[0].start_date,
'end_date': schedule.phases[0].end_date,
},
{
'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
},
},
],
},
],
)`
but got this error 'builtin_function_or_method' object is not subscriptable
Could you please share the Request ID req_xxx? https://support.stripe.com/questions/finding-the-id-for-an-api-request
okey, i will look for it.
๐ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!
sure, i am looking for request id
take your time
please, don't close the thread.
actually, there is no request to the stripe API while this error occurred, the error was from this part schedule.phases[0].items[0].price
from the above code
would you mind pasting the error?
sure, this is the error TypeError: 'builtin_function_or_method' object is not subscriptable