Appearance
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
| Purchase | Field | Lookup |
|---|---|---|
| Direct airtime | reference | GET /api/v1/transactions/status |
| Airtime vouchers | reference | GET /api/v1/transactions/status |
| Bundles | reference | GET /api/v1/transactions/status |
| Bundle vouchers | reference | GET /api/v1/transactions/status |
| ZESA tokens | reference | GET /api/v1/transactions/status |
| DStv payments | reference | GET /api/v1/transactions/status |
| WiFi vouchers | client_reference | GET /api/v1/wifi/vouchers/purchases/{reference} |
| Deposits | request_id | The 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 | |
|---|---|
| Length | 1 to 120 characters. |
| Characters | Letters, digits, and : . _ -. No spaces. |
| Scope | Unique 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. |
| Lifetime | Kept 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:
| Product | Details that must match |
|---|---|
| Airtime | Phone number, amount, currency |
| Airtime vouchers | Network, voucher value, quantity, currency, is_vendor_voucher |
| Bundles | Bundle, phone number |
| Bundle vouchers | Bundle, quantity |
| ZESA | Meter number, amount, currency |
| DStv | Smartcard number, package |
Then:
| You send | You get |
|---|---|
| A new reference | The purchase runs. |
| The same reference, same details, first request finished | The same answer as the first time, with the same status code. Nothing runs. |
| The same reference, same details, first request still running | 202 OUTCOME_UNKNOWN with data.status of processing. Nothing runs. |
| The same reference, different details | 409 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
422validation error (a body witherrorsand noerror_code); - a
404for a bundle or network id that does not exist; 422 RECIPIENT_INVALIDfrom a bundle purchase, whosedataholds only yourreference. (For ZESA,RECIPIENT_INVALIDis 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.
| Code | What it means | Before you buy again |
|---|---|---|
409 REFERENCE_CONFLICT | This 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
processedorfailedwhen 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=RFor 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
failedwithNOT_SENT; - if money had been taken, it becomes
unknownand 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 answers | Then |
|---|---|
404 REFERENCE_NOT_FOUND | The first request never arrived. Send it again with the same reference. |
status: processed | It worked. The token is in data.fulfilment. For a voucher purchase the PINs are there. |
status: failed | It 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 unknown | Wait and look again. Do not buy again. |