GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — registry-stack/tools/payment-simulator at main · registrystack/registry-stack

Expand file tree

/

payment-simulator

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

payment-simulator

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
contracts
contracts
 
 
examples
examples
 
 
src/payment_simulator
src/payment_simulator
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
CONTRACT-TESTS.md
CONTRACT-TESTS.md
 
 
DEFINITION-OF-DONE.md
DEFINITION-OF-DONE.md
 
 
P2G-SPEC.md
P2G-SPEC.md
 
 
README.md
README.md
 
 
SCENARIOS.md
SCENARIOS.md
 
 
SPEC.md
SPEC.md
 
 
pyproject.toml
pyproject.toml
 
 
uv.lock
uv.lock
 
 

README.md

Outline

Payment simulator

A small Python service for developing programmes and workflows against GovStack-aligned payment interfaces. Its five G2P APIs register, update and look up beneficiary mappings, submit a payment batch, and read its instruction results. Two P2G APIs request a citizen payment and read collection status. It uses synthetic data and never moves money.

Not for production

This is a synthetic test double. It never moves money, and nothing it returns, including a PAID status or a PaymentReferenceID, is evidence that a payment happened. Every response carries X-Payment-Simulator: synthetic, payment references start with SIM-, and serve refuses a non-loopback --host unless you pass --allow-network. SQLite is fine here because this is a test double; Registry Stack's production stores are PostgreSQL. Never point a programme at it as a real payment service.

FastAPI and Pydantic own the HTTP shapes. SQLite keeps accepted commands, destination snapshots, replay responses and simulated credits across restarts. Amounts use exact minor units. Everything stays in this directory, with no Registry Stack runtime imports or Rust build.

The maintained P2G integration uses the Adapter payment host and native Coordinator payment operations. The host owns provider correlation, durable attempts, recovery and restricted registry receipt reporting. The simulator's HTTP profile also remains independently usable for connector tests.

The Coordinator's generic external.get/v1 and external.command/v1 operations cannot call these seven APIs as written. They send only a bearer token, Accept, Content-Type and, for a command, Idempotency-Key, while every API here requires a tenant header (Platform-TenantId for G2P, X-Platform-TenantId for P2G). A command also POSTs one JSON object to one exact path with no query string, there is no PUT, and GET /transferRequests/{transferRequestId} has a path parameter. A compatible service can replace this simulator for new work after existing commands have settled.

Start locally

Install uv and use Python 3.11–3.14. From this directory (tools/payment-simulator; from the repository root, prefix each command with uv --directory tools/payment-simulator), install the locked dependencies and create a private local token:

uv sync --locked
uv run python - <<'PY'
import os, secrets
from pathlib import Path
os.umask(0o077)
Path(".state").mkdir(exist_ok=True)
with Path(".state/token").open("x") as token:
    token.write(secrets.token_urlsafe(32) + "\n")
PY
uv run payment-simulator serve \
  --database .state/payments.sqlite --token-file .state/token

Create the token once. On later starts, reuse it and the same database. The server binds to 127.0.0.1:8008, advances instructions automatically, and serves its OpenAPI at /openapi.json and interactive documentation at /docs. The token is read on every request, so replacing its contents rotates the credential while preserving the producer identity and replay records. An existing version 1 or 2 database is upgraded to version 3 in one additive transaction when the server starts, preserving its G2P records, credits and collection requests.

In another terminal in this directory:

uv run python examples/quickstart.py --token-file .state/token
uv run payment-simulator inspect --database .state/payments.sqlite

The example exercises all five APIs, updates one destination, submits two instructions totaling 250 USD, replays the same submission, and polls until both report ACCC. It prints outcome: completed and sameBatchOnReplay: true. The local ledger shows two simulated credits. Stop the server with Ctrl-C, restart it with the same command, and rerun the example. It recovers the same batch and adds no credits.

