#r.soares
1 messages ยท Page 1 of 1 (latest)
Hello ๐
You could use Subscription Schedules for this
It allows you to schedule an update to remove a subscription item
https://stripe.com/docs/billing/subscriptions/subscription-schedules
I'd recommend reading through the whole doc as it covers pretty much everything you need. There are examples for different usecases here
https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases
So if im understanding correctly, if i only pass the item i want to keep it will remove the rest ?
Correct
And it will trigger on start_date ?
Yes, I'd recommend trying it out in test mode as it will help clarify the process
You cannot set start_date if from_subscription is set.
So how would i go about that ?
[
'from_subscription' => $subscription->id,
'start_date' => 'now',
'phases' => [
[
'items' => [
[
'price' => 'price_1J7gawK9PS1qRjzz2L6IYsAo',
'quantity' => $current_quantity,
],
]
]
]
],
);```
Start date is the date at which the subscription starts. If you're creating the schedule from an existing sub, then it would have already started
So how do i make this trigger before the next invoice ?
You cannot set phases if from_subscription is set.
Now im confused
You'd need to make 2 api calls. 1 to create the schedule from the subscription then another to update the schedule: 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.
You'd just need to add a phase to the existing one (your current subscription) and set the end_date of the current phase to when you want your second phase with the changes to begin
So i need to simulate the current phase ??
$subscriptionSchedules->id,
[
'phases' => [
[
'items' => [
[
'price' => 'price_1J7gawK9PS1qRjzz2L6IYsAo',
'quantity' => 2,
],
],
'start_date' => 'now'
],
],
]
);```
-> You can not modify the start date of the current phase.
Yeah with subscription schedules you need to pass in all active phases when modifying the schedule. We call that out in our docs: https://stripe.com/docs/billing/subscriptions/subscription-schedules#updating
Stripe used to be the best API to work with, now is becoming just like the others... ๐ฆ
So for the first phase what start and end dates do i pass, "current_period_end": 1693747119,
"current_period_start": 1691068719, ???
You can retrieve the schedule: https://stripe.com/docs/api/subscription_schedules/retrieve
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
That'll show the current start date
Subscription schedules, specifically, are complicated
That's because they support so many niche/advanced usescases
Most users won't need them and can just use regular subscriptions, but schedules were designed to support a ton of functionality
Find it hard to think a use case where you pass your current phase that cant be done with subscription::update and leave the schedules endpoints for scheduling xD
Is there anyway to trigger the scheduled in the dashboard for testing ??
What do you mean by trigger the schedule?
The schedule is triggered by the dates you set in the phases
yeah, now i have to wait 1 month to see if it works ๐
Is there any button to apply the schedule changes before end date ?
Oh I gotcha. We built test clocks for this. You can read more about them here: https://stripe.com/docs/billing/testing/test-clocks
Uhh, i need to manually create a customer for this ?
Yeah
Kk, ill say nothing ๐