#bibek_code

1 messages ยท Page 1 of 1 (latest)

quiet prairieBOT
#

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

nova shell
#

now it gives Received unknown parameter: phases[0][start_date]

gusty pine
#

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.

nova shell
#

so i can't include the phases in the create api right ?

gusty pine
#

right

nova shell
#

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

"

gusty pine
#

shouldn't it be 'from_subscription': (in quotes) for python?

nova shell
#

right, thanks for the help ๐Ÿ˜…

#

now , it gives stripe._error.AuthenticationError: Invalid API Key provided: {'from_s****************************************xk'}

gusty pine
#

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')

nova shell
#

okey

#

now, it gives TypeError: StripeObject.update() got an unexpected keyword argument 'phases'

gusty pine
#

what is the code that triggers that?
and what version of stripe-python are you using?

nova shell
#

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

gusty pine
#

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

nova shell
#

if i call instance variable should the arguments should be same ?

gusty pine
#

minus the ID but otherwise the same I think

nova shell
#

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.

gusty pine
#

what's the subscription ID sub_xxx where that happened?

nova shell
#

sub_1QCIEZCACL6AzfJteYhNLyxk

gusty pine
#

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

nova shell
#

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'`
quiet prairieBOT
gusty pine
#

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

nova shell
#

now, i have installed 1.21.10, is it the latest one ?

urban basin
#

You mean the latest Python Stripe SDK?

nova shell
#

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``

urban basin
#

The error message, seems enough explicit

#

the subscription is already attached to a scheduler

nova shell
#

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

urban basin