Use --run-id other only for a deliberately new batch (at most six lowercase letters/digits). An uncertain submission must retain its original IDs.

Control outcomes

Local CLI controls affect future acceptance. They are not public HTTP APIs. All controls need the same database path as the server.

uv run payment-simulator scenario --database .state/payments.sqlite \
  --name partial --reject-request pay2-part
uv run python examples/quickstart.py --token-file .state/token \
  --run-id part --expect partial
uv run payment-simulator scenario --database .state/payments.sqlite --name success

The partial fixture rejects the named instruction with account-rejected; other valid instructions succeed. A missing mapping always finishes as RJCT with mapping-not-found, even if the mapping is added after acceptance. Updating a mapping affects future batches, not accepted destinations.

For deterministic steps, start serve with --manual. Each command below moves existing instructions once: PDNG to ACSP, then ACCC or RJCT. Use --steps 2 to finish both transitions.

uv run payment-simulator advance --database .state/payments.sqlite

The lost-response scenario lives in the test fixture: a relay observes a committed 202, disconnects before the client receives it, then restarts the service and retries the unchanged command. There is no HTTP fault switch.

Collect a citizen payment

With the same server running in automatic mode:

uv run python examples/collect_payment.py --token-file .state/token
uv run payment-simulator inspect-collections --database .state/payments.sqlite

This requests a synthetic 25.50 USD fee, replays the command, and polls until paymentStatus is PAID with a stable PaymentReferenceID. Rerunning the same example after restart recovers the same request and payment reference.

The new public operations are POST /rtpRequest and GET /transferRequests/{transferRequestId}. P2G preserves its upstream X-Platform-TenantId and X-billerId headers. See the P2G profile for the exact shapes, scope and reviewed differences from GovStack.

An RTP status of COM does not mean paid. The mock deliberately passes through COM/PENDING before COM/PAID. Consumers must validate the payment status, original IDs, amount, currency and confirmed payment reference.

Choose other outcomes for future requests:

uv run payment-simulator collection-scenario --database .state/payments.sqlite --outcome failed
uv run python examples/collect_payment.py --token-file .state/token --run-id reject --expect failed
uv run payment-simulator collection-scenario --database .state/payments.sqlite --outcome expired
uv run python examples/collect_payment.py --token-file .state/token --run-id expire --expect expired
uv run payment-simulator collection-scenario --database .state/payments.sqlite --outcome paid

Use --outcome cancelled for a payer who cancels: it reports RJC/FAILED with failureReason: payer-cancelled. To make one named test person always decline, map their payerFiDetails.financialAddress to an outcome. A payer rule beats the biller's scenario and the hosted page: the request is final as soon as it is created, and the page only shows the result. --remove deletes the rule:

uv run payment-simulator payer-outcome --database .state/payments.sqlite \
  --address citizen-decline --outcome failed
uv run payment-simulator payer-outcome --database .state/payments.sqlite \
  --address citizen-decline --remove

Each run ID here represents a different synthetic bill. The profile allows one request per bill, including failed and expired requests; it has no reissue or refund policy. Keep the original run ID when recovering an uncertain payment. Expiry is a fixture outcome, not a configured real-time deadline. In manual mode, the existing advance command advances both G2P and P2G in two steps.

Send a citizen to pay

A citizen-facing front end can hand the citizen to a hosted page and get them back. The hosted page is a standalone aid for such a front end: the Adapter payment host and Coordinator do not reach it yet. The Adapter creates requests without X-Return-URL and polls them. Start serve with the front end's return URL, then add X-Return-URL to POST /rtpRequest:

uv run payment-simulator serve --database .state/payments.sqlite \
  --token-file .state/token --return-url https://portal.example.test/paid

Send the citizen to GET /pay/{transferRequestId} on the simulator's origin. The page shows a "Synthetic payment simulator, no real money" banner, the biller, bill and amount, and three buttons: Pay, Decline and Cancel. The browser posts the choice back, and the simulator answers 303 to the return URL with transferRequestId and status (paid, failed or cancelled) added to its query. Without a return URL the page shows the result instead.

