Skip to content

References and safe retries ​

Networks drop. Requests time out. When that happens in the middle of a purchase, you do not know whether the customer got their airtime or token. Buying again risks charging twice. Not buying risks an unhappy customer.

A reference solves this. You choose an id for the purchase and send it with the request. Xash records the reference before it charges anything. From then on, the same reference always means the same purchase:

  • send it again and you get the outcome of the first request;
  • it never charges or delivers a second time.

Which purchases accept a reference ​

PurchaseFieldLookup
Direct airtimereferenceGET /api/v1/transactions/status
Airtime vouchersreferenceGET /api/v1/transactions/status
BundlesreferenceGET /api/v1/transactions/status
Bundle vouchersreferenceGET /api/v1/transactions/status
ZESA tokensreferenceGET /api/v1/transactions/status
DStv paymentsreferenceGET /api/v1/transactions/status
WiFi vouchersclient_referenceGET /api/v1/wifi/vouchers/purchases/{reference}
Depositsrequest_idThe poll endpoint

Every purchase endpoint accepts one. Transfers do not: their reference field is only a note.

The reference is always optional. A request without one is answered exactly as that endpoint always answered it, so an existing integration keeps working unchanged. But then a repeated request is a second purchase, and after a timeout you cannot ask what happened. Send a reference with every purchase.

The rest of this page is about reference on airtime, airtime vouchers, bundles, bundle vouchers, ZESA and DStv. WiFi vouchers follow slightly different rules.

Choosing a reference ​

Rule
Length1 to 120 characters.
CharactersLetters, digits, and : . _ -. No spaces.
ScopeUnique within your account, across all of these products together: a reference used for airtime cannot be used again for a bundle. Other accounts cannot see or collide with yours.
LifetimeKept permanently. A reference can never be reused for a different purchase.

Use the id of the order in your own system, for example order-1001 or shop:2026-11-19:000123. Create it before you call Xash and store it with the order, so that a retry after a crash sends the same value.

Do not generate a fresh random reference for each attempt. That defeats the purpose: each attempt would be a new purchase.

A reference that breaks these rules is a 422validation error and nothing is bought. That includes an empty string, null and a value that is not a string: the field is either left out or valid. It is never silently ignored.

What the same reference means ​

Two requests are "the same purchase" when the reference and these details match:

ProductDetails that must match
AirtimePhone number, amount, currency
Airtime vouchersNetwork, voucher value, quantity, currency, is_vendor_voucher
BundlesBundle, phone number
Bundle vouchersBundle, quantity
ZESAMeter number, amount, currency
DStvSmartcard number, package

Then:

You sendYou get
A new referenceThe purchase runs.
The same reference, same details, first request finishedThe same answer as the first time, with the same status code. Nothing runs.
The same reference, same details, first request still running202 OUTCOME_UNKNOWN with data.status of processing. Nothing runs.
The same reference, different details409 REFERENCE_CONFLICT. Nothing runs.

A repeat is honoured even if something changed since the first request: a price, a minimum, a network being switched off, a bundle withdrawn from the catalogue. You still get the first outcome.

For voucher purchases the first outcome includes the PINs. A repeat returns the same PINs; it never issues new ones.

The three outcomes ​

Every purchase with a reference ends in exactly one of these.

200: delivered ​

success is true and data.status is processed. Record the sale. What was delivered is in data.fulfilment: the token for ZESA, the PINs for airtime vouchers and bundle vouchers. It is null for products that go straight to a phone or an account.

Failure: 4xx or 503 with an error_code ​

success is false, data.status is failed, and error_code says why. Nothing was delivered. Your wallet was not charged, or was refunded.

The reference is now used up. Repeating it returns this same failure forever. If you want to try the purchase again, for example after topping up your wallet, send a new reference. This includes a purchase refused by a spending limit: the refusal is stored with its figures, and a repeat returns it even after the limit is raised or the day has reset.

A request that was rejected before the reference was recorded leaves the reference free. You can correct the request and send it with the same reference. There are three such answers:

  • a 422 validation error (a body with errors and no error_code);
  • a 404 for a bundle or network id that does not exist;
  • 422 RECIPIENT_INVALID from a bundle purchase, whose data holds only your reference. (For ZESA, RECIPIENT_INVALID is a recorded failure like any other.)

