Callbacks
An agent in SEAMLESS mode holds its members' money. Every time a game moves a member's money, best-superapi sends a callback to the agent's wallet, and the agent applies it. This page is the contract of those callbacks, version 1. Every field and every example is also in the OpenAPI file under webhooks; the examples named below live there.
Agents in TRANSFER mode receive no callbacks: their members' money is held by best-superapi.
The 10 callbacks
Each callback is POST {callback_url}/api/{path}, where callback_url is the address on the agent's API credential.
| Path | Money | Used when |
|---|---|---|
balance |
none | We need the member's balance |
bet |
debit amount |
A member places a bet |
settle |
credit amount, or credit or debit amount by direction when single_state is true |
A bet's result is paid |
refund |
credit the stake your wallet holds for the bet (we send it as amount when we hold the bet) |
The provider cancels or rejects a bet and gives the stake back |
reward |
credit amount |
A jackpot or bonus outside any bet |
rollback |
debit what the bet's settle or refund credited | The provider undoes a bet's result |
void |
credit or debit amount by direction |
The provider cancels a settled bet, or a whole round with its rewards |
tip |
debit amount |
A member tips the dealer |
cancel-tip |
credit amount |
A tip is given back |
adjust |
credit or debit amount by direction |
An open bet's stake changes, or a game played without bets (such as fishing games) changes the balance |
What each path asks of the wallet, field by field, is in the description of its webhook in the OpenAPI file.
The callback URL
https://only, with no query, no fragment and no user name or password in it.- Every address it resolves to must be public.
- We do not follow redirects: a 3xx answer counts as a failed callback, even though the request reached you.
Headers and signature
| Header | Value |
|---|---|
Content-Type |
application/json |
X-Api-Key |
The API key of your API credential |
X-Timestamp |
Unix time in seconds when we signed the request |
X-Signature |
Lowercase hex of HMAC-SHA256, keyed with the secret of your API credential, over {X-Timestamp}.{raw body} |
X-Contract-Version |
1 |
To check a request:
- Read the raw body exactly as received. Never parse and serialize it again before checking.
- Compute HMAC-SHA256 of the X-Timestamp value, a dot (
.), then the raw body, with your secret as the key. Compare it with X-Signature in constant time. - Answer 30002 when the signature does not match, or when X-Timestamp is more than 300 seconds away from your clock in either direction.
- Answer 40003 when X-Api-Key is not your key.
It is the same signature as on the requests you send us. We sign every request when we send it, a resend included, so a resend always carries a fresh X-Timestamp. There is no nonce: the resend rules keep a repeated request from moving money twice.
The request
Every callback carries the same envelope. balance has no txns; every other path has at least one.
| Field | Meaning |
|---|---|
request_id |
A new id for every request we send, a resend included. For matching logs only, never for spotting a resend. |
external_player_id |
Your id of the member, as you sent it to launch. Find the balance in your wallet by it together with currency. |
player_username |
Our username of the member, for support. Never find the member by it. |
currency |
The member's currency. Every amount in the request is in it. |
provider_code |
The provider's code, the code of the provider in the catalog |
timestamp |
Unix time in milliseconds when we built the request |
txns |
The movements to apply, all or nothing |
external_player_id and provider_code are always present, and null when we do not know them. A null external_player_id is the same case as an unknown member: answer 10001, and no money moves. A balance for an external_player_id in a currency you do not hold for it is an unknown member too: answer 10001. player_username is defined in how you name a member.
Amounts are JSON numbers in the major unit of currency, with at most as many decimals as the currency has (THB 2, JPY 0, KWD 3). An amount is never negative: the path or direction says which way it moves. An amount of 0 is valid (a free spin, a lost bet's payout) and must be answered like any other.
The fields of a txn are in the Txn schema. is_feature is on every txn (a free or feature spin). The ones that need care:
game_codeis our code of the game andprovider_game_codethe provider's own; both are on every txn, null when unknown.game_codedescribes the game and is never a key: it can change between sends without making different content. The full rule is in bet records.statusis the bet's state as the provider reports it:OPENandWAITINGonbet,SETTLEDonsettle,REFUNDorREJECTonrefund,ROLLBACKonrollback,VOIDonvoidandTIPSontip. It is for your records. How money moves is decided by the path,direction,skip_balance_updateandtransaction_type, never bystatus.reward,cancel-tipandadjustmay carry nostatus; that changes nothing. A value you do not know must be accepted.transaction_type, onsettle,refund,rollbackandvoid, isBY_TRANSACTION(only the bet ofref_txn_id, or oftxn_idwhen it is null) orBY_ROUND(every bet ofround_id). OnBY_ROUND,amountis the round's total: move it once, record it against the round, and mark every bet of the round. On avoid, the round'srewardcredits are part of the round too (void and rewards). Absent meansBY_TRANSACTION.skip_balance_update: truemoves no money: answer 0 with the current balance. On abetyou already applied it confirms that bet: the provider's confirmation of a sports bet comes this way (examplessportsWaitingandsportsConfirmedofbet). On abetyou never applied it is a bet the provider records only, its money moving through other requests (for example a stake and a payout sent asadjust): record the bet with no stake taken, so itssettlewithskip_balance_update: truefinds it, and answer 0 (examplerecordOnlyofbet). Never answer 10002 to it. Such a bet holds only the money that moves through it: arefundof it gives no stake back, and arollbacktakes back only what a settle of it paid.single_state: trueonsettlemeans the stake and the result come in this one call with nobetbefore it. Applyamount, which ispayout_amountminusbet_amount, indirection, and check that the balance coversbet_amount(examplesingleState).is_feature: trueonsettleis a free or feature spin. A free spin withtransaction_type: BY_ROUNDand atxn_idof its own adds itsamountto the round, even when the round is already settled: apply it, and never answer 20001 because the round is settled (examplefreeSpin). A free spin withtransaction_type: BY_TRANSACTIONand atxn_idof its own adds itsamountto the bet ofref_txn_idlike a part does (a bet's life, examplefreeSpinByTransaction).ref_txn_idonsettleis the bet the settle pays, sent whenever we hold that bet: the bet's owntxn_id, or the bet a settle under atxn_idof its own pays (a free spin or a part by transaction, or a provider whose settle ids are not its bet ids). Find the bet by it. It is null when we hold no bet for the settle (asingle_statesettle, or aBY_ROUNDsettle under atxn_idof its own). ABY_ROUNDsettle acts on every bet ofround_ideven whenref_txn_idnames one.is_end_roundonsettlemarks a settle that comes in parts:falsefor a part that more parts follow,truefor the last one. Absent means the settle comes in one piece (examplefirstPart). Each part has atxn_idof its own. A free spin or asingle_statesettle may carryis_end_roundtoo; it does not close the bet to further parts (a bet's life).rollback_countis how many times the bet was rolled back before this request. The firstrollbackof a bet carries 0, and the new result that follows it carries 1 (examplesrollbackandresettleofrollback).callback_idis the provider's id of the callback the txn came in, for your records. It is not part of the resend key: a provider may send a txn again under a newcallback_id.ref_txn_idis the bet or tip the request acts on, and it may equaltxn_id. Find the bet byref_txn_id, or bytxn_idwhenref_txn_idis null; never refuse a request because it is null.- On
adjust, every change has its owntxn_id. A txn withbet_amountchanges the stake of the bet inref_txn_id, andbet_amountis its new total stake (exampleraiseStake). A txn withoutbet_amountchanges the balance of a game played without bets: apply it, there is no bet to find (examplefishingWin). A change of stake withskip_balance_update: truemoves no money and leaves the stake your wallet holds for the bet as it was, whateverbet_amountit names: a laterrefundgives back that stake.
The reply
Answer every outcome with HTTP 200 and a JSON body. Any other HTTP status counts as a failed callback, whatever the body says.
| Field | When |
|---|---|
code |
Always. An integer from the table below. |
balance |
balance path. Required when code is 0. |
balance_before, balance_after |
Every other path, on every outcome: equal when no money moved, and 0 on 10001, 30002 and a 40003 for a wrong API key |
currency |
Optional echo. A currency other than the request's fails the callback. |
request_id |
Optional echo |
message |
Optional reason for a refusal, most useful with 40003 |
A success that lacks its balance, or a code that is not an integer, counts as a failed callback. Examples of every reply are under TxnReply in the OpenAPI file.
Codes
The codes are ours and stay the same whichever provider the game comes from. Apart from 0 they have five digits, unlike the four-digit codes of the endpoints you call.
| Code | Meaning | Paths |
|---|---|---|
0 |
Success, or a resend of something already applied | All |
10001 |
No member with this external_player_id, or it is null |
All |
10002 |
The balance does not cover new money in play | bet, tip, settle with single_state: true, adjust with direction: DEBIT |
20001 |
The bet or tip the request acts on is unknown, or not in a state that path applies to (a bet's life) | settle, refund, rollback, void, cancel-tip, adjust of a stake |
20002 |
A known key with a different amount or direction |
Every path with txns |
30002 |
The signature does not match, or X-Timestamp is too far from your clock | All |
40003 |
Not your API key (all paths), or new money in play refused by your own rules (a suspended member, a currency you do not hold, an amount you do not accept), with an optional message |
All for the API key; bet, tip, settle with single_state: true and adjust with direction: DEBIT for your rules |
50001 |
Your wallet could not process the request | All |
For a member your wallet can find, results and reversals are never refused for lack of balance or by your own rules: settle (unless single_state is true), refund, reward, rollback, void, cancel-tip and adjust with direction: CREDIT must be applied, even for a suspended member. A rollback, or a void with direction: DEBIT, must be applied even when the member's balance goes below zero.
Time to answer
Answer within 3 seconds. We stop waiting after 4 seconds and count the callback as failed. A failed callback is not retried by us: the provider sends it again, so a request can reach you more than once.
A bet's life
A bet is open after its bet, and a settle with single_state: true makes a bet that is already settled. A bet's rollback_count starts at 0, and a rollback that carries n makes it n + 1. First check the resend key: a resend is answered by the resend rules. Otherwise each path applies to a bet in these states only, and anything else is answered 20001 and moves no money:
| Path | Applies to a bet that is | Then the bet is |
|---|---|---|
settle |
open, or being settled in parts (every part so far had is_end_round: false). A bet settled in one piece, by a free spin or by a single_state settle still takes a part (a settle that carries is_end_round, or a free spin with transaction_type: BY_TRANSACTION) with a txn_id of its own. A bet that a part with is_end_round: true, not a free spin, settled takes none. Any other settle of a new txn_id on a settled bet is answered 20001, except a free spin (is_feature: true) with transaction_type: BY_ROUND and a txn_id of its own, which applies in both cases. |
settled, or still being settled when is_end_round is false |
refund |
open | refunded |
rollback |
settled, being settled in parts, or refunded | open again |
void |
open or settled; with transaction_type: BY_ROUND, a round that holds such a bet or a reward not voided yet |
voided, for good |
cancel-tip |
a tip you applied and have not given back | given back |
adjust with bet_amount |
open | still open, with the new stake (the stake it had when skip_balance_update is true) |
A refund gives back the stake your wallet holds for the bet: what its bet debited, or the new total after an adjust that changed the stake (one with skip_balance_update: true changes nothing). When we hold the bet we send that stake as amount (with transaction_type: BY_ROUND, the sum of the stakes of the round's open bets), so it is the figure to credit. When we hold no such bet, amount is the provider's figure: credit the stake your wallet holds, and answer 20001 when it holds no such bet. bet_amount is the provider's figure and may differ, for example when the provider asks for more than was staked: never credit a different amount than the stake your wallet holds. A resend of a refund you applied carries the same amount as the first, and another amount under the same key is a conflict (resends).
A rollback takes back everything your wallet credited for the bet since it was last open: the payout of every part of a settle in parts and of every free spin received so far, the payout_amount of a single-state settle (never its net), or the refunded stake. Use what your wallet recorded; amount and bet_amount on the rollback are the provider's figures. A settle or refund with skip_balance_update: true credited nothing, so there is nothing of it to take back. When the bet was settled or refunded BY_ROUND, a rollback of any bet of that round takes back the round's amount once and opens every bet of the round.
A request with an older rollback_count than the bet's is answered 20001.
Callbacks of a bet can arrive out of order. Answer by the state your wallet holds, as above, and never move money for a request the table does not allow.
Void and rewards
A reward does not belong to a bet, so a rollback never takes it back. A void with transaction_type: BY_ROUND does: the provider has cancelled the whole round, and the rewards paid on it go with it. Apply it when your wallet holds, for round_id, a bet that is open or settled or a reward that is not voided yet, even when the round has no bet and only rewards (never answer 20001 for that case). A round whose bets are all refunded or voided and that holds no reward to void is answered 20001. Move the one amount and direction we send, and nothing else, and mark every bet and reward of the round as voided. A void with transaction_type: BY_TRANSACTION acts on the bet of txn_id only and leaves the rewards alone.
When a settle or a reward that a void covers came with skip_balance_update: true and credited nothing, the void's payout_amount is the provider's payout but no more than the settled bets and rewards it covers were credited: a reward really paid in the same round is still taken back (example skipSettled: the stake back, nothing taken). In every other case payout_amount is the provider's. This does not apply when what the void covers holds a bet the provider records only (a bet with skip_balance_update: true you never applied, or a settle with single_state: true and skip_balance_update: true and no bet before it): there the provider's figures stand. bet_amount is the provider's stake, and amount and direction are the net of the two. A void with skip_balance_update: true carries the same figures and moves nothing. A void we send again carries the amount and direction of its first send, with the provider's bet_amount and the payout_amount that make that net (when that net gives back more than the stake, bet_amount is the net and payout_amount 0). Move the amount and direction we send, as on every void.
All or nothing
Apply every txn of a request in one transaction. When one txn fails, move no money for any of them and answer that failure with balance_before equal to balance_after.
Resends
The provider sends a callback again when it did not get our answer in time, and we send it to you again. A resend carries the same txns as the first time, with the same txn_id, rollback_count and is_end_round, and a new request_id, timestamp and signature. Its callback_id may differ.
Key each txn, not each request, on path, txn_id and rollback_count.
A txn whose key you have already applied is a resend, and it moves no money. When every txn of a request is a resend, answer:
- 0 with the current balance (
balance_beforeequal tobalance_after), moving no money, when itsamountanddirectionare the ones you applied; - 20002, moving no money, when the
amountordirectionof one of them differs.
A request that mixes resent and new txns applies the new ones and answers 0. One txn with 20002 fails the whole request (all or nothing).
Other fields (status, flags, play_info, game_code, ref_txn_id) may differ under the same key and do not make it a conflict. A settle whose txn_id is not its bet's (a free spin or a part under a txn_id of its own) that we sent before comes again with the rollback_count of its first send, even after its bet or its round was rolled back: it is a resend of that key, not a new result. A txn with skip_balance_update: true moves no money.
skip_balance_update may differ between the sends of one key, and the key is still a resend: it moves no money, whichever send carried the flag. A resend with skip_balance_update: true is never a conflict: answer it 0, whatever its amount or direction. A resend without it, of a key first sent with skip_balance_update: true, moves nothing either and is answered by the rules above. A refund or a void carries the same amount and direction on every send of its key, the one with skip_balance_update: true included.
Why each part of the key matters:
path, because a bet'sbet,settleandrollbackshare onetxn_id.rollback_count, because after arollbackthe new result comes with the sametxn_id. A bet can be rolled back more than once, so never accept "one repeat" as a rule.- Never
callback_id: each part of a settle in parts has atxn_idof its own, and a provider may send a txn again under a newcallback_id.
Still being confirmed with providers
A few edge cases depend on how a provider behaves, and we are still confirming them with providers. Build your wallet on what this page says today for each of them:
| Case | What to implement now |
|---|---|
| A provider resends a callback: does it reuse its own id? | callback_id may differ on a resend. Key on path, txn_id and rollback_count, never on callback_id (resends). |
A round settled with transaction_type: BY_ROUND is rolled back: does the rollback cover the whole round, or come per bet? |
A rollback of any bet of the round takes back the round's amount once, as your wallet recorded it, and opens every bet of the round (a bet's life). |
A void with transaction_type: BY_ROUND of a round that has rewards: does its amount include the rewards? |
Move the one amount and direction we send, and nothing else, and mark every bet and reward of the round as voided (void and rewards). |
A reward arrives on a round already voided BY_ROUND: does a second void follow? |
Apply the reward, as every reward is applied (codes). A later void with transaction_type: BY_ROUND of that round applies while your wallet holds a reward of it not voided yet: move the amount we send (void and rewards). |
If a provider's answer differs, we change version 1 by additions only, so X-Contract-Version stays 1, and we tell agents what changed (versions).
Versions
Every request carries X-Contract-Version: 1. Version 1 only grows by additions, such as new fields or new values of status. Ignore any field you do not know, and never refuse a request because of one. A change that would break an agent built on version 1 comes as a new major version, announced ahead.