#surajpatidar

1 messages · Page 1 of 1 (latest)

dim trenchBOT
toxic chasm
rough glacier
#

mean i need to create subsciption shedule with currrent plan right ?

#

i have already read doc but i can't understand well

dim trenchBOT
toxic chasm
#

mean i need to create subsciption shedule with currrent plan right ?
Yes!

#

i have already read doc but i can't understand well
Which part you don't understand?

rough glacier
#

how to downgrade

#

i have change every time only price in subscription right or need to create new subscription ?

deft shadow
#

No you just update the Subscription Schedule, which is generated from your existing Subscription

#

it controls the associated Subscription behaviors

rough glacier
#
            subscription = stripe.Subscription.retrieve(user.subscription.id)
            print(subscription)
            if not int(new_plan.amount) < int(current_plan.amount):
                stripe.Subscription.modify(
                    subscription.id,
                    cancel_at_period_end=False,
                    proration_behavior="always_invoice",
                    items=[
                        {
                            "id": subscription["items"]["data"][0].id,
                            "price": price_id,
                        }
                    ],
                )
                print("Price Greater then current price")
                messages.success(request, "Plan Upgrade SuccessFully.")
            else:
                stripe.SubscriptionSchedule.create(
                    customer=user.customer,
                    start_date='now',
                    end_behavior='release',
                    phases=[
                        {
                            'items': [
                                {'price': new_plan.id, 'quantity': 1},

                            ],
                            'iterations': 1,
                        },

                    ],
                )

                print("price less then current plan")
                messages.success(request, "Plan DownGrade SuccessFully.")

right now i work like that if upgrade show effect immedilty and charge but downgrade show effect after end of the period of current plan

deft shadow
#

You need to create a Subscription Schedule with from_subscription

rough glacier
deft shadow
#

passing in the subscription.id

rough glacier
#

my scenario is if customer have 20$ plan current and if he request for upgrade to 30$
so immediately charge and effect but in downgrade i want if customer 20$ plan current and he request for 10$plan downgrade then effect show after the current plan end the period and charge both

#

for upgrade subscription i write this code and it work

                    subscription.id,
                    cancel_at_period_end=False,
                    proration_behavior="always_invoice",
                    items=[
                        {
                            "id": subscription["items"]["data"][0].id,
                            "price": price_id,
                        }
                    ],
                )```
#

but i want for downgrade as my scenario

deft shadow
#

Yeah, so you will have to write the Subscription Schedule to do your logic

#

to downgrade at end of current billing cycle

rough glacier
#

for downgrade can i write only one phase or need two phase

deft shadow
#

You can write multiple phases

rough glacier
#

but why need multiple phases for downgrade this my main question and i cant' understand this

deft shadow
rough glacier
#

ok

#

i will try don't close chat

#

we need to cancel current plan after downgrade plan

deft shadow
#

When you downgrade, the Subscription will automatically transit to the new, lower plan on time, so you don't need to cancel, I think

rough glacier
#

ok

#

for downgrade it is right or need to modify only subsciption schedule

  customer='cus_GBXV9Q95NFT80k',
  start_date='now',
  end_behavior='release',
  phases=[
    {
      'items': [
        {'price': '{{Cuurent_Price}}', 'quantity': 1},
        {'price': '{{new_price}}', 'quantity': 1},
      ],
      'iterations': 1,
    },
    {
      'items': [
        {'price': '{{new_price}}', 'quantity': 1},
      ],
      'iterations': 1,
    },
  ],
)
deft shadow
#

Sorry the Doc are 2 separated steps you need to combine. As my colleague mentioned you need to

  1. Create the subscription schedule from existing subscription: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
  2. Update subscription schedule to downgrade the plan at the end of the month with a new phase: https://stripe.com/docs/api/subscription_schedules/update

Learn how to use subscription schedules.

rough glacier
#

i have created schedule with existing subscition

#

now downgrade i need only add new phase right ? with new price id

deft shadow
#

You will also need to specify the current phase. (You will see if you try it)

#

Play with it in Test mode, try to pass parameters as you think and see how it ends up

rough glacier
#

okay

#

i have already this one phase {'items': [{'plan': 'price_1MxquQECJUF37lWXqBf9SptP', 'price': 'price_1MxquQECJUF37lWXqBf9SptP', 'metadata': {}, 'quantity': 1, 'tax_rates': [], 'billing_thresholds': None}], 'coupon': None, 'currency': 'usd', 'end_date': 1691819707, 'metadata': {}, 'trial_end': None, 'start_date': 1689141307, 'description': None, 'on_behalf_of': None, 'automatic_tax': {'enabled': False}, 'transfer_data': None, 'invoice_settings': None, 'add_invoice_items': [], 'collection_method': None, 'default_tax_rates': [], 'billing_thresholds': None, 'proration_behavior': 'create_prorations', 'billing_cycle_anchor': None, 'default_payment_method': None, 'application_fee_percent': None}

#

now i add second item and add new price id and start date and end date write

deft shadow
#

Yeah sound good

rough glacier
#

okay

#

wait 5 minutes

#

it look good or not and need any argument or not

                end_date = user.subscription.schedule.current_phase['end_date']
                start_date = user.subscription.schedule.current_phase['start_date']
                stripe.SubscriptionSchedule.modify(
                    user.subscription.schedule.id,
                    phases=[
                        {'items':
                            [
                                {
                                    'price': current_plan,
                                    'quantity': 1,
                                }
                            ],
                            'end_date': end_date,
                            'start_date': start_date,
                        },

                        {'items':
                            [
                                {
                                    'price': new_plan,
                                    'quantity': 1,
                                }
                            ],
                            'start_date': end_date,
                        },

                    ],
                )
deft shadow
#

Yeah looks good, but please test it out on Test mode

rough glacier
#

ok

#

it give me error
stripe.error.InvalidRequestError: Request req_6FwrWq3hVHfsjn: No such price: '$79.00 USD/month for Platinum'

deft shadow
#

current_plan you passed in is a String $79.00 USD/month for Platinum

#

You need a price id there instead

rough glacier
#

Request req_c1ioTXP4QmQhMN: No such price: '$79.00 USD/month for Platinum'

#

okay

#

it give me subscription schedule update and this response now i check to it work or not ?

deft shadow
#

You would want to examine the phases on the response, check its starting and ending date to see if it's correctly reflected your intention

#

Or use Test clock to advance the time, and verify it would work as expected

rough glacier
#

okay

#

i have one more question

#

this process work on monthy to monthy but what if monthy to yearly change

deft shadow
#

Same, Subscription Schedule can do that too