If you are not sure which case you are in, look the reference up: 404 REFERENCE_NOT_FOUND means nothing was recorded.

Codes that point at an earlier purchase ​

A new reference is only for a purchase whose earlier attempt definitely failed. Five codes refuse your request because of another purchase for the same reference, meter or smartcard, and that other purchase may have been delivered, may still be held or may still be running. They do not tell you it failed.

CodeWhat it meansBefore you buy again
409 REFERENCE_CONFLICTThis reference already belongs to an earlier purchase with different details. Your request recorded nothing and changed nothing.Look up the reference to see what the earlier purchase did. Never swap in a new reference just to get past this answer.
DUPLICATE_TRANSACTION (DStv)An earlier payment of the same amount to this smartcard, in the last 10 minutes, was paid, is held or is still running.Find that payment and check its status.
DUPLICATE_PURCHASE (ZESA)This meter has an earlier purchase that is not settled yet, or was sold the same amount in the last 10 minutes.Find that purchase and check its status.
METER_BUSY (ZESA)Another purchase for this meter is running right now.Wait for that purchase to finish, then check its status.
PURCHASE_IN_PROGRESS (DStv)Another payment for this smartcard is running right now.Wait for that payment to finish, then check its status.

If the other purchase was this same order, do not buy again unless its status is failed. This matters most when your own system sent the order twice: the second request is refused, and a new reference sent later, after the 10-minute duplicate window, would buy a second time.

The reference you sent with the refused request now reads failed. That describes the refused request only. It says nothing about the other purchase, so look that one up by its own reference.

202 OUTCOME_UNKNOWN: not known yet ​

success is false and data.status is unknown or processing. The provider did not give a clear answer, so the money is held: not spent, not returned.

  • Do not buy again, with this reference or a new one. The customer may already have received the product.
  • Check the status with the same reference. It moves to processed or failed when the purchase is reconciled, by an automatic check or by Xash staff. That can take minutes or longer.
  • Tell your customer the purchase is being confirmed.

What to do in each case ​

send the purchase with reference R
│
├─ 200                          → delivered. Done.
├─ 409 REFERENCE_CONFLICT       → R belongs to an earlier purchase. Do not buy again:
│                                 GET transactions/status?reference=R
├─ DUPLICATE_TRANSACTION / DUPLICATE_PURCHASE / METER_BUSY / PURCHASE_IN_PROGRESS
│                               → another purchase exists and may have been
│                                 delivered, be held or still be running.
│                                 Check it before buying again.
├─ any other 4xx / 503 with error_code
│                               → failed. Done. (Retry needs a NEW reference.)
├─ 422 with "errors", or 404    → fix the request. R is still free.
├─ 202 OUTCOME_UNKNOWN          → wait, then GET transactions/status?reference=R
└─ timeout / no answer / 502 / 504
        → send the SAME request again with R, or
          GET transactions/status?reference=R

For the last two branches, check again with growing gaps: for example after 5 seconds, 15 seconds, 1 minute, then every few minutes. Stay inside the rate limit.

A purchase that stopped half-way ​

If a request died on Xash's side before it finished, its reference would otherwise stay processing forever. Fifteen minutes after it was created, such a purchase is settled on the next lookup or repeat:

  • if nothing had been charged, it becomes failed with NOT_SENT;
  • if money had been taken, it becomes unknown and waits for reconciliation.

So processing never lasts more than about 15 minutes.

Example: a timeout, handled ​

bash
# First attempt: the connection drops, you get no answer.
curl -X POST https://app.xash.co.zw/api/v1/electricity/buy-tokens \
  -H "Authorization: Bearer YOUR_SERVER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"meter_number":"01234567890","amount":10,"currency":"USD","reference":"order-2001"}'

# Ask what happened.
curl "https://app.xash.co.zw/api/v1/transactions/status?reference=order-2001" \
  -H "Authorization: Bearer YOUR_SERVER_TOKEN"
The lookup answersThen
404 REFERENCE_NOT_FOUNDThe first request never arrived. Send it again with the same reference.
status: processedIt worked. The token is in data.fulfilment. For a voucher purchase the PINs are there.
status: failedIt failed and you were not charged. Retry with a new reference if you wish, unless error_code points at an earlier purchase.
status: processing or unknownWait and look again. Do not buy again.