#_obo_
1 messages ยท Page 1 of 1 (latest)
Hello! It depends on your use case. Can you link me to where you're seeing that?
my use case is pretty simple, I just want to downgrade a user at the end of their subscription billing cycle
Ah, gotcha. I honestly don't know why we recommend that there... setting start_date to whatever you want, be it a date in the past, future, or now are all equally valid use cases.
so I am using the right API endpoint for scheduling a downgrade at the end of a subscription's billing cycle, yes?
or is there another (better) way of doing this I should know about
You're doing the right thing, yeah. You would use a Subscription Schedule with phases that describe the changes you want made to the Subscription in the future.
Your use case is actually documented here: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#downgrading-subscriptions
Can I also do this with just a simple subscriptions.update call? ChatGPT seems to think so, but that seems somewhat off to me so i wanted to double check what it's suggesting. Let me provide the code real quick
async function downgradeSubscription(subscriptionId, newPlanId) {
try {
const subscription = await stripe.subscriptions.update(subscriptionId, {
items: [{
id: subscription.items.data[0].id,
price: newPlanId,
}],
prorate: false,
billing_cycle_anchor: 'now'
});
console.log('Subscription downgraded successfully:', subscription);
} catch (error) {
console.error('Error downgrading subscription:', error);
}
}
const currentSubscriptionId = 'sub_xxx'; // Your subscription ID here
const newPriceId = 'price_xxx'; // Your new price (plan) ID here
downgradeSubscription(currentSubscriptionId, newPriceId);
this stuck out specifically:
"The basic method I initially provided pertains to Stripe's direct Subscription API, where you can upgrade, downgrade, or modify an existing subscription. The method provided will change the subscription at the end of the current billing cycle. The parameters prorate and billing_cycle_anchor are used to control the billing adjustments and the timing of the change. This approach is straightforward and works for many basic use cases."
it seems to think that subscription schedules are for doing things like A-> B -> C -> A
(sorry for being a pain here, I'm sure you know more than chatGPT here)
I recommend you avoid using ChatGPT to help you with Stripe code. It usually gets things wrong, often in subtle ways that will cause you a lot of pain later.
We're here 24/6 and can answer your questions better than an ML chat bot can. ๐
To answer your question though, you can update an existing Subscription to upgrade or downgrade it without a Subscription Schedule, but the changes are immediate.
If you want an upgrade or downgrade to happen in the future you can either schedule the Subscription update on your end, or you can use a Subscription Schedule to schedule the change on our end.
Okay perfect, thank you for the confirmation. Just wanted to make sure I wasn't missing something obscure
Of particular note, this part: "The method provided will change the subscription at the end of the current billing cycle." That's 100% incorrect.
haha, yes that's why I specifically came to the discord chat
spidey sense were going off
thanks for your confirmation
so from looking at the docs you provided, and the api docs, the example you linked still does have start_date: 'now'. For my use case specifically (downgrading at the end of the month), it seems like i would want to set the "from_subscription" value to the subscription i'm looking to modify and end_behavior to "release".
However the rest of things is confusing me a bit here.
-
Would what I need to include for "phases" here since it's just one change and not multiple?
-
what would I put for the start_date? If I leave this blank what would it default to given the settings above?
The examples you're looking at show the creation of a Subscription Schedule which, in turn, creates a Subscription on the start_date specified. In many use cases people want to create both the Subscription Schedule and the Subscription at the same time, which is why you're seeing start_date set to now.
For your use case you would have at least two phases: the first phase would be the current state of the Subscription, before the downgrade, and the second phase would start in the future and describe the state of the Subscription after the downgrade.
For your last question, can you clarify if you're trying to apply a Subscription Schedule to an existing Subscription?
yes, the customer will have a current subscription, and then if they choose to downgrade their subscription, we let them use their current plan until the end of their billing cycle, at which point they will be downgraded to whatever the next plan they chose was
Ah, okay, so have a look here: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
You create a Subscription Schedule for the existing Subscription, which will automatically create the first/current phase based on the current state of the Subscription, then you can update the Subscription Schedule with the second downgrade phase in the future.
got it, for my use case, could I just do that in a singular call? or do you have to do it in a separate API call?
It would be at least two separate API calls, one to create the Subscription Schedule for the existing Subscription, a second one to modify that Schedule with the upcoming changes you want.
Do you know about Test Clocks?
I recommend reading about them now. They let you speed up time in test mode, which makes testing things like Subscription Schedules a lot easier: https://stripe.com/docs/billing/testing/test-clocks
good to know. do they affect other parts of the subscription or is it pretty isolated?
(things like billing anchors, etc)
They impact everything contained within them. If you read that page things should become clear. ๐