#Whip-subscriptions

1 messages · Page 1 of 1 (latest)

undone pine
#

you'd use schedules for this yes

#

if the phase with new plan starts at period end, when will it end?
it doesn't. You just create the phase with start_date as subscription->current_period and and with no end_date

#

And with the end_behavior => 'release', will it revert the subs to old plan?
no. the subscription just stays as is and keeps cycling

elder spruce
#

Does the schedule actually change the subscription or is it a modifier on top of it? I mean if the user was to change plan in the future - which will be executed with stripe->subscriptions->update - will that work as normal with a schedule active?

undone pine
#

the former, the schedule is on top of the schedule and manages it by triggering updates at specified times

#

most updates work fine, I think there are a couple of exceptions like you can't call the cancel API on a subscription being managed by a schedule

elder spruce
#

I would need that. The customer can opt to cancel the subscription in which case our system calls stripe->subscriptions->cancel

#

Is there another alternative?

undone pine
#

I just tried it(cancelling a subscription with a schedule) and it works

elder spruce
#

Also, the schedules api asks for customer, id not subscription id. That's a bit weird, in rare cases there maybe 2 subscriptions on an account, 1 in incomplete state and other in Active. Ofcourse there can be multiple subs in cancelled state

undone pine
#

I know/think there are some limitations but it's been a long time since I looked and we don't document them unfortunately

undone pine
#

in your use case you'd be using from_subscription to create the schedule on top of an existing sub

elder spruce
#

Will I need to create 2 api calls as the docs say "When using this parameter, other parameters (such as phase values) cannot be set. To create a subscription schedule with other modifications, we recommend making two separate API calls."

undone pine
#

yep as the error says you have to first create the schedule using from_subscription in one call, and then update the schedule's phases in another(the docs I linked implicitly use that flow)

#

the dirty PHP script I use for testing this is

$subscription = \Stripe\Subscription::create([
  'customer' => $customer->id,
  'items' => [
    [
      'plan' => $silver->id,
    ],
  ]
]);

// schedule a change from silver to gold at the end of the period
$sched = \Stripe\SubscriptionSchedule::create([
  'from_subscription' => $subscription->id,
]);

\Stripe\SubscriptionSchedule::update($sched->id, [
  'phases' => [
    [
      "start_date" => $subscription->current_period_start,
      "end_date" => $subscription->current_period_end,
      'plans' => [
        [
          'plan' => $silver->id,
          'quantity' => 1,
        ],
      ],
      "prorate" => "true"
    ],
    [
      "start_date" => $subscription->current_period_end,
      'plans' => [
        [
          'plan' => $gold->id,
          'quantity' => 1,
        ],
      ],
    ],
  ],
  "end_behavior" => "release"
]);

if that shows the concept

elder spruce
#

In the 1st phase, are you specifying the current plan? Is that necessary?

undone pine
#

yes it is

#

schedules are declarative meaning you must pass all phases again on every call. For example if you had 4 phase (a month on Gold, 2 months on Silver, a year on Platinum, a month on silver then cancel the subscription, for a complicated example) and you want to change the year to use "Super-Platinum" instead, you have to call the update API and pass all 4 phases again(re-declaring them), changing the one you want. It makes sense but can be hard to work with in advanced use cases

#

so in my case I want to declare two phases : first phase, use the current plan from the start of the period to the end; second phase, start at the end of the current period and use the new plan

elder spruce
#

It is complex. An easier alternative would've been to specify the subscription, date of change and attributes to change and that would make changes on the subscription itself and then its gone/consumed.