#oftysterista_api

1 messages ยท Page 1 of 1 (latest)

nova ravenBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1397054778726416425

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

acoustic fiber
#

hello orakaro

#

i am trying to do update price base on the documentation

// Create a subscription schedule with the existing subscription
const schedule = await stripe.subscriptionSchedules.create({
from_subscription: 'sub_ERf72J8Sc7qx7D',
});

// Update the schedule with the new phase
const subscriptionSchedule = await stripe.subscriptionSchedules.update(
schedule.id,
{
phases: [
{
items: [
{
price: schedule.phases[0].items[0].price,
quantity: schedule.phases[0].items[0].quantity,
},
],
start_date: schedule.phases[0].start_date,
end_date: schedule.phases[0].end_date,
},
{
items: [
{
price: '{{PRICE_PRINT_BASIC}}',
quantity: 1,
},
],
iterations: 1,
},
],
}
);

but if my subscription is on trial the trial is end when i run the code

#

hello are u there?

strange cloak
#

hi

#

Did you give the first phase as the trial period?

acoustic fiber
#

phases: [
{
items: [
{
price: schedule.phases[0].items[0].price,
quantity: schedule.phases[0].items[0].quantity,
},
],
start_date: schedule.phases[0].start_date,
end_date: schedule.phases[0].end_date,
},
{
items: [
{
price: '{{PRICE_PRINT_BASIC}}',
quantity: 1,
},
],
iterations: 1,
},
],
}

i just did this

strange cloak
#

Could you share the request id which created the SubSchedule and Update the Schedule?

acoustic fiber
#

same as documentation

#

actually i already update the subscription multiple times

#

where can i got the id?

strange cloak
#

With trial Sub you may need to tweak the phases

#

on Dashboard request log

acoustic fiber
#

i see when i run this
const schedule = await stripe.subscriptionSchedules.create({
from_subscription: 'sub_ERf72J8Sc7qx7D',
});

when i try to log the result, it have 2 phases if the subscription still have a trial

#

req_6bIp1iGmd4lrPS

#

this one

#

i think the trial ends because of when we update the schedule, the first phase is not the trial phase

strange cloak
#

Yes true, so you want to call the Update SubSchedule API that it preserve the first phase, and only change the second phase

acoustic fiber
#

okay so when update the subSchedule, I have to keep the first phase right?

#

so the trial ends because i font put the trial end value here in the first index

#

what values do I need to rewrite? because I see the tax is also missing.

strange cloak
#

So based off the response when you create SubSchedule from_subscription, take everything from there, include the id, make sure they are identical.

Then you only change the sencond phase price id from old id -> new id

acoustic fiber
#

so for the sencond phase i only need to copy the last phase from the created SubSchedule then change the priceid?

strange cloak
#

Yes, but make sure you also include the first phase (the trial one) exactly as the response from previous request

#
phases: [
  // Exactly first phase from previous response,
  // Taking second phase from previous response, then change price id,
]
acoustic fiber
#

yes i understand, lemme try

#

i think the second phase we need to get change the start_date and also the end_date? because it is possible if the subscription is not intrialing so the secong phase from created Schedule is not exist

#

is it correct?

strange cloak
#

It all depends on the previous response of from_subscription request. You would want to look at its content and decide which phase to change

acoustic fiber
#

do i need to copy the phase manually?

nova ravenBOT
strange cloak
#

I suggest to do so. Not sure what you mean by manually but while you code it, take the response and parse to your parameters

acoustic fiber
#

can i just directly update the subcription if i want to change the price for the next period?

#

or does it have to use a schedule?

mint iron
#

hi there, taking over the thread from my colleague ๐Ÿ‘‹ give me some time to catch up

#

if you are changing price on a subscription that is held by a subscription schedule, you need to update the subscription schedule directly

#

you cannot update the subscription directly because that will result in conflicts with the subscription schedule it is tied to.

acoustic fiber
#

no i mean like,

my goal is update a price for the next period.
so to achieve that goal can i just use subscription.update api or i have to use the subSchedule api?

mint iron
#

if you intend the price to only take effect in the next period, then you should use the subscription schedule API

acoustic fiber
#

i see

#

actually i have an issue when i want to copy the phase

#

as u can see in this docs, it create a schdule then update it with the first phase is comming from the created schedule

#

but the issue is it only takes the item, start date and end date. some value is missing for example like trial ends, and default tax

#

i can defined two of those (trial ends and the default tax) but i worry if there is other is missing

mint iron
#

For example, if your subscription changes collection_method in different phases, that's also something you can define under phases

acoustic fiber
#

i only want to change the priceId

#

so i need to re define all of the other key?

mint iron
#

generally you only need to define parameters you have changed but you should also check your subscription's configuration and ensure it aligns to the default values for each parameters under phases just to ensure nothing else changes

acoustic fiber
#

lemme try, cause what i have tried is for example i want to keep the current phase. but i dont defined the trial_end it makes the current phase end the trial period immediately

mint iron
#

hi @acoustic fiber to clarify, when you are creating a subscription schedule off an existing subscription that is trialing, the first phase of the schedule must mirror your subscription's existing state. so if your subscription is currently running on a trial, you can use phases.trial and phases.trial_end to signify that the trial is in progress and when it ends.

acoustic fiber
#

it is the same with the default_tax_rates

#

if i dont set it the tax is missing too

#

but i dont know if is there any other things that i need to rewrite it

mint iron
#

do you have a subscription ID that you could share?

acoustic fiber
#

okay sure

#

let me give u

#

sub_1RnZZgKxUzgEvuWhi6j5tuah

#

this one

mint iron
acoustic fiber
#

so price, trial and tax is enough?

mint iron
#

Let us know if you run into anything unexpected during your test

acoustic fiber
#

yes i think it is good enough at least for now