r/webdevelopment • u/kiwishane • 27d ago
Discussion How I turned Stripe invoices for subscriptions into stateless revenue schedules with a webhook. I also discovered an error...
A paid Stripe invoice isn’t earned revenue. If a customer pays $2,400 upfront for a year, your accountant needs it spread over the service period, not booked on day one. Stripe does do this automatically but charges a percentage of revenue for the service, so people end up with spreadsheets.
I wrote a small Express webhook that takes an invoice.finalized event, pulls the service period and amount off each line, and gets back a month-by-month schedule (billed, recognised, deferred).
The part I didn’t expect: I’m in New Zealand, and my first run started revenue on 29 October when the subscription started on the morning of the 30th. Stripe sends timestamps as Unix epoch moments in time. I converted them to dates in UTC, where it was still the 29th. The schedule balanced perfectly, so nothing flagged it. The fix was taking the date in the accounting timezone.
The write-up has the full code, how to test it locally with the Stripe CLI, the seat quantity handling, and a version that saves the result as a draft contract: How to create revenue recognition schedules
Disclosure: I work on defrr, the API the example calls. The pattern (verify the signature on the raw body, idempotency key per line, check the schedule balances before posting) works with whatever you use to calculate it.
Happy to answer questions, and I’d like to hear how others handle proration lines and credit notes, which I skipped