#mandeep_api

1 messages ยท Page 1 of 1 (latest)

toxic ginkgoBOT
#

๐Ÿ‘‹ 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.

weary pier
toxic ginkgoBOT
sweet sparrow
#

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

weary pier
#

yes!

sweet sparrow
#

Can you share the invoice id where you would expect the meter events/reduced credit grants to see?

weary pier
#

yeah:

  • meter events were sent in req_KYuvDGnbY7X6rx and req_dcondvgReWgGjl
  • one of the invoices for a credit grant was in_1S85yeJ9T5T8QujqHnCnZDOM, after it became paid my code created grant credgr_test_61THTwBomL2NYpD8K41J9T5T8QujqBOi
  • I'm trying to use the "credit burndown" idea I was given in the previous channel
  • price is price_1S826QJ9T5T8QujqK9QUXkwG
manic lichen
#

๐Ÿ‘‹ 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

weary pier
#

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

weary pier
#

yeah

#

the issue I'm having is that the available credits doesn't seem to decrease with the metered usage

manic lichen
#

Let me look, metered usage tends to be asynchronous.

weary pier
#

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)

manic lichen
#

Yeah I'm wondering if it happens when the invoice finalizes. (unsure if that's the case) Appreciate your patience here.

manic lichen
#

Sorry, that took some time, to test. So it looks like it actually charges the credit balance when the invoice is finalized

#

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.

toxic ginkgoBOT
weary pier
#

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?

dry shale
#

๐Ÿ‘‹ taking over here

#

No shouldn't create Invoice per each every usage. Recommend to test this thoroughly, though.