#max-subscriptionschedules-updates

1 messages ยท Page 1 of 1 (latest)

ember stoneBOT
dusty lava
#

๐Ÿ‘‹ happy to help

sleek crystal
#

Thanks tarzan

sleek crystal
#

Would that create a new schedule instead of changing the current subscription?

#

For what I can see in the Stripe API reference, it will create a new schedule in the customer, instead of changing the created subscription

dusty lava
sleek crystal
#

and will the schedule only affect that subscription?

I created this code. By lining the item, will it make the connection to the existing subscription?

              `  $stripe->subscriptionSchedules->create([
                            'customer' => $cus,
                            'start_date' => $event->data->object->created,
                            'end_behavior' => 'cancel',
                            'phases' => [
                              [
                                'items' => [
                                  [
                                    'price' => 'price_1MYHJeCx0zdgDXMabDIM4Wae',
                                    'quantity' => 1,
                                  ],
                                ],
                                'iterations' => 3,
                              ],
                            ],
                          ]);`
dusty lava
#

will it make the connection to the existing subscription?
no because you haven't used the from_subscription parameter I shared earlier

zinc arrow
#

And yes, the schedule will only affect the subscription that it controls

sleek crystal
#

I can't find how the code should look in the Stripe API documentation

#

Could you please share with me an example in PHP?

zinc arrow
#

It looks like tarzan already sent that link. If it isn't linking you to the right part of the page you can look for the section titled "Adding a schedule to an existing subscription"

sleek crystal
#

I'm getting an error for creating phases. req_hKiKIkhqXO9MW0

#

invalid_request_error
You cannot set phases if from_subscription is set.

zinc arrow
#

Gotcha, yes the intended flow is to make the first call to create the schedule with from_subscription then you update the schedule that was created in another call

#

Max1414 - Subscription Schedules

sleek crystal
#

Okay, now it's working. Thanks for that

#

Is it normal to get a 500 response error, but a 200 status in the logs?

zinc arrow
#

Can you send me the request ID? (req_123)

#

500 errors usually are transient issues on the Stripe side so they can have unpredictable behavior as to whether, say, a certain object is created or not

#

Though we should log the same status that you see when you make the call

sleek crystal
#

subscription schedule created: evt_1MYW23Cx0zdgDXMaChiS3ZIV

#

updated: evt_1MYW23Cx0zdgDXMaM37yfUCq

#

req_IbkZ1NZCzNNZp1

zinc arrow
#

Thank you for the IDs. And which one did you get a 500 on?

sleek crystal
#

I think that actually the subscription schedule hasn't been created

zinc arrow
#

I see the ID sub_sched_1MYW23Cx0zdgDXMaCo70ZYOJ, you should see it on sub_1MYVc4Cx0zdgDXMaKyHhBYvZ in its schedule property if you retrieve it now

#

Why does it seem that it hasn't been created?

sleek crystal
#

The 500 error doesn't have a body

zinc arrow
#

Was it for your subscription schedule creation call? Or are you seeing it somewhere in your logs for the events?

sleek crystal
#

It has been created. This is the log:
{ "id": "sub_sched_1MYW23Cx0zdgDXMaCo70ZYOJ", "object": "subscription_schedule", "application": null, "canceled_at": null, "completed_at": null, "created": 1675695059, "current_phase": { "end_date": 1678112648, "start_date": 1675693448 }, "customer": "cus_NJ7r5jbWxbO3hj", "default_settings": { "application_fee_percent": null, "automatic_tax": { "enabled": true }, "billing_cycle_anchor": "automatic", "billing_thresholds": null, "collection_method": "charge_automatically", "default_payment_method": "pm_1MYVc3Cx0zdgDXMaeY3zsG5I", "default_source": null, "description": null, "invoice_settings": { "days_until_due": null }, "on_behalf_of": null, "transfer_data": null }, "end_behavior": "release", "livemode": false, "metadata": {}, "phases": [ { "add_invoice_items": [], "application_fee_percent": null, "automatic_tax": { "enabled": true }, "billing_cycle_anchor": null, "billing_thresholds": null, "collection_method": null, "coupon": null, "currency": "usd", "default_payment_method": null, "default_tax_rates": [], "description": null, "end_date": 1678112648, "invoice_settings": null, "items": [ { "billing_thresholds": null, "metadata": {}, "plan": "price_1MYHJeCx0zdgDXMabDIM4Wae", "price": "price_1MYHJeCx0zdgDXMabDIM4Wae", "quantity": 1, "tax_rates": [] } ], "metadata": {}, "on_behalf_of": null, "proration_behavior": "create_prorations", "start_date": 1675693448, "transfer_data": null, "trial_end": null } ], "released_at": null, "released_subscription": null, "renewal_interval": null, "status": "active", "subscription": "sub_1MYVc4Cx0zdgDXMaKyHhBYvZ", "test_clock": null }

#

But it doesn't have proper end behavior or phases

