#bibek_code

1 messages ยท Page 1 of 1 (latest)

slow orchidBOT
#

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

radiant sparrow
#

Hi there, you need include all information, including the items of the existing phase(s), when updating a subscription schedule.

cinder pivot
#

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

radiant sparrow
#

Hmm, I don't think you can create a schedule without a phase

cinder pivot
#

but this is how stripe team suggested me yesterday.

radiant sparrow
#

Why do you want to create a schedule without a phase?

cinder pivot
#

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 "

radiant sparrow
#

Anyway, as I mentioned earlier, when you update a schedule, you need to include the information of existing phase(s).

cinder pivot
#

but instead of creating a new subscriptionSchedule we need to add subscriptionSchedule for existing plan right for my requirement ?

radiant sparrow
#

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.

slow orchidBOT
cinder pivot
#

This way was recommended by stripe developers team yesterday. what will be the ideal way for this requirement?

radiant sparrow
#

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?

cinder pivot
#

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'

radiant sparrow
#

How did you import stripe?

cinder pivot
#

just like this import stripe

radiant sparrow
#

it's SubscriptionSchedule, not Subscriptionschedule

cinder pivot
#

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

radiant sparrow
#

You can check the error message to understand why the request failed. phases[0][items] expects an array, but you passed in an object

cinder pivot
#

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 ?

radiant sparrow
#

No, as I repeated many times, you still need to include the existing content of the existing phases when updating the schedule.

slow orchidBOT
cinder pivot
#

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 ?

fleet bane
#

You have to do it in 2 separate steps:

  1. Create a Subscription Schedule with from_subscription parameter.
  2. Update the Schedule with the new phase.
cinder pivot
#

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

fleet bane
cinder pivot
#

okey, i will look for it.

slow orchidBOT
real dirge
#

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

cinder pivot
#

sure, i am looking for request id

real dirge
#

take your time

cinder pivot
#

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

real dirge
#

would you mind pasting the error?

cinder pivot
#

sure, this is the error TypeError: 'builtin_function_or_method' object is not subscriptable

real dirge
#

you need to only pass the ID not the whole object

#

of the price