#TonyS

1 messages · Page 1 of 1 (latest)

manic valveBOT
stark fog
#

đŸ‘‹ happy to help

crimson venture
#

I give you some example of code here :

#

const subscriptionSchedule = await stripe.subscriptionSchedules.create({
from_subscription: "sub_XXX",
})

const currentPhaseItem = subscriptionSchedule.phases[0]

console.log(currentPhaseItem)

await stripe.subscriptionSchedules.update(
"sub_sched_XXXX",
{
proration_behavior: "none",
end_behavior: "release",
phases: [
{
items: [{ price: currentPhaseItem.items[0].price }],
iterations: 1,
},
{
start_date: subscriptionSchedule.current_phase.end_date,
items: [{ price: "price_XXXX", quantity: 1 }],
},
],
}
)

#

Thank you Tarzan! Hope you are doing well!

stark fog
#

Thanks I'm doing fine, reading through your code will be with you in a sec

crimson venture
#

Great, thank you! Take your time!

stark fog
#

what is the result that you're getting and what are you expecting instead?

crimson venture
#

What we are expecting is : 1) not do anything about current subsription 2) Add a monthly subscription after the end of the yearly one that will renew every month

#

The errror is the following : StripeInvalidRequestError: The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.

#

The problem being, if we add a start_start in the first phase it throw this error :

#

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

#

I think we are doing something wrong but I'm unsure about the best way to handle this situation

stark fog
crimson venture
#

Sure

#

req_Z4fB1Sfb91P6kT

stark fog
#

there's something I might have missed at first

#

I thought that the Subscription was already ongoing

#

and you wanted to make a change

#

but looking at your logs, the Subscription was created today

crimson venture
#

Yes we are testing it

#

we created a yearly subscription to simulate our case

#

and try to add a monthly subscirption AFTER the end of the active yearly subscirption

#

sub_1MP20TDhXwH3fVpP6eqrJvCO is the sub_id

stark fog
#

so my question is, is your use case regarding a new Subscription where you have that schedule or is it an ongoing Subscription where the customers chooses to change the plan to monthly?

crimson venture
#

The second one if I understand correctly

#

An user pay yearly on our service

#

and decide "I want to pay monthly after the end of my yearly period it will be better"

#

Sorry if i'm unclear

stark fog
#

no that's pretty clear

#

so my first assumption was right

crimson venture
#

ok could you maybe be more specific?

stark fog
#

yes I will sorry for the confusion I just wanted to make sure we're moving in the right direction

crimson venture
#

Ok thank you!

stark fog
#

would you mind trying out this code?

    "sub_sched_XXXX",
    {
      proration_behavior: "none",
      end_behavior: "release",
      phases: [
        {
          ...currentPhaseItem
        },
        {
          start_date: subscriptionSchedule.current_phase.end_date,
          items: [{ price: "price_XXXX", quantity: 1 }],
          iterations: 1
        },
      ],
    }
  )
crimson venture
#

Ok i'll try right away

#

StripeInvalidRequestError: You passed an empty string for ‘phases[0][collection_method]’. We assume empty values are an attempt to unset a parameter; however ‘phases[0][collection_method]’ cannot be unset. You should remove ‘phases[0][collection_method]’ from your request or supply a non-empty value.

stark fog
#
const {start_date, end_date, items} = currentPhaseItem;
await stripe.subscriptionSchedules.update(
    "sub_sched_XXXX",
    {
      proration_behavior: "none",
      end_behavior: "release",
      phases: [
        {
         start_date, end_date, items
        },
        {
          start_date: subscriptionSchedule.current_phase.end_date,
          items: [{ price: "price_XXXX", quantity: 1 }],
          iterations: 1
        },
      ],
    }
  )
#

did that work for you?

crimson venture
#

Sorry I'm off to lunch break, I'll test in a moment