#haxor-schedules-change
1 messages ยท Page 1 of 1 (latest)
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
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
The subscription is created from payment link actually
I capture the details on the webhook and then want to do these changes
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
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
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
I already explained them
okay then use the alternative approach I covered!
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",
});
yes, you can use Test Clocks to simulate this (but not with a PaymentLink) https://stripe.com/docs/billing/testing/test-clocks
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
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