Overview
Wallets provide a prepaid credit system for customers. Credits can be granted manually or automatically, and are consumed during invoice finalization to reduce the amount due.Wallet lifecycle
Create a wallet
Key fields
| Field | Description |
|---|---|
rate_amount | Conversion rate: balance_cents = credits × rate_amount × 100. Default: 1.0 (1 credit = $1) |
priority | Consumption order (1–50, lower = consumed first) |
initial_granted_credits | Credits to grant immediately on creation |
expiration_at | Optional expiration date |
code | Optional unique code per customer |
Top up credits
Sources
| Source | Description |
|---|---|
manual | Manually granted by admin |
interval | Automatically granted on a recurring schedule |
threshold | Granted when usage crosses a threshold |
inbound wallet transaction and increases the wallet balance.
Credit consumption
When an invoice is finalized, wallet credits are consumed automatically:- Active, non-expired wallets are sorted by priority (ascending), then by creation date
- For each wallet, the consumable amount is
min(wallet.balance, remaining_invoice_amount) - An
outboundwallet transaction is created - An
InvoiceSettlementrecord links the consumption to the invoice - The process continues until the invoice is fully covered or no wallets remain
Example
A customer has two wallets:| Wallet | Priority | Balance |
|---|---|---|
| Promo Credits | 1 | $25.00 |
| Main Credits | 2 | $100.00 |
- Promo Credits consumed: 0.00)
- Main Credits consumed: 85.00)
- Invoice
prepaid_credit_amount: $40.00
Terminate a wallet
terminated. Remaining balance is forfeited.
Expiration
Wallets with anexpiration_at date are automatically terminated by a background task when the expiration date passes. The check_expired_wallets task handles this.
Wallet transactions
List all transactions for a wallet:Transaction types
| Type | Direction | Description |
|---|---|---|
inbound | Credit | Top-up or grant |
outbound | Debit | Consumption against invoice |
Transaction statuses
| Status | Description |
|---|---|
granted | Credits granted |
purchased | Credits purchased |
voided | Transaction voided |
invoiced | Linked to an invoice |
API endpoints
| Method | Path | Description |
|---|---|---|
POST | /v1/wallets | Create a wallet |
GET | /v1/wallets | List wallets |
GET | /v1/wallets/{id} | Get wallet details |
PUT | /v1/wallets/{id} | Update wallet (name, expiration, priority) |
DELETE | /v1/wallets/{id} | Terminate a wallet |
POST | /v1/wallets/{id}/top_up | Add credits |
GET | /v1/wallets/{id}/transactions | List transactions |