#evan_api

1 messages ยท Page 1 of 1 (latest)

marsh grottoBOT
#

๐Ÿ‘‹ 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/1293498753541738519

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

wooden storm
#

Hi
You need simply to remove billing_cycle_anchor: 'unchanged' because if. you are downgrading to a price with a different interval

civic tide
#

Will try this quickly now, and get back to you

civic tide
#

well I commented this as advised.
It is basically chraged the user instantly and it moved from one plan to another

#

this is the subscription id for reference

#

sub_1Q7w88D9sYh65PYtRu5SEv0J

wooden storm
#

Yes but it didn't generated a proration right ?

#

Is this what you want or not ?

lapis badge
#

Hi sorry for jumping in. i'm a colleague with Evan working on same project. we want to:

  • users having existing subscription
  • they choose another plan to downgrade
  • user will be downgraded only after the end of current billing period
  • user subscription details will be changed only after the end of billing cycle
  • no proration applied on the new downgraded plan because it will start from fresh billing cycle
wooden storm
#

You can achieve this using Subscription Schedulers

#

You create a scheduler from an existing Subscription (nothing will change)

wooden storm
civic tide
#

I will try this quickly and get back to you

lapis badge
#

Will create:

  • new scheduler using from_subscriptions
  • then we do update on the created scheduler using scheulder.id
  • we apply the phase of downgrade within the update API request
  • the phase should only have 1 plan which is the new plan we are going to downgrade to? or we need to have 2 phases the one for the current subscription state and second for the downgraded plan for future?
  • what will be the start_date values for the downgrade phase?
wooden storm
#

the phase should only have 1 plan which is the new plan we are going to downgrade to?
You need to keep the existing phase, and update the upcoming phase with the downgraded price

#

what will be the start_date values for the downgrade phase?
The end date of the current phase

lapis badge
#

To confirm , first i will need to retreive the created scheulder and get the values of the first phase created from_subscriptions parameter.. add it to the update scheduler API request as first phase then second phase will be the downgraded plan ...etc

wooden storm
#

Yes

marsh grottoBOT
lapis badge
#

great , Will test and let you know

lapis badge
#

I'm applying this flow but getting below error:

  let scheduleId = providerSubscription.schedule
  let schedule = null
  if (!scheduleId) {
    schedule = await stripeGatewayClient.subscriptionSchedules.create({
      from_subscription: providerSubscription.id,
    })
    console.log('๐Ÿš€ ~ schedule:', JSON.stringify(schedule))
    scheduleId = schedule.id
  }

  schedule =
    await stripeGatewayClient.subscriptionSchedules.retrieve(scheduleId)

  const defaultPhase = schedule.phases[0]
  const subscriptionSchedule =
    await stripeGatewayClient.subscriptionSchedules.update(scheduleId, {
      end_behavior: 'release',
      phases: [
        {
          ...defaultPhase,
          collection_method: 'charge_automatically',
        },
        {
          ...defaultPhase,
          items: [
            {
              price: newProviderPlan.id,
            },
          ],
          collection_method: 'charge_automatically',
          start_date: defaultPhase.end_date,
          metadata: {
            subscriptionPlanId: paymentObj.newSubscriptionPlan.id,
          },
        },
      ],
    })

Error getting:

{"level":"error","message":"500 - You passed an empty string for 'phases[0][coupon]'. We assume empty values are an attempt to unset a parameter; however 'phases[0][coupon]' cannot be unset. You should remove 'phases[0][coupon]' from your request or supply a non-empty value. - POST - /subscriptions/providers/upgrade-downgrade"}

even though i tried to pass the coupon value as null explicitly as i don't have any coupon applied to the subscription phases. not sure what is the required parameters for the update API of scheduler?

burnt dove
#

Hi! I'm taking over from my colleague. Please, give me a moment to catch up.

#

Could you please summarise what you're trying to achieve at this point?

burnt dove
lapis badge
#

as per error it shows that phases[0][coupon] should not be empty while performing update to the subscription scheduler

burnt dove
#

Could you please share the Schedule ID?

lapis badge
#

"sub_sched_1Q7whsD9sYh65PYt4tclpQgp"

burnt dove
#

I suspect it's due to subscriptionSchedules.retrieve() gives you a Schedule with coupon: null. But you can't use it when updating the Schedule.
I think you need to explicitly remove the coupon property from the defaultPhase object.

#

Could you please try and see if it works?

lapis badge
#

so what values i should be using for the defaultPhase .. i added the defaultPhase that i got from retrieve just to not miss anything for the default created phase. adding manually the items, start_date, end_date should be enough values only?

burnt dove
#

Yes, but you have to remove the coupon key from the object.

lapis badge
#

alright let me check and update you

#

Seems like this worked now. i can see the scheduler object is updated.

  • subscription is now not touched as object and no invoice made which is what we want.
  • subscription now is flagged with 'update scheduled' on stripe dashboard
  • phase 2 is created start_date is same as end_date for the phase 1

Questions around this:

  • when the subscription phase 2 get triggered .. plan (price) will change to the new one attached to phase 2
  • is scheduler will be removed after that autoamtically? or i need to do manual removal? having in mind i set end_behavior: release
  • if in the middle of the phase 1 before applying phase 2 using the scheduler .. if a user want to cancel the downgrade action. should i just remove the scheuduler by schedulerId? is that will remove this action and keep subscription as non touched?
burnt dove
#
  1. The second phase will run until the end - which is, by default, one billing cycle - and then be released, remaining in the last phase state forever.
#
  1. You can either release the Schedule immediately, or update the Schedule to remove the 2nd phase. The Schedule will be released after the current phase ends.
lapis badge
#

Alright thanks, let me check the release case and let you know

marsh grottoBOT