#lucas

1 messages ยท Page 1 of 1 (latest)

dire spadeBOT
placid prism
#

Hi! Let me help you with this.

remote crescent
#

what ive done so far is create a subscription schedule attached to the subscription with the following code

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

then attempted to update what i would hope is the current active phase (now -> next invoice date) using the following

  const phaseUpdate = await stripe.subscriptionSchedules.update(
    'sub_sched_1NBzkoEk6sr5GyDh592mSuA2',
    {
      end_behavior: 'release',
      phases: [
        {
          items: [{ price: 'price_1KGRnzEk6sr5GyDh05GHnux1', quantity: 1 }],
          end_date: new Date('2023-06-01').getTime() / 1000,
          proration_behavior: 'none',
        },
      ],
    }
  );

the problem im seeing is that i get a 400 with

The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.
when i leave off start date, and
You can not modify the start date of the current phase.
when i use start_date: 'now'

#

thanks vanya!

#

no dice with substituting billing_cycle_anchor rather than start_date either

placid prism
#

You might need to add a second phase, where the first phase is the current one.

remote crescent
#

oh so rather than move the end date of the current phase, move the start date of the second phase?

#

interesting, ill give it a shot

placid prism
#

Please let me know if this works

remote crescent
#

hmm so i started off with

const phaseUpdate = await stripe.subscriptionSchedules.update(
    'sub_sched_1NBzkoEk6sr5GyDh592mSuA2',
    {
      end_behavior: 'release',
      phases: [
        {
          items: [{ price: 'price_1KGRnzEk6sr5GyDh05GHnux1', quantity: 1 }],
          iterations: 1,
          proration_behavior: 'none',
        },
        {
          items: [{ price: 'price_1KGRnzEk6sr5GyDh05GHnux1', quantity: 1 }],
          start_date: new Date('2023-06-01').getTime() / 1000,
          proration_behavior: 'none',
        },
      ],
    }
  );

to try to add a second phase, and i received

The subscription schedule update is missing at least one phase with a start_date to anchor end dates to

which is curious, since i do have a start date in there...

placid prism
#

Hm, let me check.

#

Try setting the first start_date to 'now'

remote crescent
#

sure, trying

#

another error, but this one now seems workable,

