#Max1414

1 messages · Page 1 of 1 (latest)

sharp crestBOT
pseudo mulch
#

Hi there

#

Yep you can update a schedule after it is associated with a Subscription

grizzled atlas
#

It's not working. I talked with a developer I hired to look into this, and told me that it doesn't work. Stripe doesn't receive the request. Could this be a bug from Stripe?

#

`$stripe->subscriptionSchedules->create([
'from_subscription' => $sub_id,
]);

                        $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'
                            ]);`
pseudo mulch
#

That is just code with variables. Do you have a request ID? Did you see an error message?

#

I promise you this is possible and it is almost certainly just an issue with your code but I can't tell that from the above.

grizzled atlas
#

req_JcJebffqQoBmNq this is the request ID from the first line of code

#

But I don't get a request ID from the second line of code to update the subscriptionSchedule

#

There's no error/ Stripe for some reason seems to not be working to update the subscriptionSchedule

pseudo mulch
#

I see a bunch of errors occurring on your initial Sub Schedule request which is likely the issue

#

You really want to set a variable here to be used

grizzled atlas
#
  1. Am I able to create a subscription schedule from a subscription?

$stripe->subscriptionSchedules->create([ 'from_subscription' => $sub_id, ]);

pseudo mulch
#

Yes.

#

So do $subSchedule = $stripe->subscriptionSchedules->create([ 'from_subscription' => $sub_id, ]);

grizzled atlas
#

So the problem is updating the created SubscriptionSchedule

pseudo mulch
#

Then try:

                            $subSchedule->id
                            [
                                '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'
                                ]);```
#

Then log out $updateSub

#

Also going to need to change your $$event->data->object->current_period_start

#

$event->data->object->schedule, is likely the issue though overall

#

Like schedule isn't something you get from a Stripe webhook

#

Which I assume is what you are trying to rely on there?

#

Not sure why tbh

grizzled atlas
#

To update a subscriptionSchedule is necessary to pass the subscriptionSchedule ID

pseudo mulch
#

Yes

grizzled atlas
#

Yes, I already read and tested what's on the Stripe API

#

Is $event->data->object->schedule the subscriptionSchedule ID?

pseudo mulch
#

No

#

First off, it depends on what event that is to begin with

#

Are you listening for subscription_schedule.created?

#

If so, then it would be $event->data->object->id

#

Since that event returns you a Subscription Schedule object

grizzled atlas
#
  1. I create a normal monthly subscription.
  2. This triggers a webhook:
    2.1) Create a subscription schedule
    2.2) Update the subscription schedule
pseudo mulch
#

Yep

#

So see what I did above

#

When you create your Sub Schedule

#

Set a variable

#

Don't use the Webhook

#

Then pass that variable for updating the Schedule

#

(I actually have it wrong above and you need $subSchedule->id)

grizzled atlas
#

In the webhook I'm listening for customer.subscription.created

#

So, do I need to create a separate webhook for this?

pseudo mulch
#

Nope.

#

The issue is that you are currently passing the Subscription ID to the SubscriptionSchedule update API

grizzled atlas
#

So, what should I use intead of $event->data->object->schedule?

pseudo mulch
#

You need the SubscriptionSchedule ID

#

No, please read what I wrote above.

#

When you create your Subscription Schedule

#

You want to set a variable

#

For that Schedule

#

So like this: ```$subSchedule = $stripe->subscriptionSchedules->create([
'from_subscription' => $sub_id,
]);

#

No the Subscription Schedule object is initialized within $subSchedule

#

Next step is to update the Subscription Schedule. You can access the ID of that Schedule now via $subSchedule -> id

#

So your update request should look like:

                            $subSchedule->id
                            [
                                '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'
                                ]);```
grizzled atlas
#

So basically, I should use the latest two code blocks you shared intead of mine and it should work?

#

When I store the subscriptionSchedule in a variable, does this create the subscriptionSchedule in the subscription?

#

Or do I need to call the function again?

pseudo mulch
#

Yes the code I shared should work (depending on your parameters that you use for your phrases)

#

No you don't need to call the function again

#

It both creates the Subscription Schedule and stores an instance of it in that variable

grizzled atlas
#

Thanks a lot bismark, I'll soon test this.

#

You've made my day @pseudo mulch . Really. I've been trying to figure this out for 8 hours and even paid a "Stripe dev" that wasn't helpful