Skip to content

feat(payments): add governed collections and disbursements - #2658

Merged
jeremi merged 40 commits into
mainfrom
feat/payments-p2g-integration
Nov 27, 2026
Merged

jeremi merged 40 commits into
mainfrom
feat/payments-p2g-integration

Conversation

@jeremi

@jeremi jeremi commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Coordinator workflows use dedicated typed steps to request a payment collection or a disbursement, wait for its named completion, and record the verified outcome. The optional Adapter payment host shares the Adapter listener and PostgreSQL infrastructure. Operator-owned connections set the tenant, biller, provider endpoints, credentials, currency policy, restricted BReg Actions and exact provider-pack pins.

What this adds

  • BReg: bill, receipt Action and issuance guard. The payment-fee-issuance example project holds the authoritative fee bill, a restricted Action that binds one payment attempt to an exact bill version, a restricted record-payment-receipt Action, and a guard that issues the paid service once and only after a confirmed receipt. The g2p-disbursement project holds approved disbursement instructions and the restricted provider-confirmation report.
  • Adapter payment host. adapter serve --payments-config mounts typed collection, disbursement, observation and reporting operations outside the generic record routes. It reserves one attempt per bill or instruction version before provider dispatch, retains the original binding, key and request bytes, and recovers lost acknowledgements from the saved command or exact readback. adapterctl payments check and adapterctl payments contract validate connections offline and export the typed HTTP contract.
  • Provider connectors. A standalone synthetic P2G connector for the payment simulator, and a Mifos Payment Hub EE disbursement profile that signs the exact Bulk request through a pinned Transit RSA key, verifies the raw acknowledgement with a separate pinned key, and reads Operations status under its own bearer credential. Provider packs map wire shapes; the host owns origins, credentials and mutation methods.
  • Coordinator payment steps. payments.request-collection/v1, payments.read-collection/v1, payments.record-receipt/v1, payments.request-disbursement/v1, payments.read-disbursement/v1 and payments.record-provider-confirmation/v1 over a payments connection, with the host-owned collection and disbursement completions. An uncertain disbursement stays held and reconciles only through the read-only original-request lookup.
  • Payment simulator hosted page. The simulator gains a hosted payment page, an optional return URL, a payer-cancelled outcome, and per-payer outcome rules that settle at request creation.

Rebase onto current main

This branch was rebased onto main (previously 134 commits behind) and the hosted-page simulator commits were added on top.

  • Main moved Adapter and Coordinator product prose to the docs site. The payment contracts this branch had written into products/adapter/CONCEPT.md and the Coordinator DEPLOYMENT.md, PRODUCT-CONTRACT.md and SECURITY-MODEL.md now live on the site pages: typed payment hosting on Configure an Adapter project, the payments connection on the Coordinator configuration reference, the payment operations on the Coordinator configure page, payment recovery on the operate page, and the security invariant on the Coordinator security model.
  • Main assigned COORDINATOR-INV-15 to the connection assertion audience, so the payment invariant is now COORDINATOR-INV-16, with operator obligation 14.
  • Main moved pkcs1 to 0.8. The Transit RSA key check now borrows the modulus through RsaPublicKeyRef, as registry-evidencectl already does.
  • Generated outputs (identifier catalogue, Adapter schemas, Coordinator schemas and OpenAPI, CLI catalogue) were regenerated from their sources rather than merged by hand.

Review notes (security-sensitive)

This change adds authorization and audit surface: restricted BReg Actions held by the Adapter reporter identity, Coordinator payment connections that carry no BReg grant, value-free payment audit events committed before effects, and durable payment attempts with no automatic expiry. The Coordinator security model page records the new invariant and operator obligation.

Verification

