#kirito
1 messages ยท Page 1 of 1 (latest)
Hello
You want the update to occur one year from the time of update?
Or at the end of a yearly cycle?
And do the new/old Prices have the same interval? (like are they both annual?)
at the end of a yearly cycle, what I want exactly is a yearly subscription, but the payment should be monthly, that mean if a user want to upgrade or downgrade the subscription (change the prices) it should happen after 1 year cycle.
Yes they have the same interval (annual).
Hmm I'm a bit confused. You want the payment to be monthly?
Then that wouldn't be an annual interval
That would be a monthly interval
yes the payment to be monthly and the user need to pay the current subscription for the duration of at least 1 year, if he want to change the effect should effect only after 1 year cycle.
Okay I see
Then in that case you want to use the Subscription Schedules API: https://stripe.com/docs/billing/subscriptions/subscription-schedules
Have you seen that documentation yet or looked into that API?
yes, I tried it first but if I use from_subscription field I cant change the plans
Hmm what do you mean you can't change plans?
You have to update the Subscription schedule after you create it (using from_subscription)
When you update it you set 2 phases
On the second phase is when you would have the plans change
I cant use phases with from_subscription
Hello! I'm taking over and catching up...
Can you provide more details? What do you mean when you say you can't use phases with from_subscription?
Hello
ok I tried to use from_subscription with pashes contain items but it give me an error of unknown params
could You show me how to do it with from_subscription and Subscription Schedules API
could You show me how to do it with from_subscription and Subscription Schedules API
here is the code I used const subscription = await stripe.subscriptionSchedules.create({ start_date: oneYearFromNow, from_subscription: subscriptionId, end_behavior: "none", phases: [ { items: { id: oldSubscription.items.data[0].id, price: planId, }, }, ], metadata: { ...newMetadata, kisaco_subscription_code: code, }, })
Can you give me the request ID showing the failure? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_vSPPnEOgg40XWf
You need to create the Subscription Schedule using from_subscription first, then you update the Subscription Schedule with the phases you want. See the second code snippet here and the following section for details: https://stripe.com/docs/billing/subscriptions/subscription-schedules#managing
Ok, I will try
What you ask me to do is something similar to this : ``` const subscription = await stripe.subscriptionSchedules.create({
from_subscription: subscriptionId,
})
const subscription2 = await stripe.subscriptionSchedules.update(subscription.id, {
start_date: oneYearFromNow,
end_behavior: "none",
phases: [
{
items:
{
id: oldSubscription.items.data[0].id,
price: planId,
},
},
],
metadata: {
...newMetadata,
kisaco_subscription_code: code,
},
})``` ?
Yeah, more or less. I recommend renaming const subscription to const subscriptionSchedule, and I think you need to adjust the phases to account for the current phase, but that's the basic approach.
When updating a subscription schedule, you need to pass in all current and future phases that you want to keep.
After you create the Subscription Schedule from the Subscription have a look at it; there will already be a phase there based off of the Subscription.
If you want to keep that for some period of time and then switch to something different in the future you need to specify two phases when you update the Subscription Schedule: the current phase and the next phase in the future.
ok so how about something like this : ``` const subscriptionSchedule = await stripe.subscriptionSchedules.create({
from_subscription: subscriptionId,
})
const updatedSubscriptionSchedule = await stripe.subscriptionSchedules.update(subscriptionSchedule.id, {
phases: [
{
items:
{
id: oldSubscription.items.data[0].id,
price: oldSubscription.items.data[0].id,
},
end_date: oneYearFromNow,
},
{
items:
{
id: oldSubscription.items.data[0].id,
price: planId,
},
start_date: oneYearFromNow,
},
],
metadata: {
...newMetadata,
kisaco_subscription_code: code,
},
})````
I can't validate code snippets for you. I recommend running this code in test mode to see if it does what you expect.
No I got an error
What does the error say?
StripeInvalidRequestError: You cannot migrate a subscription that is already attached to a schedule: sub_sched_1MJhtxFeR0PUZyO7KqHGJKa5.
Okay, so the Subscription you're trying to create a Subscription Schedule for already has a Subscription Schedule.
You need to modify the existing one instead of trying to create a new one.
You can't have multiple Subscription Schedules for the same Subscription.
I understand, how about storing the schedules as a metadata and each time I want to update the subscription I check whether it exist or not.
Yep, you can do that.
Thank you, I will try it right now and see if there is any problem
I got the following error : StripeInvalidRequestError: Invalid array
param: 'phases[0][items]',
detail: undefined,
items needs to be an array, not an object.
It needs to be an array of objects, in fact.
OK and in this object should I also add the id params?
like these ``` [{
id: oldSubscription.items.data[0].id,
price: oldSubscription.items.data[0].id,
}],````
because I still get this error : param: 'phases[0][items][0][id]',
detail: undefined,
That likely means oldSubscription.items.data[0].id is undefined. Can you log out that value to make sure it's what you expect?
si_N3psyuTrc5VBlF
I think the error is because it is the id of the subscription item and not the price.
But I'm not sure why it show undefined
Can you give me the request ID showing that error?
req_Qw1VmjRW95Pwub
There is no id parameter when updating a Subscription Schedule's phases: https://stripe.com/docs/api/subscription_schedules/update#update_subscription_schedule-phases-items
Not sure about the undefined part, but if you remove the id parameter that should help you move forward.
yes it did, but now the error is : ๐ฅ StripeInvalidRequestError: The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.
Okay. Sounds like you need to add a start_date.
but when I update I got another error : ๐ฅ StripeInvalidRequestError: You can not modify the start date of the current phase.
which kind of confusing.
What are you setting start_date to?
"now"
You can't have the current phase start now. It already started in the past.
Because you're keeping the current phase, correct?
What start_date did you specify for the second phase?
the same as the end_data of the first one
phases: [
{
items: [{ price: oldSubscription.items.data[0].price.id }],
end_date: oneYearFromNow,
},
{
items: [{ price: planId }],
start_date: oneYearFromNow,
},
],
Can you share the request ID for that one?
req_NOOlWf8UmPX6AG
Okay, so if you add start_date to the first phase and set it to the start date of the current phase what happens?
what do you mean by the the start date of the current phase?
If you look at the Subscription Schedule you can see the current phase's start_date.
Use that value when updating.
Yes, it worked I'm now trying with the duration of 5min to see if the subscription will really update after that
Thank you so much for your help
No problem! ๐