MONEY

Payments that explain themselves

The ledger decides why a payment failed. The model only explains.

Role
Sole developer (39 of 39 commits), personal project
Context
Personal
When
since Aug 2026
Status
In progress, runs locally (Docker), checked 26 Nov 2026
Reading time
5 min read

Mine: product thesis and spec; architecture of both services; integration debugging before and after the first full boot (28 follow-up commits, 25 of them fixes, 28-29 Aug 2026)

Built with: Java 21, Spring Boot, Kafka, Temporal, PostgreSQL, Redis, Python (FastAPI, Pydantic), Next.js, React 19, TypeScript, Gemini, Docker Compose

Personal project, built on my own time; not affiliated with my employer.

The number 9, labelled as a count of rules that check every model answer, beside the grounding diagram: a failed payment goes to rules first, the model drafts only if none fits, then gate G4 and the other rules stand between its draft and the explanation.

At a glance

  • ExplainerPay: explains one payment, hop by hop
  • Laserpay: keeps dispute evidence ready from the sale
  • The model writes slots; the ledger writes figures
Grounding rules checked before output is believed
9 rules (G1-G9)
COUNT G4 is designed to reject any digit the model writes
Source: GroundingController.java, the G1-G9 list, at c3e4708, checked 26 Nov 2026
Integration tests across 8 classes
70 tests
COUNT run against the compose Postgres; no CI run
Source: ExplainerPay test classes at c3e47086, counted from the source, checked 26 Nov 2026
Automated tests green in CI
580+ tests
COUNT 584 test methods (435 Java, 149 Python), all green in CI run 33241337543
Source: Laserpay CI run 33241337543, test counts from the job logs, checked 26 Nov 2026

The problem

When a payment fails, stalls or settles short, someone has to say why. The usual answers are a bare response code or a model asked to read the logs. A code is honest but hard to read. A model reads well and can be wrong about money, which is the one thing it must not get wrong.

I wanted payments that explain themselves. Every figure comes from the ledger, every cause comes from a closed list, and a model speaks only where the record is truly ambiguous. Two projects build on that idea. ExplainerPay, which I am still building, explains a single payment. Laserpay keeps the evidence for a future dispute ready from the moment of sale.

What I built

ExplainerPay follows each payment hop by hop: intent, switch, both banks, settlement, payout and reconciliation. A payment that fails, or succeeds in a way that does not reconcile, owes an explanation, and a debt queue shows what is still owed. The explanation is written three times, for the merchant, for support and for an engineer. A response code or a rule pays most of that debt. The model is called only when nothing fits, and it may not write a number. It names slots such as {amount_1}, and the ledger fills them.[3]

Grounding: nine rules before an answer is believed. Rules explain most failed payments without a model. When none fits, the model writes slots instead of figures, and G1-G9 check its answer before anyone reads it.

G4: model wrote a digit → rejected

Solid: rules · Dashed fence: model · Diamond: gate · Cyan: data

How it flows

  1. A failed payment arrives as hops on the ledger, each with its stage, response code and reference.
  2. A response code or a rule explains it first, and most sample payments stop here without a model call.
  3. Only when nothing fits does the model read the record. It is told to name slots such as {amount_1} instead of typing a figure.
  4. G4 reads every claim and rendering before any claim is checked. A single digit rejects the whole response, which is logged with its payload.
  5. The other eight rules check each claim. Citations must resolve to this payment, slots to typed fields, and the cause to a closed list; weak claims are dropped or downgraded.
  6. Surviving claims get their slots filled from the ledger, so every figure a reader sees comes from the record, never from the model.

Nine grounding rules, G1 to G9, check every answer before any of it is believed.[1] G4 is the strictest. By design, it reads everything the model wrote, and one literal digit outside a slot or a citation rejects the whole response.[2] The model runs in its own service with no database credentials, so anyone can check that it cannot touch the ledger by reading one compose file.[5]

Laserpay applies the same split to disputes. Every event is normalised and folded into a readiness score for its transaction, a closed-form function with no model in it. Gap and contradiction checks find the cases that might need defending. Admission control then decides which few may reach the model, and a safety gate checks its answer before anything acts on it.[9][10]

Laserpay: the two-speed funnel. Every event takes the cheap deterministic path. Only a case the rules cannot settle may reach the model, and its answer must pass a safety gate.

Solid: rules · Dashed fence: model · Diamond: gate · Cyan: data

How it flows

  1. Every event is normalised and folded into a readiness score for its transaction. The score is a closed-form function, so the same inputs give the same integer every time.
  2. Gap and contradiction checks pick out the cases that might need defending. Still no model.
  3. Admission control scores money at stake, deadline, ambiguity and confidence. Only a case scoring 55 or more, within budget, reaches the model, and three kinds of case skip it entirely.
  4. The model investigates through read-only tools and must return a schema-checked answer that cites its evidence.
  5. A safety gate applies seven rules, such as every cited evidence id existing in Postgres, before any answer is acted on.
  6. When the gate says no, a person reviews the case. Model spend follows ambiguity, not event volume.

Key decisions

Ban digits in model output

Alternative rejected
Let the model write amounts and verify them afterwards
Why
Verifying a typed figure means trusting a parser to catch a wrong one. A flat ban leaves nothing to argue about at the margin, and the ledger fills every slot.

Name causes only from a closed list

