What a refund test card is

A refund test card is a card number that a payment processor issues for sandbox use only. It works inside test mode, so you can charge it, refund it, and read the result without moving real money. Processors reject these numbers in live mode. The purpose is to exercise your refund code path from start to finish: the API call, the refund object, the webhook event, and the ledger entry.

cc refund test

Test numbers are not real cards and carry no cardholder data. Never run a refund test with a live card number, even for a dollar.

more on this topic

Prerequisites

  • Test mode API keys for your processor
  • A sandbox account with refunds enabled
  • A webhook endpoint that accepts test events
  • The processor's published list of test card numbers

How to test a refund with a test card

  1. Open the processor's test card list and pick one number for the success case.
  2. Switch every API key in your environment to test mode and confirm the dashboard shows test data.
  3. Create a payment method from the test number, or use the processor's test token if it supplies one.
  4. Create a charge for a small amount and store the charge ID.
  5. Capture the charge if your account separates authorization from capture.
  6. Send a refund request with the charge ID, the full captured amount, and a unique idempotency key.
  7. Compare the returned refund object to the charge: amount, currency, and status must match.
  8. Resend the identical request with the same idempotency key and confirm you get the original refund back, not a second one.
  9. Send a partial refund for half the captured amount and check the remaining refundable balance on the charge.
  10. Run a failure case with the test number your processor maps to a decline, then confirm your code logs the error and leaves the charge intact.
  11. Read the webhook events for each refund and match the event IDs to the refund objects.
  12. Archive or delete the test customer records once the run passes.

Picking the right test number

Processors publish several test numbers, and each one maps to a scripted outcome: a refund that succeeds, a refund that fails, a refund that stays pending, or one that settles later. Match the number to the case under test instead of reusing one number for every run. Keep the list in a fixture file next to your test suite so a processor update is a single edit.

cc refund test

What to check in the refund response

  • Status value and whether it is final or intermediate
  • Refunded amount, currency, and the original charge reference
  • Refund ID and any processor-side reference number
  • Created and settled timestamps in UTC
  • Failure code and message when the refund does not go through

Common failure cases

Three errors show up in most refund test runs. A refund larger than the captured amount returns an amount error, so clamp the request before it leaves your service. A refund on an unsettled charge returns a state error, so gate the refund button on the charge status. An expired test authorization returns a decline, which is useful for checking that your retry path does not double refund. Log the raw response body for each case and assert on the error code, not the message text, because processors rewrite messages without notice.

test card refund

Keeping test data out of production reports

Tag every sandbox charge with a test marker such as a metadata flag, then filter on that flag in finance reports. Test refunds that leak into revenue dashboards cause reconciliation work later. Confirm your webhook handler ignores test events on the live endpoint, and run a final check that no test customer record carries a live payment method.