Exercise objective: prove that one return causes one authorised refund
This test matrix is for an online retailer that accepts returns through a warehouse platform and uses a payment gateway to issue refunds. The focus is not whether callback signatures are implemented in isolation. It is whether a legitimately authorised return can be refunded exactly once, for the correct order and remaining amount, when notifications are duplicated, delayed or received in an unexpected order. Payment and fulfilment systems may disagree temporarily, but their final financial states must reconcile.
Use a sandbox merchant, fictional customers and non-settling payment tokens. The payments product owner should approve the cases, the returns manager should validate operational states and finance should verify the final ledger. Do not send live refunds or manipulate real customer transactions to satisfy this exercise. Document gateway sandbox limitations, especially if its asynchronous timing or retry model differs from production.
Prepare four reference orders
Create a standard captured card sale, a split-tender sale, a sale with an authorised partial return and a cancelled order for which no refund is due. Give each an immutable order ID, provider capture identifier, customer reference and original amount. Create separate return merchandise authorisations where the business process requires them. Record the refundable balance before each test, distinguishing a refund request that was accepted for processing from one fully completed by the payment service.
The retailer should specify the rule for partial refunds, exchanges, shipping credits and promotions. Those business adjustments can be legitimate, but they must be attributable and must not allow total refunds to exceed the relevant captured funds. A bank or card refund and a store-credit issue are not necessarily the same ledger transaction. Define which outcome the test expects rather than treating any green refund message as success.
Case A — ordinary completed return
Mark a fictional item received and inspected, authorise its refund, create the gateway request and observe the final provider outcome. Record the original capture, return approval, refund ID, gateway idempotency key, callback identifier, accounting entry and customer message. The correct state should have one payment release against the approved transaction and an updated remaining refundable balance. A queued instruction that has not yet settled should not be recorded as a completed cash refund.
Now retrieve the same order through the service desk and warehouse views. They should display consistent information even if their refresh intervals differ. If one view temporarily says “processing”, the workflow needs an explanation and a reconciliation job—not a second manual refund simply because a customer contacted support. State the expected time window for a normal transition and the escalation route when provider confirmation does not arrive.
Case B — identical callback delivered twice
Re-send the same signed test callback with the same provider event identifier. The application should recognise it as an already processed event and avoid creating a second refund or sending a second confusing customer notification. Record both deliveries and the single resulting financial action. Test a retry after an application restart, because in-memory duplicate protection can vanish when the service scales or fails over.
Also test the gateway’s own retry policy and any queue redelivery mechanism. The retailer may receive duplicates at more than one layer; every payment-generating operation needs an idempotent business key tied to the intended refund, not a new key generated for every attempt. A provider accepting the same idempotency key twice without issuing extra funds is useful defence, but the merchant should not rely on it as the only ledger safeguard.
Case C — a later event arrives first
Submit a synthetic “refund completed” notification before a preceding “refund accepted” event, where the gateway sandbox permits such reordering. Define whether the application queues the event, verifies current provider state or rejects it for review. It must not reverse the completed status back to pending when the older message eventually arrives. Preserve timestamps from the source and receipt systems; network delivery order is not necessarily the order in which the provider committed payment changes.
A second variant simulates cancellation after a refund request was queued but before the callback arrives. The merchant must determine whether the refund already became irreversible and which accounting reversal or exception is allowed. Security controls should not invent a second payment merely to make the user interface match the latest callback. Finance needs a reconciliation process for genuinely ambiguous gateway states.
Case D — valid signature, wrong transaction
A signed provider notification can still refer to a payment outside the merchant or order being processed. Feed an authorised sandbox signature with a mismatched merchant, capture or refund identifier. The receiving service should verify that the event belongs to the expected payment relationship, not only that the message originated from the gateway. No unrelated customer order should change state, and the test should create an auditable exception rather than silently dropping a financially significant mismatch.
Try another negative case using a returned item whose authorised value has already been fully refunded. A duplicate request with a new transport message identifier must not bypass the business balance check. Validate that the reconciliation ledger and the payment gateway both reject or safely neutralise the second release. If the test produces a partial over-refund, record the exact amount and route for corrective development before release.
Case E — split tenders and partial refunds
For an order paid partly with a card and partly with gift credit, approve a partial item return. The expected payment allocation should follow the retailer’s published business rules and provider constraints. Confirm that each capture can be refunded only within its remaining amount and that the final customer communication explains the split. If the refund queue crashes between the card and gift-credit components, the retry must complete the outstanding authorised component rather than refunding both again.
Use two closely spaced partial returns to test concurrency. Distinct workers may each read the same refundable balance before either commits an update. The retailer needs a transaction lock, reservation or equivalent consistency control to prevent both workers from releasing more than is allowed. The test should preserve evidence of each request’s read state and final committed balance, not merely the sequence of HTTP responses.
Case F — warehouse and payment services disagree
Simulate the warehouse approving a return while the payment API is temporarily unavailable. The customer service interface should show an honest pending state, retain the authorisation and avoid issuing a new refund without checking the existing request. When the gateway recovers, replay the original intent with its stable idempotency key. Verify that one payment reaches a completed state and the warehouse record does not mark a second return.
An alternative case starts with the gateway completing payment but the merchant’s acknowledgement failing. On recovery, the application must reconcile against provider state before reissuing funds. This is where monitoring and ledger comparison are more valuable than simply alerting on API errors. Define an operational queue that finance can inspect and close without having to override transaction boundaries.
Evidence matrix and pass conditions
Keep a test row for each variation with these columns:
- Setup: order ID, original capture, refundable balance, return status and expected payment destination.
- Trigger: callback identifier, signature validity, delivery order and whether a duplicate has already been processed.
- Expected state: resulting refund amount, single ledger entry, customer message and final provider confirmation.
- Observed state: actual payment response, queue execution, accounting balance and customer notification.
- Mismatch: which system disagreed, whether funds moved and which team owns correction.
- Re-test: evidence after code change, worker restart or payment-provider library update.
- Approval: sign-off from payments product, finance reconciliation and returns operations.
Treat “callback accepted” as an intermediate event unless the provider explicitly guarantees a final financial outcome. Every passed case should demonstrate that the authorised customer receives the correct refund and no other order or merchant is affected. A technical negative response without a corresponding ledger check is incomplete acceptance.
Containment, recovery and release gate
If a duplicate refund defect is confirmed, the business may need to pause automatic processing for the affected workflow while retaining a supervised manual route. Preserve pending requests, gateway identifiers and finance reconciliation before retrying. Determine whether any real customers were overpaid, underpaid or merely shown incorrect statuses using verified records. Do not apply ad hoc production fixes that conceal the audit trail.
Before release, have an independent reviewer execute a short smoke suite: ordinary refund, repeated callback, out-of-order event, cross-merchant mismatch, partial return and gateway recovery. Record the build and provider sandbox versions and note behaviours that production traffic might exercise differently. Put the matrix into the regression suite for future checkout, gateway and warehouse changes. The governing principle is that notification delivery is not financial authority; a refund must remain anchored to a single approved business transaction from request through settlement.
Make the reconciliation owner visible
The finance reviewer should confirm that each simulated refund maps to one authorised customer obligation and one final gateway transaction. Where the gateway’s test environment cannot represent a settlement or chargeback behaviour, record that exact limitation and obtain a separate provider-supported assurance before production approval. A successful unit test alone cannot guarantee ledger accuracy across a payment-provider outage.
Sources and further reading
Explore Next Defence expertise
Next Defence can help retail payments teams validate duplicate-callback handling against payment-event IDs, idempotency keys, order states and ledger entries. Run synthetic refund cases with a payments engineer and finance controller, and retain proof that a retry cannot issue a second credit.