How do you update a Stripe customer's usage record at the end of a billing cycle?

Viewed 902

For a metered pricing plan, rather than running a daily cron to create usage records for every customer, I'm listening for the invoice.created event triggered at the end of a billing cycle and updating the invoice with metered usage.

Unfortunately, I can't add a usage record because ERROR: Cannot create the usage record with this timestamp because timestamps must be after the subscription's last invoice period (or current period start time). So I have to manually create a new line item instead of using the pricing plan.

It would be great if usage records created during the draft period of an invoice could be added to that billing cycle. Is that possible? I imagine it would save Stripe a massive amount of api hits if it were. Is there another webhook right before an invoice gets created I can hook into?

0 Answers
Related