#haroonzuberi

1 messages ยท Page 1 of 1 (latest)

river harnessBOT
lilac spire
#

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.

simple thicket
#

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.

lilac spire
simple thicket
#

sure, give me a minute

#

here is the request id req_eakSPuL7ZhsvqJ

lilac spire
#

Thanks! Give me a few minutes to look into this.

#

This is a GET request with no errors.

#

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
simple thicket
#

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

lilac spire
#

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.updated webhook event.
simple thicket
#

thanks, let me check it and back to you, give me few minutes.

river harnessBOT
simple thicket
#

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

lilac spire
#

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.

simple thicket
#

let me try to do that.

flint igloo
#

๐Ÿ‘‹ stepping in

#

Let me know what you see

simple thicket
#

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?

flint igloo
#

Can you give me the request ID for your Subscription Schedule update?

simple thicket
#

sure

#

here is the request ID req_pBr274zdCsnQo9

flint igloo
#

Thanks let me take a look

#

So you need to check your code for how you are actually updating the Subscription Schedule here

simple thicket
#

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();

flint igloo
#

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

simple thicket
#

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.

flint igloo
#

Okay so then yeah you don't have all the necessary parameters

simple thicket
#

when I added the start_date and end_date, then it gave me error
you cannot change the start date of current phase

flint igloo
#

You need to basically pass the current phase as phase 0 when you update a Sub Schedule

simple thicket
#

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.

flint igloo
#

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

simple thicket
#

I removed the end date here, and still get the same error

flint igloo
#

Then you still have an issue with your start_date

simple thicket
#

it is quite strange here

flint igloo
#

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

simple thicket
#

should I tell you what I am trying to achieve?

flint igloo
#

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

simple thicket
#

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.

flint igloo
#

Are these 3 Prices the same interval?

#

Like all monthly?

simple thicket
#

yes, right now they are all of same interval which is monthly

flint igloo
#

Okay so in that case you don't need a Subscription Schedule at all.

#

You just use proration_behavior

simple thicket
#

I tried that before as well.

flint igloo
#

What's the issue?

simple thicket
flint igloo
#

Sure

simple thicket
#

$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

flint igloo
#

By why does proration_behavior not satisfy what you want to do?

simple thicket
#

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.

flint igloo
#

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

#

But based on the behavior you described above you don't need a Sub Schedule at all.

simple thicket
#

the subscription is not updating using the method they provided in the documentation.
I have been trying it from around 4 days.

flint igloo
#

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

simple thicket
#

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

flint igloo
#

Yeah that looks fine to me

simple thicket
#

here is the request ID
req_iSyOFJL01ZBjjH

flint igloo
#

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

simple thicket
#

oh you means that I need to first release the subscription, give me a minute to do it

flint igloo
#

Sure

river harnessBOT
simple thicket
#

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

viral mason
#

Hi what do you mean by that?

simple thicket
#

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?

viral mason
#

Yeah it will work as usual if you just release it

simple thicket
#

Great

#

Now can you help me downgrade the subscription as well?

viral mason
simple thicket
#

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?

viral mason
#

You could set the time at which you want the downgrade to occur

simple thicket
#

can you tell me about the parameter that I need to set for this?

viral mason
#

What do you mean?

#

Did you see the link above?

#

Another option if you don't want to use subscription schedules is to just update the sub with the new price and pass proration_behavior=none