#

After I create the schedule. Is it located $event->data->object->subscriptionSchedules?

zinc arrow
sleek crystal
#

I made this call:
$stripe->subscriptionSchedules->update( $event->data->object->subscriptionSchedules, ['end_behavior' => 'cancel', 'phases' => [ [ 'items' => [ ['price' => 'price_1MYHJeCx0zdgDXMabDIM4Wae', 'quantity' => 1,] ], 'iterations' => 3, ], ], ] );

#

Is the subscription scheduled id: $event->data->object->subscriptionSchedules ?

zinc arrow
#

I think it should be $event->data->object->id

sinful parrot
#

Hello ๐Ÿ‘‹
Stepping in as Pompey needs to step away soon

#

Let me know if you have any follow ups

sleek crystal
#

Hi Hanzo, how are you?

sinful parrot
#

Doing well ๐Ÿ™‚ Thanks for asking

sleek crystal
#

The subscription scheduled is not updating properly: req_kJJsNj5jGYzPK7

#

This is the code after the subscriptionschedule is created:
$stripe->subscriptionSchedules->update( $event->data->object->schedule, ['end_behavior' => 'cancel', 'phases' => [ [ 'items' => [ ['price' => 'price_1MYHJeCx0zdgDXMabDIM4Wae', 'quantity' => 1,] ], 'iterations' => 3, ], ], ] );

sinful parrot
#

The subscription scheduled is not updating properly: req_kJJsNj5jGYzPK7
That's the same request that creates the schedule.

What error are you getting?

sleek crystal
#

There're no errors. But the subscription is not updating with the end_behavior and phases

sinful parrot
#

The SDK wouldn't just fail to update the sub without any errors
do you see any relevant errors in Stripe request logs on the dashboard?

#

The only other thing that would make sense here is that your requests are not making it to Stripe

#

Yeah I don't see any incoming requests to update the subscription on your account.
So I strongly feel that some of your requests aren't reaching Stripe successfully. It might also explain 500s with no response body.
If the 500 comes from Stripe then it would definitely have some response body.

Do you have a middleware of some sort?

sleek crystal
#

What do you mean with middleware?

#

I've webhooks connected to a php file I host in my domain.

sinful parrot
#

It is possible that your host (where your domain is hosted) has some proxy/firewall servers and are blocking certain requests

#

Would recommend running the script from above URL as well as talking to your hosting provider to check if they can share any logs on these outgoing requests

sleek crystal
#

There are no errors from the host. Everything is happening in the same request

#

Is it common to not see the schedule subscription in the dashboard?

#

When I go to the link I can't find the subscription schedule ID in the subscription

sinful parrot
#

I don't think SubscriptionSchedules are visible on the dashboard

#

and like I mentioned before, I don't see a request to update the schedule on your account, So the request hasn't reached to Stripe servers at all which is why you are not seeing the schedule update OR even an error.
It must be failing somewhere in between.

sleek crystal
#

How can I check that the subscription schedule object has been created properly?

#

Is there anything wrong with this code to update the subscription schedule?

