Cross-Domain Payment Proxy Architecture

A signed server-to-server payment bridge between two independent applications, with tokenized capture, 3-D Secure and idempotent status reconciliation.

ROLEArchitecture + implementationSigned bridge, tokenized capture
SCOPECross-site flow, request signing, 3-D Secure, status reconciliationTwo sites, one final status
STACK PATTERNSWordPress / PHP / REST / HMAC-SHA256 / 3-D SecureHMAC-SHA256 + 3-D Secure
STATUS
Anonymized case
Drawn from a code audit
01 · CONTEXT AND TRUST BOUNDARIES

A single payment across two trust boundaries

Two applications under separate trust boundaries needed to complete a single payment. The storefront could not hold gateway credentials, and the payment host could not trust unsigned instructions arriving over the web.

Card data had to stay off the origin entirely while shoppers still saw one continuous checkout. Webhooks could arrive more than once, a 3-D Secure challenge could strand a shopper on a return path, and both systems had to converge on exactly one final order status despite all of that.

CORE CONSTRAINT

No card PAN ever touches the origin. Gateway credentials live on one side of the boundary only.

02 · SYSTEM REQUIREMENTS

Constraints that shaped the design

C-01 · BOUNDARY

Separate trust boundaries. The storefront never holds gateway credentials.

C-02 · SECRETS

No card PAN on the origin. Capture is tokenized in the browser.

C-03 · ZERO PAN

Duplicate webhook deliveries. Every callback must be safely repeatable.

C-04 · DUPES + 3DS

3-D Secure return path. The shopper leaves mid-payment and must land back safely.

03 · TOPOLOGY AND NODES

End-to-end payment pipeline

PIPELINE NODE SEQUENCE · SIGNED FLOW
HMAC-SHA256 SECURED
EXECUTION READ PATH AND STATUS SEQUENCE

Client → Origin API → Signed Proxy → PSP Adapter → Ledger → Reconciler. The origin records an unsigned intent, the proxy validates and signs over HMAC-SHA256, the adapter charges through the configured gateway, the ledger holds the single status record while the reconciler converges retries to one outcome.

04 · LIFECYCLE FLOWS

Three paths through the system

Happy Path & 3DS

SUCCESS
  1. 01The shopper submits the form. The origin records the intent as Processing and opens the hosted payment frame.
  2. 02The payment host validates the entry over an HMAC-signed call before rendering anything.
  3. 03The card is tokenized inside the payment frame. The number never reaches either server.
  4. 04The adapter charges through the configured gateway.
  5. 05A signed callback reports the result. The origin maps it to Paid, Failed or Pending.
  6. 06A 3-D Secure challenge returns the shopper through a signed verification path before the ledger moves.

Timeout & Recovery

RECOVERY
  1. 01The capture acknowledgement arrives late, or not at all.
  2. 02The ledger stays Pending. A missing answer is never treated as a failure.
  3. 03A status poll against the payment host reconciles the true outcome.
  4. 04Exactly one outcome is recorded. The charge is never retried blindly.

Duplicate Webhooks

IDEMPOTENT
  1. 01A webhook or callback is delivered a second time.
  2. 02The guard matches an already-seen key before touching the ledger.
  3. 03The repeat is ignored. The ledger record is unchanged.
  4. 04No double fulfilment, no second receipt, no manual repair.
05 · ARCHITECTURAL DECISION RECORDS

Evaluated options and trade-offs

ADR-001 · D1

Where to sign

ACCEPTED & DEPLOYED
OPTIONS EVALUATED

A) Sign at the origin

B) Sign at the payment proxy

CHOSEN DECISION

Sign at the payment proxy

Key material stays on one side
RATIONALE

Only the payment host holds the shared secret, so a forged instruction from the web cannot move money. Validation happens where the credentials live.

ENGINEERING TRADE-OFF

The origin cannot complete a payment while the payment host is unreachable. Availability of one side gates the other.

ADR-002 · D2

What to sign

ACCEPTED & DEPLOYED
OPTIONS EVALUATED

A) HMAC over the raw JSON body

B) HMAC over a sorted canonical string

CHOSEN DECISION

HMAC over the raw JSON body

Exact bytes, no canonicalization drift
RATIONALE

Both sides already hold the exact bytes, so there is no canonicalization step to drift apart. Verification is a single constant-time comparison.

ENGINEERING TRADE-OFF

There is no replay window or nonce on the signed call. Hardening that is recorded as a future improvement, not a current guarantee.

ADR-003 · D3

How to support three gateways

ACCEPTED & DEPLOYED
OPTIONS EVALUATED

A) Separate code path per gateway

B) One common adapter workflow

CHOSEN DECISION

One common adapter workflow

One status model for three gateways
RATIONALE

The three payment providers share a single status model, Paid, Failed and Pending, so one code path maps every outcome the same way.

ENGINEERING TRADE-OFF

Provider-specific features need adapter extensions instead of working inline. The common path stays deliberately narrow.

06 · SECURITY CONTROLS

Security controls

1. HMAC-SHA256

Signed over the raw JSON request body and verified on receipt.

2. Constant-time comparison

Every signature check compares in constant time.

3. Isolated secrets

Shared secret held on the payment host only, never on the origin.

4. Tokenized capture

The card number never reaches either server.

5. Last-four only

Only the last four digits stored, for receipt reference.

6. Idempotent status

Idempotent status updates with duplicate-callback guards.

07 · OUTCOMES

Outcomes that hold true

WHAT HOLDS TRUE
  • Card data never touches the origin. Only the last four digits are kept.
  • Gateway credentials live on one side of the trust boundary.
  • Duplicate deliveries collapse to a single ledger outcome.
  • Every payment converges on one final status, Paid, Failed or Pending.
What I would improve (Engineering Self-Critique)
  • Replay-window and nonce hardening on the signed server-to-server calls.
  • Managed secret rotation instead of manual key replacement.
  • Contract tests per payment adapter, so gateway drift is caught before deployment.
08 · RETROSPECTIVE

Transferable engineering principles

PRINCIPLE 01

Push idempotency to the edges. If every repeat is safe, the center never needs to be clever.

PRINCIPLE 02

Design the 3-D Secure return path first. It is the part of the system the shopper actually feels.

Continue reading

UP NEXT IN ARCHITECTURE DOSSIERS

Next Case Study → Employee Application Management System

A role-scoped operations console for multi-step applications, built on two different form engines.

Architecture & Payment Infrastructure
Open to New Work

Need a system architected like this?

Available for architecture advisory, custom PHP payment gateway bridges and resilient distributed workflows.

PORT: 443/TLS·LOCATION: Rajkot, India / Remote·STATUS: Available for Eng Interviews
UTC+5:30 · P99 RESPONSE: < 24H