Idempotent API, double-entry ledger, saga orchestrator with Kafka, HMAC-signed webhooks, settlement reconciliation, ML fraud scoring, and an LLM ops assistant — the full machinery underneath a payment gateway.
Each is a deliberate correctness choice — the kind payment teams actually screen for.
All amounts are integer minor units (paise / cents) stored as BIGINT. 0.1 + 0.2 ≠ 0.3 has no place in a ledger. No floating-point, no rounding errors, no surprises.
An account's balance is always computed by summing its ledger lines — never stored. A stored balance can drift; a derived one is correct by construction. Every write posts a balanced journal entry.
Networks retry. The same Idempotency-Key with the same body replays the original response — charged once. The unique constraint in PostgreSQL is the source of truth, not application memory.
A capture posts one balanced journal entry. A refund posts the exact reverse. Because both sides always move together, the books are always balanced.
| Account | Type | Direction | Amount | Meaning |
|---|---|---|---|---|
ACQUIRER_CASH |
Asset | DEBIT | 150000 | Cash received from acquirer |
MERCHANT_PAYABLE |
Liability | CREDIT | 150000 | Amount owed to merchant |
Every write requires an Idempotency-Key header. Retries are safe by design.
Replays the original response. No new payment created.
Returns 409 Conflict. Prevents accidental mutations.
Returns 400 Bad Request. Every write must be idempotent.
One command to start, one curl to test. Docker Compose spins up PostgreSQL and the application together.
# Start Postgres + the app docker compose up --build # Create a payment (idempotent) curl -s -X POST http://localhost:8080/v1/payments \ -H "Content-Type: application/json" \ -H "Idempotency-Key: demo-001" \ -d '{"merchantReference":"order-42","amountMinor":150000,"currency":"INR"}' # Retry the SAME request — same key → same result, charged once curl -s -X POST http://localhost:8080/v1/payments \ -H "Content-Type: application/json" \ -H "Idempotency-Key: demo-001" \ -d '{"merchantReference":"order-42","amountMinor":150000,"currency":"INR"}' # Verify the ledger is balanced curl -s http://localhost:8080/v1/accounts/ACQUIRER_CASH/balance curl -s http://localhost:8080/v1/accounts/MERCHANT_PAYABLE/balance # Both return 150000 ✓
Five of six phases are live. Each phase adds a production concern.
Idempotent payment API, double-entry ledger, integer money, derived balances, Flyway migrations, Testcontainers integration tests.
LiveExplicit state machine (INITIATED → AUTHORIZED → CAPTURED → SETTLED) with the saga pattern and compensating transactions over a Kafka event bus.
LiveHMAC-SHA256 signed outbound events with exponential-backoff retries and dead-letter. Settlement CSV reconciliation with auto-settle on match.
LiveXGBoost model with SHAP explanations in the decline response — every "declined: fraud" says why. Dockerized Python scoring service.
LivePredict success probability per acquiring route and route to maximise expected success at minimum cost.
PlannedNatural-language queries over payment and risk data, powered by Anthropic Claude with template-based fallback for local dev.
Live