The redirect is a hint. The front end must still poll GET /transferRequests/{transferRequestId} and check the payment status and reference before it acts. The page needs no bearer token: the transfer ID is a random UUIDv4 and acts as the capability, and each submission carries a form token stored with the request. A request with a return URL stays PND/PENDING until the payer decides, and the decision settles it at once, unless a payer rule settles it at creation. Requests without a return URL behave as before. See the P2G profile for precedence and refusals.

Configuration and boundaries

The local credential belongs to one producer per server. The defaults are:

Scope Default serve override
Producer / source registry / registry --producer / --source-id
Tenant pilot --tenant
Institution ministry --institution
Programme cash-support --program
Payer account programme-account --payer-account
P2G biller ministry --biller
Accepted return URLs none (any X-Return-URL is refused) --return-url
Currency and decimal scale USD:2 --currency
Submission mode 00 --mode (00, 01, 03)
Accepted callback URLs https://programme.example.test/callback, https://programme.example.test/api/v1/batch --callback-url

Repeat an override to allow several values, except producer/source. Supplying an override replaces its default set. Currency scales range from 0 to 6. Headers select permitted scope; they do not grant it. Token files must have private permissions (chmod 600) and contain one ASCII bearer token of at least 16 characters. Keep token and SQLite files in ignored .state/.

Callbacks are accepted as configured wire fields but are not delivered. Use polling. Receipts are retained for the lifetime of this disposable database. There is no receipt expiry, reset API, real rail, production identity provider, high availability or container publishing. serve upgrades a v1 or v2 state file to v3 in place, additively; any other database version is refused. Programme funding and real citizen checkout are outside this mock. The hosted page is a synthetic stand-in with no card or bank entry. Do not use real beneficiary data or expose this development server as a payment service.

Verify and reuse the contract tests

uv sync --locked
uv run ruff check .
uv run ruff format --check .
uv run payment-simulator openapi --check
uv run pytest -q

Regenerate the checked-in schema with uv run payment-simulator openapi. The live HTTP suite is tests/contract/. It starts isolated local processes, uses ordinary HTTP for public assertions, and keeps scenario control, restart and ledger inspection in tests/fixtures/. tests/test_service.py and tests/test_p2g_service.py contain implementation-specific checks. No real provider is contacted by default.

To run the portable subset against an existing synthetic sandbox:

uv run pytest tests/contract/test_g2p_profile.py -q \
  --target-url https://payments.sandbox.example.test \
  --token-file /path/to/private-sandbox-token --external-sandbox \
  --target-capability success

Use uv run pytest --help for target scope, currency and polling options. Select tests/contract/test_p2g_profile.py and --target-capability collection-paid instead to check the collection profile; --target-biller defaults to ministry. The external server need only expose the selected profile's APIs, not /healthz. Unavailable partial-outcome, held-processing, restart and ledger controls are reported as NOT VERIFIED skips. A provider fixture driver must supply those controls before claiming their evidence; declaring a capability alone does not implement it. The suite creates synthetic records with unique IDs and does not delete remote data.

The replacement boundary is this HTTP profile, implemented directly by a provider or an adapter. Matching wire shapes alone does not establish equivalent retry guarantees or prove recipient credit.

Document Purpose
Definition of done Required scope and explicit exclusions
Specification Five APIs and differences from the pinned GovStack sources
P2G collection profile Request to pay, payment evidence and collection scenarios
API traces Three illustrative request/response journeys
Contract tests Executed coverage versus future test catalogue
Generated OpenAPI Implemented wire schemas

These are Payment Simulator G2P Profile 0.1 and P2G Collection Profile 0.1, not full GovStack conformance or a claim that a real provider has moved money.

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.