#mathan

1 messages ยท Page 1 of 1 (latest)

azure heartBOT
clever lance
#

Can you share what is your use case? If you're going to update subscription in the current billing cycle, why do you need subscription schedule?

cunning axle
#

I need to add another plan or price in the next billing cycle!

clever lance
#

I see! After subscription schedule is created from the from_subscription, you should get the first phase (current billing cycle) as the first phase.

When updating the subscription schedule, you will set the first phase as the one you get from create subscription instead of empty one, then add a new phase of price changes as the second phase.

cunning axle
#

okay, so what are the changes in this API?

#

` $subscriptionSchedule = \Stripe\SubscriptionSchedule::create([
'from_subscription' => $this->model->stripe_subscription_id,
]);

        \Stripe\SubscriptionSchedule::update(
            $subscriptionSchedule->id,
            [
                'phases' => [
                    [
                       
                    ],
                    [
                        'items' => [
                            [
                                'price' => $plan->stripe_id,
                            ],
                        ],
                        'start_date' => $subscription->current_period_end,
                    ],
                ],
            ]
        );`
clever lance
#

In your first phase (that has empty body), you should change to the first phase returning from the subscription schedule object during subscription creation

cunning axle
#

for example, how can I fill the first phase?

granite rose
#

๐Ÿ‘‹ taking over

granite rose
#

Hi, gimme a few mins to catch up

#
'start_date' => $subscription->current_period_end,

This part, I suspect it doesn't reflect the correct phase start

#

Generally you want to specify the exact current start_date and end_date, then chance the price

cunning axle
granite rose
#

It's hard to tell. Let's try retrieving the Subscription Schedule to see in detail

cunning axle
#

I faced this error ||Missing required param: phases[0][items]. ||

#

for this code

#

` $subscriptionSchedule = \Stripe\SubscriptionSchedule::create([
'from_subscription' => $this->model->stripe_subscription_id,
]);

        \Stripe\SubscriptionSchedule::update(
            $subscriptionSchedule->id,
            [
                'phases' => [
                    [
                        'start_date' => $startDate,
                        'end_date' => $endDate,
                    ],
                    [
                        'items' => [
                            [
                                'price' => $plan->stripe_id,
                            ],
                        ],
                        'start_date' => $subscription->current_period_end,
                    ],
                ],
            ]
        );`
granite rose
#

You should have items inside the phases

#

Look at this Doc code

\Stripe\SubscriptionSchedule::update(
  'sub_sched_1FSRtAILNmKrzH4z9scwDpeL', [
  'phases' => [
    [
      'items' => [
        [
          'price' => 'price_1GqNdGAJVYItwOKqEHb',
          'quantity' => 1,
        ],
      ],
      'start_date' => 1577865600,
      'end_date' => 'now',
    ],
    [
      'items' => [
        [
          'price' => 'price_1GqNdGAJVYItwOKqEHb',
          'quantity' => 2,
        ],
      ],
      'start_date' => 'now',
      'end_date' => 1580544000,
    ],
  ],
]);
cunning axle
#

how can I set the end date like one billing cycle dynamically?

granite rose
#

Yes you should be able to use iterations from 2nd phase. It's more convenience and accurate

cunning axle
#

if I add iterations, do I need start_date and end_date?

granite rose
cunning axle
granite rose
#

I think you don't. Let's just try it

cunning axle
#

` $subscriptionSchedule = \Stripe\SubscriptionSchedule::create([
'from_subscription' => $this->model->stripe_subscription_id,
]);

        \Stripe\SubscriptionSchedule::update(
            $subscriptionSchedule->id,
            [
                'phases' => [
                    [
                        'items' => [
                            [
                            'price' => $this->model->subscriptionPlan->stripe_id,
                            ],
                        ],
                        'start_date' => strtotime($subscriptionPLanLogs->start_date),
                        'end_date' => strtotime($subscriptionPLanLogs->end_date),
                    ],
                    [
                        'items' => [
                            [
                                'price' => $plan->stripe_id,
                            ],
                        ],
                        'iterations' => 1,

                    ],
                ],
            ]
        );`
#

error for this code Invalid integer: false in file

granite rose
#

That looks unrelated. Have you looked at your requests log in Dashboard?

#

Let's see what exactly the error returned from Stripe

cunning axle
#

okay

#

where I can see the subscription schedule details in stripe?

granite rose
#

Better to just use Retrieve Subscription Schedule API

cunning axle
#

Okay nice, but if the customer changes his plan in the customer portal how can I schedule? anyways?

granite rose
#

You can still retrieve the latest Subscription Schedule from that Subscription, no?

cunning axle
#

No, how can schedule the subscription, if the customer changes his plan in the customer portal?

granite rose
#

You mean after you make the schedule, the customer changes his plan on customer portal?

cunning axle
#

No

#

API subscription schedule is one method, I speak about, how can schedule the subscription, if the customer changes his plan in the customer portal?

granite rose
#

Hmm not really follow. Do you mean after the customer changes his plan on Customer Portal, you don't want to change immediately but somehow "schedule" for later time?