2.03 Transfers, Merchant Payments and Fees: Exit Evidence
Evidence · Step: 2.03 Transfers, Merchant Payments and Fees
| Step | 2.03 Transfers, Merchant Payments and Fees |
| Date | 2026-11-14 |
| Database | PostgreSQL 18 (postgres:18-alpine, compose.yaml) in Docker Desktop on Windows 11 |
| Result | Passed |
Deliverables
Section titled “Deliverables”| Deliverable | Where |
|---|---|
| Payment templates | crates/ops/src/payments.rs: merchant_payment.v1, payment_request_settle.v1 |
The channel field |
mezgeb_ops::CHANNELS (qr, card_tap, phone_tap, fingerprint), required by merchant_payment.v1 |
| Template features | crates/ops/src/template.rs: optional amounts (Template::OPTIONAL_AMOUNTS, Input::optional_amount), optional roles (Role::optional), checked metadata (Template::METADATA, MetadataField) |
| Errors 2016–2020 | crates/ops/src/error.rs |
| Decision record | ADR-0014: channels are metadata; fees are lines in the payment’s own entry |
| Tests | crates/ops/tests/payments.rs |
| Documentation | payments.md (E07–E10 name their templates; the fee questions are decided), spec.md 4.6 and 4.8, the fee notes in E01–E04 and the chart |
Implementation tasks
Section titled “Implementation tasks”| Task | Done |
|---|---|
merchant_payment.v1 (payer → merchant, optional fee lines to fee revenue) |
Yes: up to three lines. Payer, merchant (the price minus any merchant_fee), and fee revenue (both fees together), with payer_fee added to what the payer pays. fee_revenue is an optional role, needed only when there is a fee |
payment_request_settle.v1 |
Yes: the same booking to a customer or a merchant, requiring the payment_request it pays (E10) |
A channel metadata field with an enumerated set |
Yes: required by merchant_payment.v1, one of qr, card_tap, phone_tap, fingerprint; refused when missing (2019) or not in the set (2020) |
| Validate that fee ≤ amount and that all lines share one currency | Yes: the fees together at most the amount (2016); every amount in one currency (2017); the posting rules then check each line’s currency against its account (1007) |
| Channel as metadata, not accounts (decide in an ADR) | Yes: ADR-0014 |
The P2P transfer was already booked by p2p_transfer.v1 (step 2.01).
Testing requirements
Section titled “Testing requirements”| Requirement | Test | Result |
|---|---|---|
| Payer-paid and merchant-paid fee variants | merchant_paid_and_payer_paid_fees |
Pass: merchant-paid (Dr 100 / Cr 98 / Cr 2), payer-paid (Dr 101.50 / Cr 100 / Cr 1.50), both together in one fee line, and a fee equal to the price (no merchant line) |
| A zero fee produces no fee line | a_zero_fee_produces_no_fee_line |
Pass: with no fee, or fees given as 0, the entry has two lines and fee revenue need not be bound; with a fee and no fee revenue, 2007 |
| Fee > amount is rejected | fees_and_amounts_are_checked |
Pass: a merchant fee, a payer fee, or both together above the amount give 2016; also a negative fee (2006), a fee in USD (2017), an amount plus fee beyond i64 (2018) and an unknown amount (2005) |
| Concurrent payments to one merchant from 100 payers: merchant total = sum of the net amounts | one_hundred_payers_one_merchant (PostgreSQL, 8 threads, 20 connections) |
Pass: all 100 post at once; the merchant holds exactly the sum of the net amounts, fee revenue exactly the sum of the fees, and the integrity report is clean |
| Each template against its worked entry | each_template_books_its_worked_entry |
Pass: the story OB–E20 is replayed with E07 (qr), E08 (card_tap), E09 (fingerprint) and E10 booked by their templates; each draft equals its table line for line |
Acceptance criteria
Section titled “Acceptance criteria”Fee revenue in the trial balance equals the sum of the fee lines.
- In the worked story: after E20, 4010 in the trial balance (3.40) equals
the fee lines posted to it, with the credits from E07–E09 and E17, less
the fees given back in E11 and E12 (
each_template_books_its_worked_entry). - Under load:
fee_revenue_equals_the_sum_of_the_fee_linesbooks 2,000 random merchant payments, from 10 payers to 4 merchants, through every channel, with merchant-paid, payer-paid, both and no fees. 4010’s balance equals the sum of its fee lines, which equals the sum of the fees requested. Each merchant is owed exactly the sum of its net amounts, and the reference ledger’s invariants hold.
Exit gate
Section titled “Exit gate”Every channel in the product list books through a template. ADR-0014
lists the product’s channels and the template that books each.
every_channel_books_through_a_template checks that:
- each merchant channel (
qr,card_tap,phone_tap,fingerprint) books throughmerchant_payment.v1, with the channel recorded on the entry; - a missing channel (2019) or any other value, such as
nfc,QRor empty (2020), is refused; - a payment request books through
payment_request_settle.v1, which refuses one without itspayment_request(2019) and can pay a customer or a merchant but never fee revenue (2010); - the P2P transfer books through
p2p_transfer.v1(step 2.01 tests).
Decisions
Section titled “Decisions”From ADR-0014:
- The channel’s allowed values are part of the template version. A new
channel is
merchant_payment.v2, because a released version never changes. - The client computes and rounds fees. The ledger only checks them.
- No fees on deposits, withdrawals or returns in this version. Step 2.02 deferred these to this step. No product charges them, so 4020 and 5020 stay reserved, and a future fee there is a new template version with a fee line.
Not done in this step
Section titled “Not done in this step”- The fee sweep from 1010 to 1020: still an open question in E07.
- Holds for card payments that are authorised first and captured later (E08 open question), and partial payment of a request (E10 open question).