#inderjeet-downgrade

1 messages · Page 1 of 1 (latest)

rare solar
#

heya @empty stump, if i understood correctly, you want to downgrade the subscription plan at the end of the period, but the above code downgraded your plan immediately?

empty stump
#

Hi @rare solar , you are absolutely right.

rare solar
#

alrighty! cancel_at_period_end actually means quite literally to cancel the subscription at the end of the billing period. The upgrade/downgrade would happen instantly with your pasted code above.

If you want to upgrade/downgrade the subscription at a certain datetime, you would want to look into using Subscription Schedules instead : https://stripe.com/docs/billing/subscriptions/subscription-schedules

empty stump
#

Okay! Need some more brief about when I create subscription schedules with the help of subscripiton Id then next subscription id will be same or changed?

rare solar
#

the subscription id is the same

empty stump
#

@rare solar
With the help of the below code, i can cancel the subscription at the end of the period. not instantly right

\Stripe\Subscription::update(
'sub_49ty4767H20z6a',
[
'cancel_at_period_end' => true,
]
);

rare solar
#

yep, that's right! This code will cancel the subscription at the end of the period. It will not cancel it immediately

empty stump
#

Let me clear one thing below code is right for downgrade purpose.

\Stripe\SubscriptionSchedule::create([
'from_subscription' => 'sub_XXXXXXXXXXX',
]);

\Stripe\SubscriptionSchedule::update(
'sub_sched_XXXXXXXXXXXXXXXXXX',
[
'phases' => [
[
'items' => [
[
'price' => 'price_1GqNdGAJVYItwOKqEHb',//cureent plan
'quantity' => 1,
],
],
'start_date' => 1577865600,
'end_date' => 'now',// if it is today
],
[
'items' => [
[
'price' => 'price_1GqNdGAJVYItwOKqEHb', //downgrade plan
'quantity' => 2,
],
],
'start_date' => 'now',// if it is today
'end_date' => 1580544000,
],
]
);

rare solar
#

weeeell, honestly i would just test it. create a new subscription -> create a subscription schedule with it -> Set the downgrade to ~5 mins later and verify what happens

empty stump
#

Okay, Please help me !

rare solar
#

since you already have the code, can you try it on your own test account?

empty stump
#

Actually, I don't have a code I just copied from your given links. so is it possible for you to test it ?

rare solar
#

everyone's use case might be slightly different, which is why i suggested that you test it out. The code you pasted is just an example - it actually increased the quantity also. You would also need to define the variables to store the newly created subscription schedule, so that you can update the subscription schedule in the subscription call

empty stump
#

I have to do this code through webhook or on button click.

rare solar
#

Sorry, i don't quite understand. could you try rephrasing?

empty stump
#

Sure, I mean I want to do subscription schedule code on plan button click not on webhook . So is it possible when i click on the plan button on that time subscription schedule code run and downgrade the plan at the end of period, i hope you got it

rare solar
#

yep, that's possible

empty stump
#

Thank for your support i implement it if i face any challenge then i will contact you. Thanks @rare solar

rare solar
#

you're welcome!

empty stump
#

@rare solar I have one question for you. suppose I have a basic plan and that plan i have sub_xxxxxxx (subscription id) and sub_sched_xxxxx (sub schedule id).
When i next time upgrade/downgrade the plan then my subscription id is remain same but sub schedule id will also be same?