How to modernize a payment API while old clients depend on it
An old client sends Authorize and waits up to 30 seconds for one of two words, APPROVED or DECLINED. The system that now processes the payment has neither word ready. It has accepted the request, passed it to the issuer and recorded the payment as pending. The contract the client was built against has no element for that, and the client’s developers left years ago.
Most writing on payment API modernization is about versioning fields, a largely solved problem. The harder one is that the new system can put a payment into states the old contract cannot express. A payment reported as declined while its authorization is still live at the issuer is a defect in money, and no response transformation removes it. My claim is that during coexistence the old and new APIs are two views of one state machine, and this guide builds the three things that keep them consistent for one system constructed for the article.
The system being migrated
An acquirer runs an old gateway: a synchronous SOAP web service with five operations, Authorize, Capture, Void, Refund and GetStatus. Merchants call it from shop systems and back-office jobs, and receive a settlement file each night. The part of its contract that matters most is small. The listing is illustrative, an excerpt of the XML Schema (XSD) that old clients generated their code from.
<xs:simpleType name="StatusType">
<xs:restriction base="xs:string">
<xs:enumeration value="APPROVED"/>
<xs:enumeration value="DECLINED"/>
<xs:enumeration value="CAPTURED"/>
<xs:enumeration value="VOIDED"/>
<xs:enumeration value="REFUNDED"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ResponseCodeType">
<xs:restriction base="xs:string">
<xs:enumeration value="A00"/> <!-- approved -->
<xs:enumeration value="D01"/> <!-- insufficient funds, retry allowed -->
<xs:enumeration value="D02"/> <!-- card expired, do not retry -->
<xs:enumeration value="D05"/> <!-- refused, do not retry -->
<xs:enumeration value="D09"/> <!-- try again later -->
</xs:restriction>
</xs:simpleType>
Both types are closed enumerations: a client that validates against the schema rejects a sixth status. Outside these values the contract has one more answer, a SOAP fault named ProcessingError, which clients were told to treat as “outcome not known, call GetStatus”. Capture takes no amount and captures the full authorization once, Refund answers REFUNDED synchronously, and clients time out after 30 seconds. In this contract every state is the immediate answer to a call, so a payment is never between two states.
The replacement is a new core: it accepts a payment over JSON, answers at once, and delivers later changes of state as events. It supports authentication challenges, partial authorization, several captures per payment and asynchronous refunds. One payment recurs below: merchant M-2041, old transaction ID T-88417, €120.00.
Why versioning does not carry this
Payment companies have settled how to change the shape of an API. Stripe pins each account to a version and, as its 2017 engineering post describes, transforms responses backwards one version change at a time. Adyen puts the version in the URL path. All of this concerns fields. The same Stripe post names the limit: a change that cannot be contained in a response transformation is flagged has_side_effects, and Stripe tries to avoid those. A new payment state is that kind of change. Current APIs have many such states: Adyen’s result codes include Received, Pending and PartiallyAuthorised, and Stripe’s PaymentIntent has requires_action, processing and requires_capture. A contract that says “approved or declined” has no place for any of them.
Figure 1 shows the new core’s states. Three of them (pending, action_required, partially_captured) are places where a payment waits for something that is not a client call: the issuer, the cardholder, or the next parcel.
stateDiagram-v2 state "pending" as pending state "action_required" as action state "authorized" as authorized state "partially_captured" as partial state "captured" as captured state "declined" as declined state "canceled" as canceled [*] --> pending: payment created pending --> action: issuer asks for a challenge action --> pending: challenge completed pending --> authorized: issuer approves pending --> declined: issuer refuses pending --> canceled: cancel action --> canceled: cancel or expiry authorized --> partial: capture of a part authorized --> captured: capture of all partial --> captured: final capture or release authorized --> canceled: cancel or expiry
Two more things need decisions. A partial authorization shows up as authorized with less than the amount asked. And a refund has its own states, because refunds can fail “even a few days after you submit the refund request” (Adyen).
Map, hide or reject, decided per state
For each new state, and each attribute that changes what a state means, the old contract allows three treatments. Map: the old contract has a value that means the same. Hide: the facade absorbs the state and shows the old client only what comes after it. Reject: the facade, or the new core on its behalf, prevents a payment that old clients depend on from entering the state.
The table below is the central artefact of the migration. I would write it before any facade code, and have product, operations and finance sign it, because every row is a commercial decision that looks like a technical one.
| New state | What the old client sees | Decision | What makes it safe |
|---|---|---|---|
pending, before second 25 |
No response yet | Hide | The facade holds the SOAP call open |
pending, at second 25 |
DECLINED/D09 after a confirmed cancel; ProcessingError if unconfirmed |
Hide, then cancel | A cancel wins over a late approval in the new core |
action_required |
DECLINED/D05 |
Reject | The facade creates the payment with challenges disallowed |
authorized, full amount |
APPROVED/A00 |
Map | Same meaning |
authorized, partial amount |
DECLINED/D01 |
Reject | The facade never requests it; if one arrives, the core reverses it |
partially_captured |
APPROVED |
Hide | Refused for merchants on the old settlement format unless they opt in |
captured |
CAPTURED, with the captured amount |
Map | A released remainder is visible in the amount |
canceled |
VOIDED if APPROVED was reported, otherwise DECLINED |
Map | The facade stores every answer it gave |
declined, any reason |
DECLINED with the nearest old code |
Map, many to one | The code must be in the same retry class |
Refund pending |
REFUNDED |
Map | A later failure is a settlement file line and an operations alert |
Two rules hold for every row. The mapping is total: no value of the new core reaches an old client untranslated, including values added next year. And an outcome keeps its retry class, the answer to “may the client send this again?”: a hard decline mapped to D09 produces a retry loop, and a temporary refusal mapped to D05 loses a sale. Three rows are lossy (refund, captured, partially_captured), and I would mark each loss where a merchant can see it.
A facade and one owner per payment
Figure 2 shows the target of the coexistence period. Old clients still call the same address; everything behind it has changed.
flowchart TD OC["Old clients, SOAP"] --> F["Facade"] F -->|"who owns it"| T["Ownership table"] F -->|"owner is old"| G["Old gateway"] F -->|"owner is new"| K["New core"] NC["New clients, JSON"] --> K G --> N["Card networks"] K --> N G -->|"change events"| L["Ledger and reports"] K -->|"change events"| L
This is the strangler fig approach, with branch by abstraction as the routing seam. Payments add a constraint those patterns do not state. A payment lives for weeks or months, and its state is partly at the issuer and the card network, so routing is sticky per payment: one authorized on the new core is captured and refunded there, whichever API the later request arrives on. The listing is an illustrative sketch.
enum Owner { OLD_GATEWAY, NEW_CORE }
Owner ownerFor(String merchantId, String txnId, Operation op) {
Optional<Owner> existing = ownership.find(merchantId, txnId);
if (existing.isPresent()) {
return existing.get(); // sticky for life
}
if (op != Operation.AUTHORIZE) {
return Owner.OLD_GATEWAY; // born before the facade
}
Owner chosen = rollout.newCoreEnabled(merchantId)
? Owner.NEW_CORE
: Owner.OLD_GATEWAY;
// unique key on (merchant_id, txn_id); returns the row that won
return ownership.insertIfAbsent(merchantId, txnId, chosen);
}
String idempotencyKey(String merchantId, String txnId) {
return merchantId + ":" + txnId; // "M-2041:T-88417"
}
The ownership row is written before the downstream call. Reverse the order and a crash between call and insert leaves a live authorization with no owner, the retry may go to the other system, and the card carries two holds. The rollout flag is read only when no row exists, which makes rollback cheap: switching it off sends new payments to the old gateway and leaves every payment born on the new core where it is.
Old clients send no idempotency key, so the facade derives one from merchant and transaction ID, and a retry, a restart and a second facade instance all address the same payment. Both systems need each other’s payments for reports and the ledger, but the facade should not write to both: two resources without a shared transaction diverge after a crash, as the Debezium write-up of the outbox pattern explains. The owner alone writes, with an outbox row in the same transaction that change data capture publishes.
Translating status for the old contract
GetStatus for a payment owned by the new core has to answer in the old vocabulary. The illustrative translator below is the mapping table turned into code.
OldStatus toOld(Payment p, AnswerLog answers) {
return switch (p.state()) {
case AUTHORIZED -> OldStatus.APPROVED;
case PARTIALLY_CAPTURED -> OldStatus.APPROVED; // hide: remainder open
case CAPTURED -> OldStatus.CAPTURED;
case DECLINED -> OldStatus.DECLINED;
case CANCELED -> answers.reportedApproved(p.id())
? OldStatus.VOIDED
: OldStatus.DECLINED;
case PENDING, ACTION_REQUIRED ->
throw new ProcessingErrorFault(p.id()); // outcome not known
};
}
The switch has no default branch, deliberately. Java requires a switch expression to be exhaustive (JLS §15.28.1), so an eighth state stops the facade compiling until the table has a new row, where a default would guess silently in production.
The CANCELED line is why the facade logs its own answers: a deadline cancel and a merchant void end in the same core state, but only one was ever reported as approved. Decline reasons get a lookup table and a build-time test that each maps to an old code of the same retry class.
The deadline: one payment the old contract cannot express
The numbers here are constructed. The old endpoint carries 1,000,000 authorizations a month. On the new core 99.8% have a final outcome within 25 seconds; the other 2,000 a month are still pending, and suppose 1,500 of them would later be approved and 500 refused. The client stops waiting at second 30, and the facade has three possible answers.
| Answer at the deadline | What follows | Monthly effect in the example |
|---|---|---|
DECLINED, payment left alone |
The merchant believes it failed while funds are held | 1,500 live authorizations nobody will capture or void |
APPROVED |
Goods ship against a payment the issuer may refuse | 500 orders without money |
Cancel, confirm, then DECLINED |
The ledger agrees with what the client was told | 2,000 attempts lost or retried |
Only the third keeps one truth. Its budget, 30 seconds minus 2 for transport and 3 for the cancel round trip, puts the decision at second 25. Figure 3 follows T-88417 through the worst ordering, in which the issuer approves just after the cancel was accepted.
sequenceDiagram participant C as Old client participant F as Facade participant K as New core participant I as Issuer C->>F: Authorize T-88417, 120.00 EUR F->>K: create payment, key from T-88417 K->>I: authorization request K-->>F: 202, state pending Note over F: second 25, no outcome yet F->>K: cancel payment I-->>K: approved at second 26 Note over K: cancel wins, approval is voided K->>I: reversal I-->>K: reversal accepted K-->>F: state canceled at second 27 F-->>C: DECLINED, code D09
Walk the failure this prevents. Without “cancel wins”, the core would move the payment to authorized at second 26, and the facade would still answer DECLINED at second 27. The shop shows an error, the buyer tries again, and the second attempt succeeds. The card now carries two holds of €120.00 for one order. The first belongs to a payment nobody will capture or void, because the only client that knows its transaction ID believes it failed. It ends when the authorization expires; Stripe’s documentation of authorization validity windows says an online card authorization is usually valid for 7 days. So “cancel wins” is a rule in the new core that exists only because of the old clients.
The reversal may itself go unanswered. For a cancel not confirmed by second 28, the facade must not answer DECLINED; it returns ProcessingError, and the client’s handling of an unknown outcome takes over (a timeout is not a decline covers that case). D09 invites a retry, which is safe because the payment is cancelled.
A partial capture that arrives from the other channel
Old clients cannot create a partial capture, because the old Capture has no amount. A merchant in mid-migration can: its shop authorizes through SOAP, and its new warehouse system captures through the new core as parcels leave. After a first capture of €80.00 on T-88417, the core holds this (illustrative):
{
"id": "pay_7Q2M",
"state": "partially_captured",
"amount": 12000,
"currency": "EUR",
"captured_amount": 8000,
"capturable_amount": 4000,
"origin": { "channel": "soap", "merchant": "M-2041", "transaction_id": "T-88417" },
"captures": [ { "id": "cap_1", "amount": 8000, "state": "succeeded" } ]
}
CAPTURED would tell the shop’s nightly GetStatus job that €120.00 is on its way when €80.00 is, so the translator answers APPROVED until nothing remains capturable. Stripe’s multicapture hides the state the same way: the PaymentIntent “remains in a requires_capture state” between captures. An old Capture becomes a final capture of the remaining €40.00. The settlement file, though, now needs two lines with the same transaction ID on different days, and a merchant whose reconciliation rejects the second line has a broken month-end. That is why the table refuses partial capture on SOAP-born payments until the merchant confirms its reconciliation accepts it.
Moving traffic in slices
Shadowing both systems on the same requests does not work for writes: GitHub’s Scientist “is only safe for wrapping methods that aren’t changing data”, and an authorization changes data at the issuer. Reads can be shadowed live, as Stripe describes for its subscriptions migration, and authorizations against an issuer simulator. Consumer-driven contract tests need the other side to take part, which a years-old integrator will not. My substitute is recorded production request and response pairs per client, replayed on every build, plus one synthetic request per row of the mapping table.
A slice is a part of the traffic that moves to the new core as a unit and can be sent back as a unit. The order puts reads before writes and reversible writes before settlement, starting with slice 0: the facade in front of the old gateway with every payment still owned by it. It changes nothing and is the most useful slice, because it puts the transitional component into production while the only thing that can differ is the facade. Because routing is sticky, captures and refunds for new-core payments must work before the first live authorization. Rollback in every slice is the same act: the flag stops sending new payments to the new core, and payments already born there finish there. From the first live slice onward the new core is a production system with obligations.
The slices and their rollback conditions
The thresholds are illustrative; set them from the variance of your own traffic.
| Slice | What moves | Rollback condition |
|---|---|---|
| 0 | Facade in front of the old gateway, all payments owned by it | Any difference in a replayed response |
| 1 | GetStatus and reports, shadowed, then served |
Any diff outside the agreed ignore list |
| 2 | Authorize in shadow against a simulator |
None needed, nothing is live |
| 3 | Live Authorize for 1% of one merchant cohort |
Approval rate 0.3 points below control, or one unconfirmed deadline cancel |
| 4 | Captures, voids and refunds relied on at volume | Any clearing account not at zero after settlement |
| 5 | Settlement files from the new ledger, in parallel | Any line-level diff over a month including month-end |
| 6 | Remaining cohorts, then switch-off | The ledger proof below |
Proving from the ledger that the old path can go
I would retire the old system on ledger evidence, not a calendar date. A clearing account is a ledger account money passes through on its way between parties, and that returns to zero when the flow is complete. Stripe uses this as the health measure of its Ledger: “Clearing measures the fraction of Ledger that is appropriately zeroed out at steady state.” A balance with no recent entry is money stuck in the path.
Four statements must hold together. No request has reached the old gateway for a full cycle including a month-end and the longest refund or dispute window. Every payment it owns is in a final state and past its last possible movement. Every clearing account it feeds is at zero across consecutive settlement cycles. Every deadline cancel has a confirmed outcome. The second and third are queries that must return nothing (illustrative).
-- Payments the old gateway owns that can still move
SELECT o.merchant_id, o.txn_id, p.state
FROM payment_ownership o
JOIN payment_view p USING (merchant_id, txn_id)
WHERE o.owner = 'OLD_GATEWAY'
AND (p.state = 'APPROVED' -- can still be captured or voided
OR p.last_possible_movement > now()); -- refund or dispute window open
-- Clearing accounts fed by the old gateway that are not at zero
SELECT account, currency, sum(amount) AS balance
FROM ledger_entry
WHERE account_type = 'clearing'
AND source_system = 'OLD_GATEWAY'
GROUP BY account, currency
HAVING sum(amount) <> 0;
last_possible_movement takes the work: a captured payment can be refunded and disputed for as long as the card scheme allows. Rather than wait that out, migrate the tail: import each remaining old payment into the new core as a record that accepts refunds and disputes, changing its ownership row in the same step. This is the one case where a payment changes owner, acceptable because nothing is in flight. The proof says the old gateway can go. The facade goes when the last old client does.
Limits of this design
No payment company has published how it moved live authorizations between two cores. The migrations cited concern storage, reads and ledgers. The design above is reasoning from documented behaviour and published patterns, not checked against a public account of the same migration.
Cancel-and-decline costs sales: in the example, 1,500 a month. Answering ProcessingError at the deadline keeps them for clients that implement the status inquiry and harms those that treat a fault as a decline; which clients are which is an empirical question per integrator.
A deadline cancel has no meaning for file-based partners, and the ownership table is a new single point of failure whose availability must match the old gateway’s. Every number about the constructed system is illustrative.
The facade and the ownership table are known patterns. The cost estimates tend to miss is in the mapping table: for as long as one old client remains, the old contract constrains the new system’s state machine.
Sources
- Versioning (API reference), Stripe, accessed 28 November 2026
- APIs as infrastructure: future-proofing Stripe with versioning, Stripe, 5 August 2017
- How Payment Intents and Setup Intents work, Stripe, accessed 30 November 2026
- Place a hold on a payment method, Stripe, accessed 30 November 2026
- Capture a payment multiple times, Stripe, accessed 30 November 2026
- Online migrations at scale, Stripe, 2 February 2017
- Ledger: Stripe’s system for tracking and validating money movement, Ilya Ganelin, Stripe, 16 February 2024
- API versioning, Adyen, accessed 28 November 2026
- Payment result codes, Adyen, accessed 30 November 2026
- Refund, Adyen, accessed 28 November 2026
- Strangler Fig, Martin Fowler, 22 August 2024
- Branch By Abstraction, Martin Fowler, 7 January 2014
- The Java Language Specification, Java SE 21 Edition, chapter 15, §15.28.1, Oracle, accessed 30 November 2026
- Reliable microservices data exchange with the outbox pattern, Gunnar Morling, Debezium, 19 February 2019
- Scientist, GitHub, accessed 28 November 2026