There is a gap between phase 0 (1685107379, 1693056179) and phase 1 `(1685577600, 1693526400)

#

gah

  const phaseUpdate = await stripe.subscriptionSchedules.update(
    'sub_sched_1NBzkoEk6sr5GyDh592mSuA2',
    {
      end_behavior: 'release',
      phases: [
        {
          start_date: 'now',
          end_date: new Date('2023-06-01').getTime() / 1000,
          items: [{ price: 'price_1KGRnzEk6sr5GyDh05GHnux1', quantity: 1 }],
          iterations: 1,
          proration_behavior: 'none',
        },
        {
          items: [{ price: 'price_1KGRnzEk6sr5GyDh05GHnux1', quantity: 1 }],
          start_date: new Date('2023-06-01').getTime() / 1000,
          proration_behavior: 'none',
        },
      ],
    }
  );

results in

You may only specify one of these parameters: end_date, iterations.

but

  const phaseUpdate = await stripe.subscriptionSchedules.update(
    'sub_sched_1NBzkoEk6sr5GyDh592mSuA2',
    {
      end_behavior: 'release',
      phases: [
        {
          start_date: 'now',
          end_date: new Date('2023-06-01').getTime() / 1000,
          items: [{ price: 'price_1KGRnzEk6sr5GyDh05GHnux1', quantity: 1 }],
          proration_behavior: 'none',
        },
        {
          items: [{ price: 'price_1KGRnzEk6sr5GyDh05GHnux1', quantity: 1 }],
          start_date: new Date('2023-06-01').getTime() / 1000,
          proration_behavior: 'none',
        },
      ],
    }
  );

gives me

You can not modify the start date of the current phase.

taking start back off and i'm back where i started

The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.

chilly geyser
#

Hi there ๐Ÿ‘‹ jumping in as my teammate needs to step away soon. Can you share the ID of your most recent request (should start with req_) and help me understand what you're trying to change with this update request?

remote crescent
#

hello!

from an end user perspective we have customers with subscriptions and we ship them physical packages based on their invoices (we'll never prorate)

i want to allow our customers to reschedule their upcoming invoice/shipment via a calendar picker. i do not want to use trial as a "hack"

im trying to accomplish this with subscription schedules, and having trouble figuring out the phases i need - we think either to move the end date of the first phase up or push the start date of the second phase out

last request was req_6PrKWyZoQlm5RT

chilly geyser
#

Gotcha, so looking at the request above, can you try making that request again, but for the first phase also pass the start_date parameter and provide it with the value that is already set for that phase?

remote crescent
#

sure, whats the easiest way to determine the exact millis for the current phase start? ill try to retrieve the sub schedule and look, i suppose

chilly geyser
#

Yup, retrieving and checking is the best way for that.

remote crescent
#

oh shoot, i think it worked. a 200 response anyway. looking at the UI

chilly geyser
#

The Subscription Schedule update needs enough dates/interval details to be provided for it to know exactly where you want the phases to be, and it won't rely on already set values to make that determination, so you typically need to resupply it with the start date of the first phase so it know where to pin everything.

remote crescent
#

ten four, thank you. its a little confusing looking at the UI now to know what it'll actually do next, let me show you

#

the exact update i ran for reference

 const phaseUpdate = await stripe.subscriptionSchedules.update(
    'sub_sched_1NBzkoEk6sr5GyDh592mSuA2',
    {
      end_behavior: 'release',
      phases: [
        {
          start_date: 1684865215,
          end_date: new Date('2023-06-01').getTime() / 1000,
          items: [{ price: 'price_1KGRnzEk6sr5GyDh05GHnux1', quantity: 1 }],
          proration_behavior: 'none',
        },
        {
          items: [{ price: 'price_1KGRnzEk6sr5GyDh05GHnux1', quantity: 1 }],
          start_date: new Date('2023-06-01').getTime() / 1000,
          proration_behavior: 'none',
        },
      ],
    }
  );
chilly geyser
#

Taking a look at the current state of things, just a moment.

#

Alright, I see the Schedule has two phases, but I'm not spotting anything in those phases that would result in a change to the underlying Subscription. Let's take a step back from the Schedule for a moment, what about the underlying Subscription are you wanting to change with this process? Is it the billing_cycle_anchor that you want to move around, or something else?

remote crescent
#

yeah, probably more the billing cycle anchor than anything else

#

10k foot view

customer asked us to charge them 10 days before when their next recurrence would be
customer asked us to charge them 10 days after when their next recurrence would be

in either case, the next invoice after that should be based on their regular schedule

#

(also bill now, but i know that can be currently accomplished quite easily with billing anchor and without sub schedule/phases)

chilly geyser
#

Gotcha, if I recall our previous conversations correctly you're working with 3-month prices.

So for instance, if you have a Subscription that is currently in a billing period from:
May 1 - Aug 1 (next phase Aug 1 - Nov 1)
and you want to move the generation of the next Invoice back, but not delay the generation of Invoices after that point, so something like:
May 10 - Aug 1 (next phase Aug 1 - Nov 1)

Does that sound about right?

remote crescent
#

yes i wasnt sure if you'd remember me ๐Ÿ™‚

chilly geyser
#

๐Ÿ˜„ gotcha, then I believe it is the billing_cycle_anchor that you'll want to have your phases adjust. You can have a phase reset the billing_cycle_anchor for the underlying Subscription by utilizing the phases.billing_cycle_anchor parameter:
https://stripe.com/docs/api/subscription_schedules/object#subscription_schedule_object-phases-billing_cycle_anchor

You can use a value of phase_start for that parameter to have the billing cycle anchor aligned with the beginning of the phase when the Schedule updates the Subscription.

remote crescent
#

okay cool. im starting to get busy with meetings but i plan on testing as soon as im able

dire spadeBOT
remote crescent
#

what confuses me off the bat with billing_cycle_anchor is that its not something you pass millis to. could you maybe give me an assist by listing out the concrete steps i'd take, like

  1. make sub schedule for sub
  2. add a phase <with billing anchor value = blah>
  3. etc
chilly geyser
#

Correct, billing_cycle_anchor can't accept exact timestamps once a Subscription is created.

  • Create Subscription Schedule
  • Update Subscription Schedule with desired changes
    • add a phase for the shift, and add a phase to shift back to the typical timing
    • if you want to align the billing anchor to the phase start, then set billing_cycle_anchor to phase_start
    • if you don't want prorations to be calculated for this change, then set proration_behavior to none