Alternative rejected
Let the model describe any cause it likes
Why
A free-text cause cannot be scored or checked. The list keeps an UNDETERMINED entry, so a model that cannot tell abstains instead of picking the nearest neighbour.

Ration the model with admission control

Alternative rejected
Send every disputed case to the model
Why
Most cases are not ambiguous. A priority score and a budget tie model spend to ambiguity, and a case starved by the budget escalates to a person instead of failing quietly.

The rule paths follow the same discipline. Their per-cause templates write slots too, so a figure in a rule-written explanation comes from the ledger exactly as it does on the model path.

The closed list was tested on purpose. With the correct cause removed from the list, the two model-path payments abstained instead of grabbing a tempting neighbour.[6] An abstention still does not pay the debt. “Cannot be determined” is the right answer when the record cannot separate two causes, but the money is still unexplained, so the payment stays on the queue for a person.

How it was proven

ExplainerPay has 70 integration tests across 8 classes, run against the Postgres in its compose stack.[4] They never call a live model. The model client is stubbed, because an assertion that costs money and can fail for reasons outside the code proves nothing. Thirteen cover the grounding validator, including G4 rejecting a whole response for one literal number, timestamp or reference. Another asserts that 12 of the 15 sample payments resolve with no model call at all.[3] ExplainerPay has no CI, so I cite its test directory at a fixed commit, never a run.

Laserpay’s CI run 33241337543 passed on 29 Aug 2026 at commit f5bb5a5. It ran 505 backend unit tests across 11 Maven modules, 9 backend integration tests and 161 Python tests, with no failures.[7] The source holds 584 test methods: 435 in Java and 149 in Python.[8] The model boundary is checkable here too: Laserpay’s model service gets no Postgres credentials, and its tool registry refuses any tool that is not a read-only GET.[10]

Getting Laserpay to boot end to end took 28 follow-up commits on 28 and 29 Aug 2026, 25 of them fixes.[13] The bugs were the instructive kind. A Redis dedupe key was shared across consumer groups, so one consumer skipped work meant for another. A race in the state builder lost whole batches until its consumers were serialised.

The record itself is built to be checked. Laserpay writes an audit event at every step into a chain per merchant, where each entry stores the hash of the one before. A changed entry shows up when the chain is recomputed.[11] Ten architecture decision records explain the larger choices, from integer minor units for money to a mock model provider as the default in development.[14]

Outcomes

This is work in progress, and everything here describes the code as it stands today. Both systems run locally in Docker. ExplainerPay boots as four containers: Postgres, the Java API, the model service and the console. Its 15 sample payments split the way the design intends. Two clean successes owe nothing, two are explained by their response code and eight by a rule. Two more reach the model as marked hypotheses, and one is built to end in an abstention that leaves its debt open.

Laserpay’s sketch of the funnel reads 10⁷ events → 1 human escalation, an illustrative design target, not a measurement.[12] What the code does today is count every admission decision, so the claim can be measured once it runs at volume.[9]

Neither project has met real payments or real users. Every figure on this page comes from sample data, tests or CI.

Limitations and what I’d change

  • G4 has one edge case I am fixing now. A regex escape in its Java citation mask is wrong, so a citation such as hop:4 counts as a written figure, and an answer that cites a hop is rejected whole.[2] It fails closed: it throws good answers away and never lets a figure through.
  • The model is not reproducible across fresh runs, even at temperature zero with a fixed schema. I would score each case over several runs before trusting a cached answer.
  • ExplainerPay’s tests run only on my machine, against its compose stack. I would add a CI job that boots the stack and runs them on every push.

Credits and permissions

My own project.

Personal project, built on my own time; not affiliated with my employer.

  1. GroundingController.java, the G1-G9 list, at c3e4708, checked 26 Nov 2026
  2. GroundingValidator.java, G4 and the citation mask, at c3e4708, checked 26 Nov 2026
  3. ExplanationPipelineTest.java, 12 of 15 without a model call, at c3e4708, checked 26 Nov 2026
  4. ExplainerPay integration tests, 70 in 8 classes, at c3e4708, checked 26 Nov 2026
  5. ExplainerPay docker-compose.yml, the model service without database credentials, at c3e4708, checked 26 Nov 2026
  6. ExplainerPay context.md, the closed cause list tested, at c3e4708, checked 26 Nov 2026
  7. Laserpay CI run 33241337543, 29 Aug 2026, test counts from the job logs, checked 26 Nov 2026
  8. Laserpay test methods in the source at f5bb5a5, checked 26 Nov 2026
  9. Laserpay ADR 0009, admission control, at f5bb5a5, checked 26 Nov 2026
  10. Laserpay context.md, the model boundary and the seven safety rules, at f5bb5a5, checked 26 Nov 2026
  11. Laserpay V8__audit.sql, the hash-chained audit log, at f5bb5a5, checked 26 Nov 2026
  12. Laserpay README, the two-speed sketch (illustrative), at f5bb5a5, checked 26 Nov 2026
  13. Laserpay commit list at f5bb5a5, 27-29 Aug 2026 (IST), checked 26 Nov 2026
  14. Laserpay ADRs 0001-0010 and its 12 Maven modules, at f5bb5a5, checked 26 Nov 2026

Contact

Have a project?

Open to a small amount of freelance work: AI features, internal tools and web apps for small teams. Tell me what you're building, who it's for and when you need it.

Write to me →