#mandeep_api
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/1417635129198641275
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- mandeep_api, 2 hours ago, 43 messages
ah, this is the direct link to the previous discussion: #1417555602863030323 message
Hi there,
you are sending meter events but the customer available credits are not getting reduced, is that what you are saying? Just want to make sure we are on the same page
yes!
Can you share the invoice id where you would expect the meter events/reduced credit grants to see?
yeah:
- meter events were sent in
req_KYuvDGnbY7X6rxandreq_dcondvgReWgGjl - one of the invoices for a credit grant was
in_1S85yeJ9T5T8QujqHnCnZDOM, after it became paid my code created grantcredgr_test_61THTwBomL2NYpD8K41J9T5T8QujqBOi - I'm trying to use the "credit burndown" idea I was given in the previous channel
- price is
price_1S826QJ9T5T8QujqK9QUXkwG
๐ Changing of the guard, taking over for Vegvisir, just getting caught up.
Reading up on your prior thread
Do you have the req_id for the credit grant, or a customer_id I can review
yeah, the grant was req_h1DbeiZig4Hegd (among others, there's a few grants active), and the customer is cus_T44nAOQ0HVQsUw
other grant is req_b0GHhDtCfGSCWh
Looks like the credit grants are showing?
yeah
the issue I'm having is that the available credits doesn't seem to decrease with the metered usage
Let me look, metered usage tends to be asynchronous.
So it looks like they've racked up $3 in metered usage and 3 dollars has been applied to cover the cost so far.
hmm, that looks about right then
basically, before serving a user's request, I make a request to Stripe's credit_balance_summary endpoint to retrieve the balance, and check the available_balance field to see what they've got left. if it's <= 0, reject the request
it's that available_balance that doesn't seem to be changing? (I still get ยฃ25, rather than ยฃ22, available)
Yeah I'm wondering if it happens when the invoice finalizes. (unsure if that's the case) Appreciate your patience here.
Sorry, that took some time, to test. So it looks like it actually charges the credit balance when the invoice is finalized
I believe what you can do is set a billing_thresholds.amount_gte on the subscription itself. Whenever the threshold is passed it will charge automatically. and reset the cycle.
https://docs.stripe.com/api/subscriptions/create#create_subscription-billing_thresholds-amount_gte
Then whenever the user buys credits, you retrieve their credit balance, and then update the subscription threshold to match.
So you can avoid going negative.
would this create an invoice for every usage (every time a meter usage occurs)?
if so, I'd want to avoid that (as it may end up a bit spammy for the customer) - otherwise I think that would work?
separately, I wonder if there's a way to get the available_balance less the amount on the pending invoice not charged yet?