#mathan
1 messages ยท Page 1 of 1 (latest)
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?
I need to add another plan or price in the next billing cycle!
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.
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,
],
],
]
);`
In your first phase (that has empty body), you should change to the first phase returning from the subscription schedule object during subscription creation
for example, how can I fill the first phase?
๐ taking over
?
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
Does this start from the subscription create object or the current subscription?
It's hard to tell. Let's try retrieving the Subscription Schedule to see in detail
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,
],
],
]
);`
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,
],
],
]);
In phase 2 start_date will be the end date of the current subscription right?
how can I set the end date like one billing cycle dynamically?
Yes you should be able to use iterations from 2nd phase. It's more convenience and accurate
how can I add iterations in this code?
if I add iterations, do I need start_date and end_date?
Here https://stripe.com/docs/api/subscription_schedules/update#update_subscription_schedule-phases-iterations. I would suggest looking at API Reference
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
if I add iterations, do I need start_date and end_date?
I think you don't. Let's just try it
` $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
That looks unrelated. Have you looked at your requests log in Dashboard?
Let's see what exactly the error returned from Stripe
Better to just use Retrieve Subscription Schedule API
Okay nice, but if the customer changes his plan in the customer portal how can I schedule? anyways?
You can still retrieve the latest Subscription Schedule from that Subscription, no?
No, how can schedule the subscription, if the customer changes his plan in the customer portal?
You mean after you make the schedule, the customer changes his plan on customer portal?
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?
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?