#oftysterista_api

1 messages ¡ Page 1 of 1 (latest)

queen lanternBOT
#

👋 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/1396757497330794529

📝 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.

foggy magnet
#

hello sam

#

it's me again

#

i have tried the docs u given

#

but when i try to do stripe.subscriptionSchedules.create
the response doesn't have schedule.phases[

fair grove
#

Hi! I had to delete your message as it contained your secret test key. Can you post it again but without the secret key please?

foggy magnet
#

ohh sorry thanks

#

so yeah

#

const schedule = await stripe.subscriptionSchedules.create({
from_subscription: 'sub_xxxx',
});

#

the docs tell to do that

#

then
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 subscriptionSchedules.create doesn't have schedule.phases[0].items[0].price

fair grove
foggy magnet
#

but how can i fill this value?
price: schedule.phases[0].items[0].price,
quantity: schedule.phases[0].items[0].quantity,

#

schedule.phases[0] doesn't exist

#

wait

#

i think it is exist

#

sorry my bad

#

what will happen if we create a more than 1 schedule ?

fair grove
#

For the same subscription?

foggy magnet
#

yes

fair grove
queen lanternBOT
fair grove
foggy magnet
#

so if i want to create a new update, i need to release the previous one first right?

#

release the schedule will not roll back the phase that is already running, right?

#

are u still there sam?

glossy birch
#

I'm taking over. You should be able to update the existing schedule's phases. No need to release and attach a new schedule

foggy magnet
#

how to do it?

glossy birch
foggy magnet
#

will there be any shortcomings? for example if there is already a phase that is running

#

what if i just release the current schedule and create a new one?

glossy birch
#

Yes you can update the current phase. So you just need to make sure you pass the existing phase JSON into the payload for the update if you want it to remain the same

#

You need to pass in all current and future phases when you update a subscription schedule. You also need to pass in any previously set parameters that you want to keep. **Any parameters that were previously set are unset for the existing phase unless you pass those in the update request. **You still receive information in the response about past phases.

foggy magnet
#

what about this?
what if i just release the current schedule and create a new one?

foggy magnet
glossy birch
foggy magnet
glossy birch
#

No, the subscription will continue on it's current 'phase'

foggy magnet
#

okay i think it is simpler

#

but to release the schedule, the status must be active and not_active?

glossy birch
foggy magnet
#

completed
released
canceled
For these 3 statuses, we can override them with a new schedule, right?

glossy birch
#

Sort of I guess

foggy magnet
#

i have other question

#

when create a subsription, i fill this
default_tax_rates : [taxRate.stripeTaxRateId]

#

when creating a schedule, should i put it again?

glossy birch
foggy magnet
#

iterations: 12,

what is iterations in the phases?

glossy birch
#

Integer representing the multiplier applied to the price interval. For example, iterations=2 applied to a price with interval=month and interval_count=3 results in a phase of duration 2 * 3 months = 6 months. If set, end_date must not be set.

#

e.g. how many times the phase runs before it transitions to next phase

foggy magnet
#

okay i see

#

let's back to the tax rate

#

so i need to defined the default tax rates even in the first phase?

queen lanternBOT
glossy birch
foggy magnet
#

so basically i need to defined all thing like when i want to create the subcription in the phase?

glossy birch
#

Yes, exactly!

#

Map the phase parameters to Subscription create params

foggy magnet
#

const schedule = await this.stripeClient.subscriptionSchedules.create({
from_subscription: stripeSubscriptionId,
});

await this.stripeClient.subscriptionSchedules.update(schedule.id, {
  phases: [
    {
      items: [
        {
          price:
            typeof schedule.phases[0].items[0].price === 'string'
              ? schedule.phases[0].items[0].price
              : schedule.phases[0].items[0].price.id,
          quantity: schedule.phases[0].items[0].quantity,
        },
      ],
      start_date: schedule.phases[0].start_date,
      end_date: schedule.phases[0].end_date,
    },
    {
      items: [
        {
          price: prices.data[0].id,
          quantity: 1,
        },
      ],
      iterations: 1,
    },
  ],
});

in the documentation, i saw it rewrite the first phase,

what if i dont rewrite the first phase. instead i just put the second phase with the start_date : schedule.phases[0].end_date

prime quail
#

If you don't rewrite the first phase, then the second phase will be considered as the first phase

#

You need to keep the first phase, if you want to change just the second phase

foggy magnet
#

so my objective is change the price in the next period.

what if i only give 1 phase which will start at the end of the current period?

forexample current price is 100$ the next month will be 500$

prime quail
#

what if i only give 1 phase which will start at the end of the current period?
No you need to specify the 1st/existing phase too

#

And add a second phase with the new price

foggy magnet
#

i see

#

okayy

#

so what should i defined in the first phase?

#

because previously i am not define the default tax

#

and it is gone when the schedule is created

#

{customer: stripeCustomer.customerId,
items: [
{
price: prices.data[0].id,
},
],
expand: ['latest_invoice.payment_intent'],
payment_behavior: 'allow_incomplete',
payment_settings: {
save_default_payment_method: 'on_subscription',
},
default_payment_method: stripePaymentMethodId,
metadata,
default_tax_rates: taxRate ? [taxRate.stripeTaxRateId] : undefined,
trial_period_days: payload.trialPeriodDays,
}
this is the payload when i create the subscription

prime quail
#

so what should i defined in the first phase?
You specify the existing phase, you can make a get by Id to the Subscription details before updating it. And then update the schedule by specifying the first phase details from the get by id response