Case study

A billing platform for SaaS

Subscriptions, plans and automatic charges with precise money accounting and idempotent jobs.

Year
2024
Client
SaaS product (B2B)
Role
Senior Backend Developer
A

Description

The billing platform manages the subscriptions of a SaaS product: pricing plans, trial periods, upgrades and downgrades with proportional recalculation, automatic renewals, invoices and closing documents. I implemented it in Laravel with strict money accounting in integer minor units and calculations via bcmath, eliminating any rounding errors. Automatic charges and renewals are performed by idempotent queued jobs designed for retries: each operation is protected by a unique key and a status check so that a customer is never charged twice. The scheduler forms charges daily and triggers renewals with overlap protection. All subscription state transitions are logged for auditing, and the integration with the payment provider is built on webhooks with deduplication. PostgreSQL stores the data with a thought-out schema and integrity constraints that guarantee the consistency of financial records.

Task

The in-house billing allowed rounding errors during proportional recalculation, sometimes charged customers twice during failures, and provided no transparent history of charges for support and accounting.

Solution

I moved all monetary calculations to integer minor units and bcmath, made charges idempotent queued jobs with deduplication, added a state-transition log and automatic generation of charges via the scheduler.

Results

Rounding errors and double charges were eliminated entirely, billing disputes dropped by 70%, the monthly close for accounting became twice as fast, and the platform serves over 12,000 active subscriptions.

Technologies