$stripe->subscriptionSchedules->update( $event->data->object->schedule, [ 'phases' => [ 'items' => [ [ 'price' => 'price_1MXS0jH5SaHbz40ciRUSR9jN', 'quantity' => 1, ], ], 'start_date' => $event->data->object->current_period_start, 'end_date' => $event->data->object->current_period_end, ], [ 'items' => [ [ 'price' => 'price_1MXS0jH5SaHbz40ciRUSR9jN', 'quantity' => 1, ], ], 'iterations' => 2, ], ]

sinful parrot
#

How can I check that the subscription schedule object has been created properly?
as long as the API doesn't return any errors and you see a successful response, you can assume it has been created properly. You can also check the response to be sure.

The code looks fine. It can't fail silently. There must be an error. If there's no error and no response, then that means that the request isn't reaching Stripe servers.

sleek crystal
#

The event shows as succeded: evt_1MYWsiCx0zdgDXMadw9E1LJY

#

When I retrieve the object in the stripe CLI, it doesn't show the quantity of iterations

#

I just charged a subscription (first month) and I want to charge another 2 more months. When I update the subscription scheduled, should I set 2 or 3 iterations?

sinful parrot
#

That event is for a subscription update, NOT a subscription schedule update. You are looking at the wrong event.

If you look at the request log here
https://dashboard.stripe.com/test/logs?method[0]=post&method[1]=delete&direction[0]=connect_in&direction[1]=self&starting_after=1675699759-req_AA6mUt2g6AiXMo

You would see the errors from the API

sleek crystal
#

It shows:
parameter_invalid_empty - phases
You passed an empty string for 'phases'. We assume empty values are an attempt to unset a parameter; however 'phases' cannot be unset. You should remove 'phases' from your request or supply a non-empty value.

{
"phases": ""
}

#

Also, If I just charged a subscription (first month) and I want to charge another 2 more months. When I update the subscription scheduled, should I set 2 or 3 iterations?

sinful parrot
#

Also, If I just charged a subscription (first month) and I want to charge another 2 more months. When I update the subscription scheduled, should I set 2 or 3 iterations?
If you want the phase to run twice then you'd set iterations to 2

sleek crystal
#

Could you tell me if the following code will update an existing subscriptionSchedule to charge 2 more iteration when the current phase finishes?

$stripe->subscriptionSchedules->update( $event->data->object->schedule, [ 'phases' => [ 'items' => [ [ 'price' => 'price_1MXS0jH5SaHbz40ciRUSR9jN', 'quantity' => 1, ], ], 'start_date' => $event->data->object->current_period_start, 'end_date' => $event->data->object->current_period_end, ], [ 'items' => [ [ 'price' => 'price_1MXS0jH5SaHbz40ciRUSR9jN', 'quantity' => 1, ], ], 'iterations' => 2, ], ]

sinful parrot
#

I can't tell you it will 100% work just by looking at it since it uses a ton of variables ๐Ÿ™‚
You need to run and test your code

sleek crystal
#

How should I call the function in PHP/

  1. \Stripe\SubscriptionSchedule::update
  2. $stripe->subscriptionSchedules->update
tribal depot
sleek crystal
#

Hi Snufkin, how are you?

#

I located the subscription schedule in the dashboard and it hasn't changed to only be two itirations

#

I really don't know why the subscription schedule is not updating

#

Could you help me with this?

tribal depot
sleek crystal
#

req_l5obIzu745ZE5c

tribal depot
#

Okay that request created the Schedule from the Subscription sub_1MYY15Cx0zdgDXMaYBnQo6AU

#

And it has the single phase for the Price associated with that subscription.

#

What about this is not what you expect?

sleek crystal
#

It should be two iterations

#

I would like it to cancel after 2 iterations. But it shows that runs forever

tribal depot
#

Okay but that is not how the schedule was created. You will need to update the schedule in order to do that.

sleek crystal
#

How do I do that?

#

I've set up the end_behavior to cancel

#

$stripe->subscriptionSchedules->update( $event->data->object->schedule, [ 'phases' => [ [ 'items' => [ [ 'price' => 'price_1MYJnhCx0zdgDXMaoqEwUg2A', 'quantity' => 1, ], ], 'start_date' => $event->data->object->current_period_start, 'end_date' => $event->data->object->current_period_end, ], [ 'items' => [ [ 'price' => 'price_1MYJnhCx0zdgDXMaoqEwUg2A', 'quantity' => 1, ], ], 'iterations' => 2, ], ], 'end_behavior' => 'cancel' ]);

tribal depot
#

Okay do you have an API request ID for this request? The Update request?

sleek crystal
#

req_gIpXxZ6CHIkP1y

tribal depot
#

That is still a SChedule creation request, not an update.

sleek crystal
#

There are both in my PHP file

#

First happens $stripe->subscriptionSchedules->create

#

and then $stripe->subscriptionSchedules->update

tribal depot
#

Okay, I need to see the API ID for the second request. It will be a Subscription Schedule Update request

sleek crystal
#

It does't appear

tribal depot
#

What is the error message that your code returns when you attempt the update?

sleek crystal
#

req_Mh9Q2hyF7mBQ9x

#

I think that is this error that came later

#

Why am I not able to update the subscription?

tribal depot
#

That is still a creation request

sleek crystal
#

So why is the request not reaching the server?

tribal depot
#

You need to log the response you get when you attempt to update the subscription. Save the response to a variable and print it out.

sleek crystal
#

How can I save the response and print it out?

tribal depot
#

$result = $stripe->subscriptionSchedule->update()

sleek crystal
#

I added that to the code but I don't know how to find it

#

this is the latest subscription scheduled created

#

"sub_sched_1MYYnGCx0zdgDXMaZJ60fyCI"

tribal depot
#

Yup, and it was created just like the others.

sleek crystal
#

But not updated

#

I don't know why the subscription is not getting updated.

#

I checked the code multiple times with Stripe API dev and there's no errors

tribal depot
sleek crystal
#

Could the error be that I'm requesting to create the subscriptionSchedule, and immediately requesting the subscriptionSchedule ID to update the subscription?

tribal depot
#

No, those creation requests a synchronous so you should get the correct ID immediately

sleek crystal
#

I've created the webhook to send the data directly to stripe. I don;t know where to log $event->data->object->schedule

tribal depot
#

I would start by testing this out in code you are running locally and not in a response to a webhook

sleek crystal
#

This is the event: evt_1MYZFqCx0zdgDXMadrDdHqeu

#

to update the subscriptionscheduled

#

If the event exist why does it not show the log

#

and why is not updating the subscriptionscheduled event?

tribal depot
#

That isn't an event for updating the schedule. It is an event for updating the Subscription itself which is triggered when you create the schedule