All work
Writing · Payments

The refund that fails by design

Two of the five payment gateways I test against refused the same step, every time. The gateways were right. My tests were wrong, and fixing them properly taught me more about UAT than the failure did.

The flow

UAT-Ops runs the same card flow against each gateway’s sandbox: authorize a card, capture it, refund part of it, then authorize again and void that one. Stripe, Square and PayPal passed every step. Braintree and Authorize.net refused the partial refund, on every run, at exactly the same place.

Why they said no

Neither gateway was broken. Both only refund money that has started to settle, and the flow asks for the refund seconds after the capture, before any settlement has run. Braintree’s documentation says so directly: a transaction that hasn’t begun settlement has to be voided instead. Authorize.net answers with response code 54, “the referenced transaction does not meet the criteria for issuing a credit,” and an unsettled transaction is one of that code’s documented causes.

Before settlement, the right move is a void, which cancels the charge before any money moves. After settlement, it’s a refund, which returns money that already has. They’re two different operations, and which one is available depends on timing the customer never sees.

It looked exactly like a broken integration

In the run log, a gateway behaving exactly as documented was indistinguishable from an integration that didn’t work: a red step, every time, at “Partial refund.” Anyone reading that later, whether a reviewer, a client or me a few weeks on, would draw the wrong conclusion from it.

That’s the part that matters beyond refunds. A test result is only useful if the person reading it can tell what it means without the context of the person who ran it.

The fix that would have been wrong

The easy fix is to mark the step as expected to fail. That would have been worse than the problem. Every refusal would then pass, including the ones that are real failures: a malformed request, a wrong amount, a missing permission. And a refund that succeeded, on a gateway that refunds immediately or a sandbox that had already settled, would be reported as a problem, when it’s exactly the right result.

What I did instead

The step now names the one precondition it’s allowed to hit, a refund before settlement, and recognises it by the gateway’s structured error code, never by the wording of the message: Braintree’s legacy code 91506, and Authorize.net’s error code 54 on a declined transaction. A match is recorded as an expected rejection, with the reason stated and the gateway’s own documentation cited. Anything else the gateway says still fails the run.

The published result doesn’t overclaim either. A run with an expected rejection is marked “tested,” not “verified.” The refund wasn’t demonstrated, so the directory page doesn’t say it was, and the counts stay visible: 7 passed, 1 expected rejection.

A refund accepted isn’t a refund done

The gateways that passed had their own lesson. Square’s refund step passed, but the refund came back as pending. Square documents that most refunds complete within hours, and card refunds can stay pending for up to 14 days. So “pass” meant the refund was accepted, not that the money had gone back.

What to take from it if you’re integrating payments

  • Build both paths. Void before settlement, refund after, and choose by the transaction’s state, not by how long ago it was made.
  • Read the code, not the message. Error messages are written for people and can be reworded. The code is what your integration should act on.
  • Separate “no, by design” from “something broke.” In a log they look identical, and whoever reads it next won’t have your context.
  • Track a refund until it’s done. Accepted and completed can be days apart, and your support team will be asked about the gap.
  • Say what wasn’t tested. A capability the sandbox declined to exercise hasn’t been proven, however green the rest of the run is.

Why it’s a foundation problem

In Foundation Layer terms, this was never a delivery problem. The integration worked. What failed was Clarity (L3): a record that couldn’t tell anyone the difference between a gateway doing its job and an integration that was broken. That’s also why UAT is where integrations go to die: not because the work is hard, but because the evidence doesn’t say what it means.

The sandbox runs are public, step by step, for Authorize.net and Braintree. If you’re wiring a gateway into your platform and want this kind of testing done before go-live, that’s the work I do.