#haxor-schedules-change

1 messages ยท Page 1 of 1 (latest)

high narwhalBOT
gray glacier
#
const createSubscriptionSchedule = async (customerId, currentSubscriptionId, newPlanId) => {
  const subscription = await stripe.subscriptions.retrieve(currentSubscriptionId);

  await stripe.subscriptionSchedules.create({
    customer: customerId,
    from_subscription: currentSubscriptionId,
    items: [
      {
        id: subscription.items.data[0].id,
        plan: newPlanId,
      },
    ],
    start_date: 'now',
    end_behavior: 'release',
  });
};

This is the headstarter

#

my senior gave me

main mesa
#

haxor-schedules-change

#

@gray glacier based on what you described, you would be better off creating the SubscriptionSchedule upfront with all the details/phases needed really

gray glacier
#

The subscription is created from payment link actually

#

I capture the details on the webhook and then want to do these changes

main mesa
#

I'd advise against this entirely personally since the UI won't show any info about when it will end, what the new Price will be, etc.

#

but otherwise you call the Update SubscriptionSchedule API after that code adn you set a first phase on Price A with a number of iterations (number of months) and then a second phase on Price B

gray glacier
#

Yes, this I know but I am given task to do this way only unfortunately, I cant go otherwise unless I want to get fired lol

main mesa
#

that's a bit dramatic ๐Ÿ˜…

#

like you're the developer, you can explain why it's a bad idea and then offer an alternative where you properly design and build this

gray glacier
#

I already explained them

main mesa
#

okay then use the alternative approach I covered!

gray glacier
#

If that was accepted, I wouldnt have message here ๐Ÿ˜„

#

Ohk I have one more qeustion

#

Since my end_behavioud is release so it will trigger subscription_schedule.released after phase 2 is applied

      const subscriptionItems = await stripe.subscriptionItems.list({ subscription: subscription.id });
      
      await stripe.subscriptionSchedules.create({
        from_subscription: subscription.id,
        default_settings: { collection_method: "charge_automatically" },
        phases: [
          {
            items: [{ quantity: 1, price: subscriptionItems.data[0].price.id }],
            iterations: 1,
          },
          {
            items: [{ quantity: 1, price: process.env.STRIPE_ANNUAL_UPGRADE_PLAN_ID }],
          },
        ],
        end_behavior: "release",
      });
main mesa
gray glacier
#

Thanks

#

Could you please help me with confusion between

subscription_schedule.completed and subscription_schedule.released?

#

Event types

#

Which more accurately gives me the webhook when the phase 2 is applied on the subscription

main mesa
#

the completed one is when the SubscriptionSchedule ends and the underlying Subscription is canceled
the released one is when the SubscriptionSchedule ends and the underlying Subscription is still active