API & Payment Gateways

A payment timeout is not a retry problem until you know whether the money moved. We design the gateway around idempotency, reconciliation and a clear answer to who owes whom after a failure.

Integration work between your systems and third-party APIs, most often payments. It covers the interface contract, the behaviour when a call fails or times out, the reconciliation between provider and ledger, and the monitoring that tells you when the two disagree.

Starts with
What happens when it fails
You get
A gateway with reconciliation
You own
Settlement rules
We bring
Integration, tests, monitoring
Best fit
Payment flows with timeouts, refunds, multiple channels or reconciliation gaps.
Not a fit
A checkout UI redesign with no access to settlement, gateway logs or finance.

When a timeout leaves two versions of the truth

  • A timeout leaves two different truths about whether a payment went through.
  • Channels accept different payment methods and settle on different terms.
  • Refunds are handled by hand and nobody can say how many are open.

Why this is harder than it looks

A payment either happens or it does not, and the network is allowed to be unsure. Every gateway integration therefore lives with a gap where the request left and the answer never came back.

Most integrations handle that gap by guessing — retry, or mark as failed. Both guesses cost money: a retry can charge twice, a failed mark can leave a paid order unfulfilled.

So the design work is idempotency and reconciliation, settled before the first line of code, because neither can be retrofitted into a live ledger.

Where a payment fails twice

Figure 1 — Where a payment flow breaks, the control that prevents it, and the evidence it leaves

Where a payment flow breaks, the control that prevents it, and the evidence it leavesWHERE IT FAILSTHE CONTROLTHE EVIDENCEA timeout with no known outcomeTwo versions of whether the money moved.Idempotent retries on a stable keyA retry can never charge the customer twice.One charge per key in the ledgerReconciled against the gateway, not the app.Channels that settle on different termsThe same order closes on a different date.One settlement model per channelFees, delays and cut-offs written down.A settlement map finance signsPer channel, per method, per currency.Refunds tracked by handNobody can say how many are still open.A refund register with an ownerEvery refund gets an id and a state.Open refunds aged and ownedMeasured daily, not at month end.Reconciliation is a finance control. If it is owned by engineering alone, it reports on itself.

Figure 2 — The layers that have to hold for API & Payment Gateways

stack, top to bottomRouteswhich channel, which methodrulescostsContractrequest and responseidempotencyerrorsBuildone integration pointadaptersretriesReconcilemoney and recordsdailyautomaticOperateowner, alerts, refundsrunbookA payment that times out is not a retry decision until the system can answer whether it already succeeded.

What you get

Routes
A route and method map
Which channel uses which method, under which commercial terms.
Contract
A gateway contract
Requests, responses and the idempotency key that makes a retry safe.
Rules
Idempotency and retry rules
What is retried automatically and what is handed to a person.
Reconciliation
A reconciliation report
Money recorded by the gateway against money recorded by the business.
Refunds
A refund path
Who approves, what is evidenced and how long it is kept open.
Operations
An operating runbook
Alerts, owner, settlement calendar and the failure cases.

Who signs off each layer

Finance owns settlement rules, delivery owns the route design and engineering owns idempotency and monitoring.

Figure 3 — Who owns each payment control

FinanceDeliveryEngineeringRoutesContractBuildReconcileOperateapproves costsmaps channelsadvisesaccepts termswrites contractbuildsacceptstestsintegratessigns offchecksautomatesowns refundsruns runbookalertsReconciliation is a finance control, not a technical report nobody reads.

What we need before we start

  • The current payment methods and who settles each one.
  • A real example of a payment that failed in an ambiguous way.

How it usually runs

Stage 1
Trace the money
We follow one transaction end to end — authorisation, capture, settlement, refund — through every system that stores a version of it.
You decide: which system is the record of truth.
Stage 2
Fix the identity
Every attempt gets a key that survives a retry, and every state change becomes explicit rather than inferred from a status string.
You decide: how long an unresolved payment may stay unresolved.
Stage 3
Reconcile on a schedule
A daily comparison between gateway settlement and your ledger, with a named person for the exceptions.
You decide: who owns the exception queue, and by when.

Questions we get asked

Can we add a second gateway later?

Yes, if the abstraction exists now. Retrofitted, the retry and reconciliation logic usually lives inside the first provider’s assumptions, and the second provider breaks them.

What about refunds and partial captures?

They are where most of the edge cases live, and the reason the state machine has to be explicit rather than derived from whatever the gateway last returned.

Is PCI our problem?

The scope decision is. Tokenised hosted fields shrink it dramatically, but somebody still has to sign that decision and keep it true after the next release.

Where this has been applied

Reading that goes with this

How to start

Bring the last payment dispute and the logs from both sides. Get in touch.

CONTACT US

We provide a custom made service for just drop us a line.
We would be glad to have feedback from you.