# Operate prepaid accounts

> Enroll metered subscriptions, fund a EUR wallet from settled bank credits and reconcile monthly spend controls with the ledger and network.


A customer tops up €20 and sets a €5 monthly spend limit. Their first €3.20 of metered usage leaves €16.80 available. Another €1.80 reaches the limit with €15 still in the wallet. If a further €0.60 of usage arrives before the network restricts service, the operator covers it.

| After posting | Available funds | Customer spend this month | Operator coverage |
|---|---:|---:|---:|
| Booked payment | €20.00 | €0.00 | €0.00 |
| First usage | €16.80 | €3.20 | €0.00 |
| Limit reached | €15.00 | €5.00 | €0.00 |
| Late usage | €15.00 | €5.00 | €0.60 |

With online charging, the customer statement distinguishes the booked balance, funds reserved for live sessions and the amount still available. A reservation protects both funds and monthly headroom. Offline rated usage can consume only the remaining headroom. When a session reports consumption, accounting posts the funded charge and releases the unused hold. A finance reversal or lower cap that would invalidate a live hold returns `prepaid.online-budget`. Reconcile the session and retry the finance command.

## Open and fund a wallet

1. Open **Konto → Prepaid-Guthaben → Prepaid einrichten** in the Desk. Select the account’s active subscriptions and the gross monthly limit. Start with a clean service month. The subscriptions share both funds and limit. billd accepts the enrollment and delivers it to accountingd.
2. Read the wallet’s RF reference under **Gebuchten Zahlungseingang zuordnen**. Give the payer that reference and the operator’s receiving IBAN. Use the structured creditor reference on the transfer.
3. Import the booked EUR credit in **Zahlungen**. Copy the **Beleg-ID** from the payment review and apply it on the account. Accounting takes the amount from the bank record and moves it from unapplied funds to the prepaid liability. Repeating the same command credits it once. [Bank statement format](../docs/payments/)
4. Use **Monatslimit ändern** for an authorized change. Enter the new limit and a reason. A top-up leaves period spend intact.

### Reverse a confirmed payment

After the bank confirms a reversal, open **Aufladung zurückbuchen** in the Desk. Through the API, finance posts the original top-up receipt with its account, the accounting business date and the reason to `POST /prepaid/reversals`. Accounting removes at most the available credit. Any difference posts to `Expenses:PrepaidChargeback` and freezes further spending. A later top-up remains available in the wallet while the review is open.

Once finance verifies the loss, use **Fehlbetrag klären** and record the decision. Through the API, read `shortfall_review` and `shortfall_cents` from the operator wallet. Send the review UUID as `id` with `account`, `shortfall_cents`, `date` and the decision's `reason` to `POST /prepaid/shortfall-resolutions`. The review closes once, with an audit entry. The cap and available funds still determine whether to release service.

## Reconcile the worked example

| Journal account | Balance from the example |
|---|---:|
| `Assets:Bank` | €20.00 debit |
| `Liabilities:Prepaid` | €15.00 credit |
| `Income:PrepaidUsage` | €5.60 credit |
| `Expenses:PrepaidExcess` | €0.60 debit |

The bank import initially credits `Liabilities:Unapplied`. Allocating the receipt transfers that credit to the wallet. The operator coverage and the customer debit together explain the gross usage journal entry. This posting profile carries gross usage in one income account. Finance selects the applicable tax posting treatment before production use.

## Read the customer statement

Serve accountingd’s `GET /prepaid/wallets/{id}/html` behind the customer portal. The portal authenticates the customer and supplies a server-side `customer:<account-uuid>` credential. Keep the Desk on the operator’s authenticated origin. The read-only statement shows funds, monthly spend, recent postings, when usage was last rated, and the latest requested and confirmed network actions. The JSON resource is available at the same path without `/html`.

billd applies the enrolled tariff and its allowances to cumulative usage for the service month. Later records can change the cumulative price. Each revision records the funding decision. Fixed recurring charges continue through invoicing. At period close, billd checks the final tariff facts and waits for the wallet receipt before sealing. A later service record or a backdated plan change produces a new wallet revision. Support can use a `read` credential for `GET /prepaid/ratings/{id}` on billd with the evidence ID from the accounting movement to see the measured records, dated plan, tariff hashes, gross rating and allocation.

## Connect the network

Use a dedicated `prepaid-oss` credential to poll accountingd’s `GET /prepaid/proposals`. Follow the account cursor for subsequent pages and resume polling from the beginning after each sweep. Pass the last returned account UUID as `?after=<uuid>` to get the next page. Persist the highest applied revision per account. Apply a proposal only to its listed chargeable subscriptions and preserve emergency access. Send `PUT /prepaid/proposals/{id}/ack` with `{"outcome":"confirmed"}` after applying the command. Use `failed` when delivery fails. A retry retains the proposal identity.

The account can have a pending release while its latest confirmed network state is restricted. The wallet page shows both. Monthly headroom renews on the operator’s Berlin billing calendar. Empty credit or an unresolved shortfall can keep the restriction in place.

## Monitor wallet postings and disputes

Read billd’s `GET /prepaid/rating-metrics` for source lag in days, pending deliveries and the 95th percentile of elapsed posting time. Inspect accountingd’s `GET /prepaid/metrics` for outstanding network commands, acknowledgement latency, exposure and bill-shock disputes. Record an independently opened dispute once with `PUT /prepaid/wallets/{id}/disputes/{case_id}`. The monthly rate divides unique cases opened in the month by all accounts enrolled by month end, then multiplies by 1,000. The report retains both counts.

Commission the OSS adapter with real restriction and release acknowledgements. Measure upstream feed delay, posting and proposal readiness, and network acknowledgement separately. The five-second target covers posting an accepted rating update and making any proposal available. Live session reservation runs through chargingd. [Online charging](../docs/online-charging/) · [3GPP charging architecture and principles, section 4.3](https://www.etsi.org/deliver/etsi_ts/132200_132299/132240/18.06.00_60/ts_132240v180600p.pdf)

The release-build workload sends one account’s usage over HTTP for 30 seconds. It exercises tariff rating, the one-second delivery worker, the accounting journal and the cap restriction. On a dedicated local PostgreSQL 17 instance, all records posted and the network proposal was ready in both runs.

| Offered updates per second | Posted | HTTP submission to accounting confirmation, p95 | Rating queue to accounting confirmation, p95 |
|---:|---:|---:|---:|
| 1 | 30 of 30 | 1.120 s | 1.078 s |
| 4 | 120 of 120 | 0.863 s | 0.828 s |

To repeat the measurement, set `TELCO_TEST_DATABASE_URL` to a PostgreSQL test administrator URL. Choose the offered rate with `TELCO_PREPAID_LOAD_PER_SECOND`. Measure operator feed delays and network acknowledgements with the live integrations.

```sh
TELCO_PREPAID_LOAD_PER_SECOND=4 cargo test --release -p billd --test prepaid prepaid_decision_latency -- --ignored --nocapture
```
