#Mathieu-subscription

1 messages · Page 1 of 1 (latest)

earnest inlet
#

Hi there!

#

is it possible to set the invoice.upcoming interval at less than 3 days with the dashboard ?
No 3 days is the minimum.

#

I'm trying to do a subscription update with proration_behavior none to adjust some item quantity just before the renewal cycle but this 3 days gap can let the time for our user to mess with there subscription.
I'm not sure to understand, what do you mean by "for our user to mess with there subscription"? Can you give an example?

serene whale
#

Our integration aim to let the user the freedom of cancelling some of his "licences" (by cancel we mean reduce the quantity of his product subscription) but he can also add up more licence during the year.
This 'cancel effect' can be revert at any time to, if the user changes his mind before renewal, keep the licence.
To ease dealing with cancelling, while adding product needs to be proration_behavior always_invoice, we decide to "only" deal with this cancel quantity update at the renewal time.

Here is a basic working scenario :

  • Customer buys 5 licences yearly at 7 June 2022
  • Customer cancel 3 licences at september 2022 (as explain above we don't update at this point)
  • We receive the invoice.upcoming event the 4 June 2023
  • On response we call subscription.update with the fix quantity of 5-3 => 2 licences
  • At that point everythings works fine the customer can even add more licence if he wants to
  • It's 7 June 2023 and the customer is well paid with 2 licences

And so by doing some test i can fall into this extreme yet possible scenario :

  • Customer buys 5 licences yearly at 7 June 2022
  • Customer cancel 3 licences at september 2022 (as explain above we don't update at this point)
  • We receive the invoice.upcoming event the 4 June 2023 => call subscription.update with the fix quantity of 2 licences
  • If the customer cancel again like 1 licence the 5 june 2023 we don't call the subscription.update as we don't want this behavior to trigger subscription.update
  • Then at 7 June 2023 the customer will pay 2 licences instead of 1
serene whale
wooden moon
#

hi sorry, I'm taking over for @earnest inlet , please give me a few minutes to catch up and respond

mellow kernel
#

Hey there, sounds like a pretty advanced billing system! Have you considered instead implementing schedules to handle these updates?

serene whale
#

Hi i've try to use them but didn't really succeed to apply it correctly to the subscription

#

Do you have some code example of schedule call for an existing subscription to reduce the quantity of a product at the renewal cycle timing ?

serene whale
#

When i try your example with negative quantity (because i need to reduce the quantity) i got this error "Invalid non-negative integer"

#

Seems like schedule object have been designed for adding quantity not reducing it

mellow kernel
#

Well you'd just pass the positive integer that reflects the quantity you want to be

#

So if its originally 5, and you want to remove 2 quantity, you'd pass 3

serene whale
#

ah ok that it's the targetted value my bad

#

with your example a new subscription is being added to the customer but i want to edit the existing one
i guess i must use the from_subscription param instead of the customer param ?

mellow kernel
#

Yup, that's right. If you have an existing subscription you want to now control with a schedule

serene whale
#

Ok so now i got this error "You cannot set phases if from_subscription is set." but how do i specify my changes then ?

mellow kernel
#

It'd be 2 different calls: initially with from_subscription, then you can do a subsequent update with phases

serene whale
#

can you skip the current phase config when calling schedule update or do you must redefine the actual price config before add the next phase ?

mellow kernel
#

If you omit a current phase in the update call, it'll be removed

serene whale
#

since i just create the schedule my current phase items must match the current items subscription is that it ?

reef sigil
#

yes, usually you end up with a phase with start_date:subscription.current_period_start and end_date:current_period_end

serene whale
#

Then it is in the second phase that i set the items "target" ?

reef sigil
#

you can think about it that way sure

serene whale
#

and the start_date of the second phase must be equal to the end_date of the first one if i understand ?

reef sigil
#

yep, the phases have to be concurrent and uninterrupted

#

if it helps here is a random example script I have that demonstrates the concept

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

// schedule a change from gold to silver 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" => "1632738750",
      'plans' => [
        [
          'plan' => $gold->id,
          'quantity' => 1,
        ],
      ],
      "prorate" => "true"
    ],
    [
      "start_date" => "1632738750",
      "billing_cycle_anchor" => "phase_start",
      'plans' => [
        [
          'plan' => $silver->id,
          'quantity' => 1,
        ],
      ],
      "prorate" => "true"
    ],
  ],
  "end_behavior" => "release"
]);
serene whale
#

is it possible to phase an update at the end of a subscription cycle then release it immediately so that the customer can retake the lead of his subscription ?

pliant dove
#

Hello 👋
Taking over here as karllekko had to step away

#

Not sure I fully grasp the question, what do you mean by customer re-taking the lead of the subscription exactly?

serene whale
#

I update a schedule with, i believe, a duration phase too long ending up stacking subscription update from the customer on top of my schedule :

2023 - 2024 being my schedule api
2024-2025 being my manual customer test subscription update

#

i mean is it possible to have phase during just one second ?

pliant dove
#

Still grasping the question but do you mean making the phase last one second and releasing the subscription from the schedule?

serene whale
#

yes

pliant dove
#

I dont know for sure as this is really a niche usecase but I'd recommend trying it out in testmode
You can set the length of a phase using start_date and end_date . Also, defining end_behavior as release should release the subscription from schedule

serene whale
#

ok thanks all for your time, i will do some more testing