#ali_best-practices
1 messages ¡ Page 1 of 1 (latest)
đ 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/1417912446898933777
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
We saw that the main subsription has a cancel_at_period_end option, which will work perfect for our use case if it was supported on subscription items
but wondering what you guys think is best practice here in this instance
would appreciate your help!
Got it, are you deleting the subscription item when the feature is canceled?
no currently we schedule the deletion of the subscription item until after the subscription period end
because stripe API forces us to clear usage if we delete mid cycle
so we opt to force clear any extra usage after the billing period is done to reduce monetary impact
we just mark the subscription item for deletion at subscription period end internally and have a cron job do it manually in the future
so basically what this translate to is that:
- customer subscribes for metered billing feature
- they use it and accumulate $10 of usage
- they cancel the feature after that
- we mark their feature as cancelled internally and block their access to it
- we mark the stripe subscription item for deletion at period end (to prevent having to clear that $10 of usage)
- user gets invoiced at the end of the month, pays for base sub plus $10 usage
- our worker runs sometime after that to force delete the subscription item starting from the new billing period
I think what we did is fine for now, but wondering what other customers of yours do and what you recommend in terms of best practices
Have you attempted prorating the subscription item on delation?
yes but stripe API blocks calls to delete an item if you don't also clear usage
we get an error saying that we must clear usage
https://docs.stripe.com/api/subscription_items/delete
this is what we use and it forces you to clear usage
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yep. I'm looking to see if there's an alternative to your current approach.
if it helps this is exactly what we do
const subscriptionItem = await this.stripeClient.subscriptionItems.retrieve(subscriptionItemId);
// Update the subscription to remove this item with prorations
await this.stripeClient.subscriptions.update(
subscriptionItem.subscription as string,
{
items: [
{
id: subscriptionItemId,
deleted: true,
clear_usage: true,
},
],
proration_behavior: 'create_prorations',
}
);```