Local, on the rebased head:

  • cargo fmt --all --check and cargo clippy --all-targets -- -D warnings over the Adapter, payment, Coordinator, BReg, registry-platform-crypto, registry-cli-docs and registry-language-server crates.
  • cargo test over the same crates: 5,874 passed. 56 tests in registry-bregctl and registry-coordinator failed only because the local checkout sits under a group-writable parent directory, which the runtime-configuration permission check correctly refuses (platform.runtime-config.unsafe-file). CI runs them in a normal checkout.
  • bregctl check for payment-fee-issuance and g2p-disbursement (0 errors). The payment-fee-issuance native acceptance helper ran check, the bregctl test journey suite, package, plan, apply, status and the authorization probes against a disposable TLS PostgreSQL; the exact-fee-before-issuance journey passed.
  • Payment simulator: 133 tests pass under uv run pytest, and payment-simulator openapi --check is clean.
  • Adapter and Coordinator dependency-direction gates and their unit tests, the Coordinator script tests, the CI change-routing tests, the config-conventions lint, the identifier reference closure check, and the payment native-support Node tests.
  • Coordinator and Adapter generated schemas and OpenAPI match their generators.
  • Docs site source checks for the changed pages: evidence anchors, relative and draft links, frontmatter, markdownlint, Vale style, cutover, and the Coordinator tutorial dry run.

Not verified

  • Live Mifos signing and verification through a real OpenBao Transit engine. The fake Transit regression checks the wire contract only. This is a follow-up.
  • The Mifos record-receipt operation stays withheld: Mifos Operations completion is a provider report and does not authorize a paid fee-bill receipt.
  • Collection bindings require simulation: true; no live collection provider is supported yet.
  • Beneficiary credit and settlement need their own verification contract.
  • The g2p-disbursement BReg journeys were not run against PostgreSQL locally; only bregctl check ran.

@jeremi
jeremi force-pushed the feat/payments-p2g-integration branch from 8ede031 to 33dabfb Compare November 12, 2026 21:32
@jeremi jeremi changed the title feat: add native payment collections and guarded bill receipts feat(payments): add governed collections and disbursements Nov 12, 2026
@jeremi
jeremi force-pushed the feat/payments-p2g-integration branch from 4da0fd9 to 58040ed Compare November 19, 2026 21:11
@jeremi jeremi added the ci:full Run the heavy integration tier on this pull request label Nov 19, 2026
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
…cess

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Main moved pkcs1 to 0.8, whose owned RsaPublicKey is generic over its integer type. Borrow the modulus through RsaPublicKeyRef, as registry-evidencectl does.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
…he simulator

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
…ules

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
A request whose payer has a configured outcome stayed pending until the worker advanced it, so a fast click on the hosted page could decide it first. The rule now settles the request when it is created.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Main moved Adapter and Coordinator product prose out of products/ and
into the docs site. Carry the payment contracts this branch had written
into the removed CONCEPT, DEPLOYMENT, PRODUCT-CONTRACT and SECURITY-MODEL
files to their site pages: typed payment hosting on the Adapter configure
page, the payments connection on the Coordinator configuration reference,
the six payment operations and their completions on the Coordinator
configure page, payment recovery on the operate page, and the payment
invariant (now COORDINATOR-INV-16, since main assigned INV-15) with its
operator obligation on the security page.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The payment provider pack schema still carried references to the removed Adapter concept document; regenerate it and the identifier catalogue digests from their sources.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Collections are simulation-only, as the payment-collections contract
states. A collection binding is accepted only with the simulator
provider and simulation: true; a Mifos or mapped HTTP collection, or a
simulator binding with simulation: false, is refused with
adapter.payment.collection-simulation-only by both adapter serve and
adapterctl payments check. The generated payments schema fixes
simulation to true.

The Mifos and HTTP collection branches in the router and request path
stay for a follow-up; no new connection can reach them. Service and
authoring tests that ran live collections now assert the refusal, and
the provider-pack pin tests use pinned simulator collections.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
…ction

