#fabry_billing-threshold

1 messages · Page 1 of 1 (latest)

proven gladeBOT
#

👋 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/1485670872374186084

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

rich briar
#

Adding more context:
Working on a SaaS with both a fixed-price usage plan product and a credits product which keep track of overuse, when overuse gets spent completely (so the current invoice bill is higher than 30€), a new cycle should start

surreal thunder
#

fabry_billing-threshold

rich briar
#

Also, I can confirm the billing threshold is correctly configured on the Stripe Dashboard

surreal thunder
#

👋 I don't really get what this means

or more is met, a new invoice does NOT get created and the current one paid correctly.

rich briar
#

Sorry, let me rephrase this:
On the current billing cycle, If I exceed 30€ (tax excl.) of usage, the invoice should be paid and the next cycle should start, but this isn't happening

surreal thunder
#

Okay, can you share how you are reproducing this? Exact code, exact example object id (Subscription id, how you reported usage, what you see on the Upcoming Invoice, etc.)

Note that usage is not aggregated in real time so it takes some time for the new Invoice to be created

rich briar
#

Sure, this is an excerpt of what I'm doing:

Stripe webhook catches "customer.subscription.created" ->
Some internal business logic -> Update stripe subscription and attach billing_thresholds: {
amount_gte: 3000,
},

In the stripe dashboard, this works fine, the event gets fired correctly:

200 /v1/subscriptions/sub_1TE9kkLZKpRE4i30oTUhjb4X

With the following POST request body:
{
"billing_thresholds": {
"amount_gte": "3000"
}
}

In the stripe dashboard, the following text gets displayed:
Soglia di fatturazione
"Il raggiungimento di un totale non addebitato pari a 30,00 € al lordo delle imposte attiverà una nuova fattura. Il periodo di fatturazione rimarrà invariato." -> "Billing Threshold
When your total outstanding balance reaches €30.00 (before taxes), a new invoice will be generated. The billing cycle will remain unchanged."

#

This is the current invoice which should trigger the next cycle:

surreal thunder
#

sorry a lot of it is in another language so hard to grasp those UIs

Are you doing all of this in Test mode? If so can you create a Subscription with billing thresholds and then report usage well over 30€ and see what happens?

rich briar
#

This is in sandbox mode, should I test in test mode?

rich briar
surreal thunder
#

really I don't need screenshots

#

I need a clear understanding of your exact code and how you reproduce each thing

rich briar
#

I can pass you the entire sub object

#

To repro, I'm using sandbox mode, with a daily subscription

surreal thunder
#

are you writing code though or doing all of this in the UI? Sorry to push, but really what I'm asking for is end to end code that does all the steps sequentially in the right order

  1. Create Sub with billing_thresholds (no need to update async)
  2. Report usage multiple times
  3. Wait for Invoice to be created
rich briar
#

Yes, I'm writing code and monitoring through the UI.

For sub creation, I don't create it, I just get a customer.subscription.created event after a checkout session is completed, then call the stripe subscription api to attach billing threshold

To report usage, I have a simple UI button that fires the metered event which gets correctly tracked in the invoice

The invoice still isn't getting created after some hours, and I've exceeded the 30€ threshold

surreal thunder
#

For sub creation, I don't create it, I just get a customer.subscription.created event after a checkout session is completed, then call the stripe subscription api to attach billing threshold
sure but you can bypass that to run an end to end test just to test billing thresholds

#

I'm looking in parallel though

surreal thunder
#

No with just code the same way you update the Subscription in your webhook handler right now

rich briar
#

This is the code which updates the sub (inside the subscription created handler)

surreal thunder
#

yeah sorry

proven gladeBOT
surreal thunder
#

I don't need a picture to be clear

#

I was hoping you could spend a few minutes writing a really simple end to end test that does all the steps, no Checkout, no webhook, no Dashboard usage. Just spending a couple minutes trying what I was explaining.

#

My gut: this just never works with MeterEvents, it's a feature for our older "usage based billing" integration via UsageRecords. But at this point let's pause and let me investigate and confirm, that'll be easier for you than all the back and forth

lucid spindle
#

fyi i'm taking over for my colleague!

surreal thunder
#

(sorry clarified, we are the ones testing and then we'll confirm)

lucid spindle
#

ok, i finished a test of this and i think you're right in that the billing threshold isn't being respected at all

#

gonna run a couple more tests to make sure it isn't a me problem

lucid spindle
#

ok yes, i've tested this a few ways now and i am pretty sure meters aren't supported for billing_thresholds currently. the best solution i can think of at the moment is to use billing alerts, which allows you to configure a webhook alert that will fire when a user hits a given threshold. once that event fires, you can update the subscription's billing cycle anchor to "now" to reset the billing cycle anchor and send an invoice. from there, you would need to create a new alert as each alert is a one-off and must be recreated after it fires.

proven gladeBOT
lucid spindle
#

ok sorry, i just tested again and this should actually work. in a few of my tests it looked like it wasn't working, but meters are a little tricky to work with alongside test clocks because they can take a while for us to aggregate them on our side

#

so what you need to do is

  1. create a customer + test clock
  2. create a subscription with a billing thresold
  3. log enough meter events to trigger the threshold
  4. wait for several minutes in real time for our system to aggregate the meter events (in my testing 5 minutes was usually long enough, but the aggregation time is variable)
  5. advance your test clock by a day or so (this should generate an invoice for the billing events aggregated so far)
  6. inspect your subscription + invoice to verify that the invoice has been generated
  7. advance your test clock one more full billing period (this should generate a $0.00 invoice)