#Amar
1 messages · Page 1 of 1 (latest)
The easiest way to do this would be to use Stripe's subscription schedules: https://stripe.com/docs/billing/subscriptions/subscription-schedules
That way you can define how we should change your subscriptions and when ahead of time and we will change them automatically and right on time
If you want to do this yourself, you can listen to invoice.created events and can edit these invoices for up to an hour after they have been created
Thanks Pompey
But if I update the invoice after receiving the invoice created event, that won't update the subscription quantity will it?
My apologies, I misspoke. You can update the subscription itself in this hour. That being said the subscription schedule would be a way better way to do this
With the schedule you wouldn't have to time things like this. You could just set the subscription items that you want as soon as you know you want them on the next bill
Ah but I won't know the quantity
So the job runs, it does a calculation based on a database query to output a quantity of consumption
Then I need to update the users subscription + subsequent invoice to change the line item quantity to that ca;culated quantity
this will change every month
So I can't do it with schedules
What would be the best approach to take, with this new information?
Have you looked in to our usage-based billing offerings? It sounds like that may be a good match for what you are trying to do https://stripe.com/docs/billing/subscriptions/usage-based
You could report usage throughout the month and we could calculate total usage automatically
I did look at that, but i dont need to report throughout the month
I just need to work it out once
Also, this gets reset every month, whereas I would need a persistent quantity as the usage is rolling
Gotcha, in that case I believe you can listen for the invoice.created event and make your updates to the subscription then
And this will update the invoice in real time?
I believe so but the server is a bit too busy to test. Have you tested making updates like this? Would be a quick way to determine if this fits your needs
Also definitely use test clocks when testing this kind of thing. Allows you to simulate time passing rather than actual waiting https://stripe.com/docs/billing/testing/test-clocks
I dont think updates a created invoice
I tried in the portal and it said this would update the next invoice in 1 month, not the current created invoice
Good point, I think I was thinking of another flow. For this you can listen to the invoice.upcoming event https://stripe.com/docs/api/events/types#event_types-invoice.upcoming