#haroonzuberi
1 messages ยท Page 1 of 1 (latest)
Hi there!
Pasting your other message here:
when I run the code, it also give me error that you cannot do it right away, you need to use the stripe schedule for this but when I use the stripe schedule then it wont put any impact on this.
when I run the code, it also give me error that you cannot do it right away, you need to use the stripe schedule for this but when I use the stripe schedule then it wont put any impact on this.
Can you share the request ID (req_xxx) where you see the error? You can find it here https://dashboard.stripe.com/test/logs
Thanks! Give me a few minutes to look into this.
This is a GET request with no errors.
Did you mean this request: https://dashboard.stripe.com/test/logs/req_DtGGAPudS1Tv46
If so, the error message is pretty clear:
The subscription is managed by the subscription schedule
sub_sched_xxx, and updating any cancelation behavior directly is not allowed. Please update the schedule instead.
You cannot directly update a Subscription created by a subscription schedule. You shoudl either:
- Update the subscription schedule directly
- Or remove the subscription from teh schedule, and then update the subscription
when I do that, how can I verify that the schedule is updated?
because when I update the schedule then it wont put any impact on the subscription
In general if the request suceeds then everything was updated properly. If you want to double check:
- The Stripe response will contain a subscription schedule object, that you can check to verify everything is as expacted
- You will also get a
subscription_schedule.updatedwebhook event.
thanks, let me check it and back to you, give me few minutes.
thanks
I used this code.
$schedule = SubscriptionSchedule::retrieve($scheduleId);
$schedule->phases[0]->items[0]->plan = $newPriceId;
$schedule->phases[0]->items[0]->price = $newPriceId;
$schedule->save();
But after that when I dump the schedule then it did not changed the plan in the schedule.
I have checked the logs of the requests, I sent the new plan Id price_1NSknJKxrzXzvH7EG5biXxAF
but in the schedule body, I checked that the price id is still price_1NSkqWKxrzXzvH7EanAttuAa
Maybe when using save() you need to make an extra API call to retrieve the object and see its new values, I'm not sure.
let me try to do that.
๐ stepping in
Let me know what you see
I'd also recommend using Test Clocks to test out schedules: https://stripe.com/docs/billing/testing/test-clocks
I tried to retrieve it as well but still I did not get any luck.
can you tell me one thing that my code is correct here?
Thanks let me take a look
Okay so doesn't look like that Subscription Schedule update request passed anything -- it is just an empty request POST body: https://dashboard.stripe.com/test/logs/req_pBr274zdCsnQo9
So you need to check your code for how you are actually updating the Subscription Schedule here
Yes, I already checked it.
but I am using the code that is recommended
here is the code
$schedule->phases[0]->items[0]->plan = $newPriceId;
$schedule->phases[0]->items[0]->price = $newPriceId;
$schedule->save();
Yeah but that code is not doing anything right now
Are you using a third party currently?
Because that does not look like a proper Update request using our SDK
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I tried this code and it return this
SubscriptionSchedule::update($scheduleId, [
'phases[0][items][0][plan]' => $newPriceId,
'phases[0][items][0][price]' => $newPriceId,
]);
The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.
Okay so then yeah you don't have all the necessary parameters
when I added the start_date and end_date, then it gave me error
you cannot change the start date of current phase
You need to basically pass the current phase as phase 0 when you update a Sub Schedule
SubscriptionSchedule::update($scheduleId, [
'phases' => [
[
'items' => [
[
'price' => $newPriceId,
'quantity' => 1,
],
],
'start_date' => time(),
'end_date' => strtotime("+1 month", time()),
],
],
]);
I use this code, and then I get this error
You can not modify the start date of the current phase.
Right so you need to put in the start_date as the start_date of the current phase of the Subscription Schedule that you are modifying
I removed the end date here, and still get the same error
Then you still have an issue with your start_date
it is quite strange here
Sub Schedules are a bit advanced and take some tinkering to get the API request right
You mostly want to retrieve the Subscription or Subscription Schedule prior to the update and make sure your phase 0 mirrors exactly what is going on currently
Then make your updates
should I tell you what I am trying to achieve?
Sure if that would help you.
But it sounds to me like you just need to figure out the proper data to use to perform a Sub Schedule update right now.
But happy to confirm that is the right path forward
We have 3 subscriptions
sub 1- $10
sub 2- $20
sub 3- $30
My agenda is that, right now the user have sub 1, when the user want to upgrade its subscription to sub 2, then it must upgrade immediately to the sub 2.
On the other hand, if the user want to downgrade the subscription from sub 2 to sub 1 again, then the subscription completes its time period and then downgrade to the sub 1.
yes, right now they are all of same interval which is monthly
Okay so in that case you don't need a Subscription Schedule at all.
You just use proration_behavior
If you set proration_behavior: always_invoice (https://stripe.com/docs/api/subscriptions/update#update_subscription-proration_behavior) then a new Invoice is created immediately.
I tried that before as well.
What's the issue?
in the start I followed this blog
https://stripe.com/docs/billing/subscriptions/upgrade-downgrade
Sure
$subscription = Subscription::update(
$subscription->id,
[
'cancel_at_period_end' => false,
'proration_behavior' => 'always_invoice',
'items' => [
[
'id' => $subscription->items->data[0]->id,
'price' => $newPriceId,
],
],
]
);
this is the code I tried in the start
By why does proration_behavior not satisfy what you want to do?
when I tried this it simply return me this error, from which this conversation start on top ๐
The subscription is managed by the subscription schedule sub_sched_1NSku5KxrzXzvH7EWgn7eZ39, and updating any cancelation behavior directly is not allowed. Please update the schedule instead.
Okay so you didn't try just updating the Subscription then.
You would do this without a Schedule involved at all.
To test this you should either create a fresh Subscription in test mode
Or you can release the subscription schedule via https://stripe.com/docs/api/subscription_schedules/release
But based on the behavior you described above you don't need a Sub Schedule at all.
the subscription is not updating using the method they provided in the documentation.
I have been trying it from around 4 days.
If you have a request ID for a successful Subscription update where you passed proration_behavior: always_invoice then I'd be happy to check it
let me share the request ID
can you verify me that the code is right?
$subscription = Subscription::update(
$subscription->id,
[
'cancel_at_period_end' => false,
'proration_behavior' => 'always_invoice',
'items' => [
[
'id' => $subscription->items->data[0]->id,
'price' => $newPriceId,
],
],
]
);
Yeah that looks fine to me
here is the request ID
req_iSyOFJL01ZBjjH
Yeah so it doesn't seem like you read what I said above
You can't do this with a Sub Schedule attached
You need to release the schedule or start a new Sub
oh you means that I need to first release the subscription, give me a minute to do it
Sure
I think after releasing the schedule, it allowed me to update it
can you confirm me one thing, will the monthly billing work after updating the subscription?
because I have released the schedule here
Hi what do you mean by that?
I had a talk with @flint igloo
I was having issue in upgrading the subscription
so for that purpose I have to release the subscription schedule from the subscription
so my question here is that, after releasing the subscription, after upgrade, will the billing work as usual or not?
Yeah it will work as usual if you just release it
What specifically do you need help with? We have a guide here: https://stripe.com/docs/billing/subscriptions/upgrade-downgrade. If you have specific questions after reading that, I can address them
Yes, I am following the same blog
Here is what I am trying to achieve
We have 3 subscriptions
sub 1- $10
sub 2- $20
sub 3- $30
My agenda is that, right now the user have sub 1, when the user want to upgrade its subscription to sub 2, then it must upgrade immediately to the sub 2.
On the other hand, if the user want to downgrade the subscription from sub 2 to sub 1 again, then the subscription completes its time period and then downgrade to the sub 1.
The upgrade part is now done, can you please tell me how can I achieve the downgrade part?
You could use a sub schedule for that as well: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#downgrading-subscriptions
You could set the time at which you want the downgrade to occur
can you tell me about the parameter that I need to set for this?