#borys

1 messages · Page 1 of 1 (latest)

oblique mortarBOT
whole bluff
#

here is the code snippet

const subscription = await stripe.subscriptions.retrieve(
    "sub_1Lmgn81WJGsEk3QvMNTN03yG"
  );

  const subscriptionSchedule = await stripe.subscriptionSchedules.retrieve(
    subscription.schedule
  );

  const newQuantity = 2;
  const phases = [];

  console.log(subscriptionSchedule);

  subscriptionSchedule.phases.forEach((phase) => {
    if (new Date(phase.end_date * 1000).getTime() < Date.now()) {
      // phase ended, cannot be updated, but need to preserve the order
      phases.push({
        items: [], // because of "Missing required param: phases[0][items]" error
        end_date: phase.end_date,
        start_date: phase.start_date,
      });
    } else {
      phases.push({
        items: phase.plans.map((item) => ({
          price: item.price,
          quantity: newQuantity,
        })),
        end_date: phase.end_date,
        start_date: phase.start_date,
      });
    }
  });

  console.log("updating with", phases);

  const subscriptionScheduleUpdated = await stripe.subscriptionSchedules.update(
    subscription.schedule,
    { phases }
  );

  console.log("updated", subscriptionScheduleUpdated);

but the update request still fails

solemn apex
#

What error message do you get back on the failure?

whole bluff
#

when running that code, still getting missing error

StripeInvalidRequestError: Missing required param: phases[0][items].
solemn apex
whole bluff
#

can post the log output if that be helpful

#

sure one sec

#

req_wjNZwq4Yq66GU1

solemn apex
#

Thank you, checking in to that request

#

So I am interested in your because of "Missing required param: phases[0][items]" error comment. You introduced that line of code to address that error?

whole bluff
#

yea but i just checked the req via dahsboard, and seems like empty array is not being sent out

#

changed code to

items: phase.plans.map((item) => ({ price: item.price }))

and seems to work fine now

solemn apex
#

As far as I understand, you can just pass the phase back in, you shouldn't need to manipulate it

#

Oh that would work too.