#max-subscriptionschedules-updates
1 messages ยท Page 1 of 1 (latest)
๐ happy to help
Thanks tarzan
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
when you create a schedule from a subscription the schedule now controls the original subscription and doesn't create a new one
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,
],
],
]);`
will it make the connection to the existing subscription?
no because you haven't used thefrom_subscriptionparameter I shared earlier
And yes, the schedule will only affect the subscription that it controls
I can't find how the code should look in the Stripe API documentation
Could you please share with me an example in PHP?
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"
I'm getting an error for creating phases. req_hKiKIkhqXO9MW0
invalid_request_error
You cannot set phases if from_subscription is set.
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
Okay, now it's working. Thanks for that
Is it normal to get a 500 response error, but a 200 status in the logs?
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
subscription schedule created: evt_1MYW23Cx0zdgDXMaChiS3ZIV
updated: evt_1MYW23Cx0zdgDXMaM37yfUCq
req_IbkZ1NZCzNNZp1
Thank you for the IDs. And which one did you get a 500 on?
I think that actually the subscription schedule hasn't been created
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?
The 500 error doesn't have a body
Was it for your subscription schedule creation call? Or are you seeing it somewhere in your logs for the events?
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?
You need to make an update call after that initial creation call, that is where you can set the phases and end behavior https://stripe.com/docs/api/subscription_schedules/update
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 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 ?
I think it should be $event->data->object->id
Hello ๐
Stepping in as Pompey needs to step away soon
Let me know if you have any follow ups
Hi Hanzo, how are you?
Doing well ๐ Thanks for asking
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, ], ], ] );
The subscription scheduled is not updating properly: req_kJJsNj5jGYzPK7
That's the same request that creates the schedule.
What error are you getting?
There're no errors. But the subscription is not updating with the end_behavior and phases
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?
You can also try running this script to see if your server is able to reach Stripe successfully or not
https://github.com/stripe/stripe-reachability
What do you mean with middleware?
I've webhooks connected to a php file I host in my domain.
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
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
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.
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, ], ]
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.
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?
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
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
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?
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
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, ], ]
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
How should I call the function in PHP/
- \Stripe\SubscriptionSchedule::update
- $stripe->subscriptionSchedules->update
Hi ๐
I'm stepping in as @sinful parrot needs to go. You can see an example of this syntax in PHP here: https://stripe.com/docs/api/subscriptions/update?lang=php
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?
Can you share the request ID for the most recent update request?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_l5obIzu745ZE5c
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?
It should be two iterations
I would like it to cancel after 2 iterations. But it shows that runs forever
Okay but that is not how the schedule was created. You will need to update the schedule in order to do that.
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' ]);
Okay do you have an API request ID for this request? The Update request?
req_gIpXxZ6CHIkP1y
That is still a SChedule creation request, not an update.
There are both in my PHP file
First happens $stripe->subscriptionSchedules->create
and then $stripe->subscriptionSchedules->update
Okay, I need to see the API ID for the second request. It will be a Subscription Schedule Update request
It does't appear
What is the error message that your code returns when you attempt the update?
req_Mh9Q2hyF7mBQ9x
I think that is this error that came later
Why am I not able to update the subscription?
That is still a creation request
So why is the request not reaching the server?
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.
How can I save the response and print it out?
$result = $stripe->subscriptionSchedule->update()
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"
Yup, and it was created just like the others.
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
Can you log this value in your PHP code? $event->data->object->schedule,. Are you sure this is an ID value? sub_sched_XXXXX
https://stripe.com/docs/api/subscription_schedules/update
Could the error be that I'm requesting to create the subscriptionSchedule, and immediately requesting the subscriptionSchedule ID to update the subscription?
No, those creation requests a synchronous so you should get the correct ID immediately
I've created the webhook to send the data directly to stripe. I don;t know where to log $event->data->object->schedule
I would start by testing this out in code you are running locally and not in a response to a webhook
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?
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