#phillip_ubb-upcoming
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/1291091152690352190
๐ 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.
- phillip_code, 6 hours ago, 22 messages
Hello @compact haven , let me know if my question is clear. Basically I'd like to know how to add the value for the usage just right before the amount gets charged.
phillip_ubb-upcoming
@stark hare that will work but the "problem" you might have is that the Event is sent a while before the Subscription's period end (default of 3 days) so you might miss some reporting. If that's okay with you then your approach sounds fine
3 days would be too early. Is there a way to set it to 2-3min before? Or somehow stop the charge event, set the value, and after it has been set by my function, continue with charging the credit card?
No that's impossible. If we did 2/3 minutes before then any delay or downtime on your end would lead to no payment that entire cycle
Now if you use our MeterEvents API you can report usage when the Invoice is already created. See https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage#add-usage-to-invoices-in-draft-state
would that fit your needs?
This is a lot of information to take in and I'm not quite sure how this is supposed to work.
Am I understanding it correctly?
- Implement a webhook whenever an invoice was created in draft status
- Then, add the usage
- Then, finalize the invoice and charge the credit card
Yep! sorry that's really the same as what you planned to do with invoice.upcoming, just you would listen to invoice.created instead and react accordingly to add the right usage
Gotcha. So this means I would listen to the invoice.created webhook. I assume this webhook will return the drafted invoice with an invoice ID.
Then, I probably have to call
await stripe.invoices.finalizeInvoice('in_1MtGmCLkdIwHu7ix6PgS6g8S'); and I would pass amount_due?
I'm unsure how this is supposed to work. Because I have set up a meter for the usage billing. Not sure how to properly set the value
You listen for invoice.created yes. Then you report usage usually that means creating a MeterEvent with the right information. You don't configure any amount due yourself no
https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage-api
Sorry I kinda assumed you already were familiar with all that based on your question but this doc explains how you do this
Ah, got it! This makes perfectly sense. I think I have all the right information for now.
Thanks for steering me in the right direction ๐