The simulator reports a cancel on its hosted page, or a cancelled payer rule, as RJC/FAILED with failureReason payer-cancelled. The connector refused that pairing as a protocol error, holding the collection. Map it to CollectionState::Failed like payer-rejected. The tests use a status body captured from the simulator for a cancelled payer rule, decoded directly and through SimulatorClient.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Startup checks the adapter_g2p tables when disbursements are configured; the payment example listed only the collection grants.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The mifos-payment-hub pack is not in this repository or published yet. Say the operator supplies a reviewed pack matching the pin, and show --payment-provider-pack on adapter serve in the example and on the Adapter configure page.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Only the collection example runs against the simulator. The disbursement example is checked and tested with coordinatorctl scenarios; no simulator pack or Adapter example backs its connection.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The changelog and example limits read as if no live provider ships. Add the disbursement entry (operations, provider packs, --payment-provider-pack, bearer and mifos-legacy-signature authentication), say live collection providers where collections are meant, and state that live Mifos signing through a real Transit engine is unverified, so a live disbursement must not move real money until that follow-up lands.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Starting the same workflow again with the same bill or instruction identity reattaches to the version's existing attempt, and record-receipt returns a receipt already recorded. A declined, cancelled or expired collection, or a failed disbursement, keeps the version bound to its attempt; a new version is the way to try again.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
retry-same on a held payments.request-disbursement/v1 told the operator to inspect or cancel, although the operation offers a read-only original-request lookup. When the operation supports a read receipt, the refusal now names reconcile; unkeyed mutations and evaluations keep their advice. The mutation-uncertain problem detail covers both cases.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The collection and disbursement request and request-receipt handlers audited a successful release with no attempt, stored as the nil UUID. Pass the accepted collection or disbursement id; refusals still carry none.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
List the four disbursement routes in the payment contract. Say the simulator upgrades v1 and v2 state to v3, and that its hosted page is a standalone aid the Adapter and Coordinator do not reach yet. Add one set-up paragraph to the Adapter configure page: Transit custody (a non-exportable service-created signer, an imported public verifier), the Payment Hub EE channel and operations apps shipping with authorisation off, and draining Bound attempts before raising min_encryption_version.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The service-issuer profile could read the payer identity, payer financial address, payment attempt, provider binding and reference, and digests. Issuance guards only the bill identity, tariff, amount, currency, simulation flag, payment state and receipt identifier; keep those and the issuance identifier.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Carry the simulation-only payments schema digest and the revised mutation-uncertain problem detail.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
@jeremi
jeremi force-pushed the feat/payments-p2g-integration branch from e67ddf2 to ca05ea8 Compare November 26, 2026 20:28
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
@jeremi
jeremi marked this pull request as ready for review November 26, 2026 23:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T23:37:53.769370Z 0e46e14 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jeremi
jeremi added this pull request to the merge queue Nov 26, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e46e149af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

|| observation.money.minor_units != self.provider_intent.money.minor_units
|| observation.money.currency != self.provider_intent.money.currency
|| observation.money.scale != self.provider_intent.money.scale
|| !text(&observation.provider_reference, 512)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce the public reference bound before retaining confirmation

If a provider mapping returns a confirmed observation with a 129–512-byte reference, this check accepts it and record_observation persists the attempt as terminal ProviderConfirmed. However, DisbursementStatus::validate limits provider references to 128 bytes, so the HTTP status conversion subsequently returns adapter.payment.unavailable. Later status requests skip provider observation for terminal attempts, leaving this disbursement permanently unreadable through the API; the supplied BReg reporting contract also limits the reference to 128 characters. Enforce the downstream bound before persisting the terminal observation so an invalid mapped reference cannot strand the attempt.

Useful? React with 👍 / 👎.


fn canonical_registry_origin(value: &str) -> Result<String, G2pError> {
url::Url::parse(value)
.map(|url| url.origin().ascii_serialization())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the registry deployment prefix in its source namespace

When two independent BReg deployments are exposed under different prefixes on the same HTTPS origin, such as /registry-a/ and /registry-b/, this normalization gives them the same source namespace whenever their record route and type match. The BReg client preserves those prefixes when making requests, so these are distinct authoritative sources. If they contain the same instruction UUID/version, find_instruction or the unique constraints in G2pStore::reserve treat the second deployment's instruction as an existing attempt and reject its disbursement with a conflict. Include the normalized deployment prefix in the namespace while continuing to ignore credential and access-profile rotation.

Useful? React with 👍 / 👎.

Merged via the queue into main with commit cd83550 Nov 27, 2026
79 checks passed
@jeremi
jeremi deleted the feat/payments-p2g-integration branch November 27, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Run the heavy integration tier on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants