Credits
Manage customer credit balances and apply them to invoices
Overview
Vayu uses a balance-based credit system that allows customers to pre-fund usage and apply credits over time. Credits can be added either through upfront purchases or through credit notes issued for refunds or billing adjustments.
How Credits are Added
There are two primary ways credits are added to a customer account:
- Credit Notes: When Vayu issues a credit note, the credited amount is added to the customer’s credit balance rather than refunded in cash.
- Credit Purchases: Customers can purchase credits in advance and draw down that balance as services are consumed.
Each addition of credit creates a corresponding ledger entry. Credit entries are recorded as explicit transactions and should be treated as immutable. If a correction is needed, Vayu records a separate reversing or adjustment entry rather than modifying the original transaction.
Available Balance
All credits contribute to a single available balance, which represents the total amount available to cover future charges. The balance is derived from the credit ledger as:
available balance = total credits added - total credits applied - total credits reversed or expired
The balance cannot go below zero, so credits can only be applied up to the amount currently available.
If Vayu supports multiple currencies, the balance should be maintained separately per currency, and credits should only be applied to invoices in the same currency unless explicit currency-conversion rules are defined elsewhere.
Applying Credits
Credits from the available balance can be applied to invoices in two ways:
- Manual application: A user chooses how much credit to apply to a specific invoice.
- Automatic application: Available credits are automatically applied to the next generated invoice based on configured auto-apply rules.
Credits are applied at the invoice level, not at the individual line-item level, unless explicitly stated otherwise. Partial application is supported, meaning a customer may apply only part of the available balance, and credits can only reduce an invoice up to its outstanding amount. Credits do not cause an invoice balance to become negative.
If multiple credit entries exist in the ledger, Vayu should apply them according to a defined ordering rule, such as first-in-first-out or oldest-available-first. That rule should be consistent so credit consumption can be reconciled and audited.
For automatic application, the system should define when the application occurs, for example at invoice generation or finalization, and whether it applies the full eligible balance or only up to the invoice total.
Credit Ledger
Behind the available balance, Vayu maintains a credit ledger as the system of record for all credit activity. The ledger records every credit movement, including:
- Credits added through purchases
- Credits issued through credit notes
- Credits applied to invoices
- Credit reversals or adjustments
- Credit expirations, if expiry is supported
The available balance is not stored as a standalone value, but derived from these ledger entries.
To preserve integrity, ledger operations should be written atomically and protected against concurrent double-spending. If multiple invoices or application attempts occur at the same time, the system must ensure that the same balance cannot be consumed more than once.
Invoice and Reversal Behavior
When credits are applied to an invoice, they reduce the invoice amount due before payment collection. Tax calculation should remain part of the invoicing and billing logic, not the credit ledger itself, unless Vayu explicitly models tax-inclusive credit behavior.
If an invoice is voided, regenerated, or otherwise reversed after credits have been applied, Vayu should create offsetting ledger entries that return the applied amount to the customer’s available balance when appropriate. The original ledger entries should remain in place for audit history.
Expiry and Validity
If credits expire, expiry should be represented as a separate ledger event with a clear effective date and amount. If credits do not expire, that should be stated explicitly in the product or billing policy.
This design improves reconciliation and auditability because every change in credits is recorded as an explicit transaction. It also provides a clear history of balance changes over time while keeping the user experience simple through a single available balance.

