#inderjeet-downgrade
1 messages · Page 1 of 1 (latest)
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?
Hi @rare solar , you are absolutely right.
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
you can convert an existing Subscription into a Subscription Schedule : https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription. Then upgrade/downgrade it in the next phase
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?
the subscription id is the same
@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,
]
);
yep, that's right! This code will cancel the subscription at the end of the period. It will not cancel it immediately
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,
],
]
);
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
Okay, Please help me !
since you already have the code, can you try it on your own test account?
Actually, I don't have a code I just copied from your given links. so is it possible for you to test it ?
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
I have to do this code through webhook or on button click.
Sorry, i don't quite understand. could you try rephrasing?
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
yep, that's possible
Thank for your support i implement it if i face any challenge then i will contact you. Thanks @rare solar
you're welcome!
@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?