#ali_best-practices

1 messages ¡ Page 1 of 1 (latest)

hushed anvilBOT
#

👋 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.

crystal mist
#

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!

next field
#

Got it, are you deleting the subscription item when the feature is canceled?

crystal mist
#

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:

  1. customer subscribes for metered billing feature
  2. they use it and accumulate $10 of usage
  3. they cancel the feature after that
  4. we mark their feature as cancelled internally and block their access to it
  5. we mark the stripe subscription item for deletion at period end (to prevent having to clear that $10 of usage)
  6. user gets invoiced at the end of the month, pays for base sub plus $10 usage
  7. 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

next field
#

Have you attempted prorating the subscription item on delation?

crystal mist
#

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

next field
#

Yep. I'm looking to see if there's an alternative to your current approach.

crystal mist
#

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',
        }
      );```
hushed anvilBOT
next field
#

Your current approach is sound. Another approach you could take is after removing the item, you can manually create an invoice to bill for the accumulated usage.