> ## Documentation Index
> Fetch the complete documentation index at: https://docs.igamingace.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bet

当玩家下注时，会发送`“bet”`回调函数。您的服务器必须从玩家余额中扣除投注金额，并返回更新后的余额。该操作是幂等的——如果您的钱包收到多个具有相同 `transactionId` 的请求，必须只登记一次该交易。

***无需在回调 URL 末尾添加“Bet”；您可以获取请求正文“command”来识别哪个回调即将到来。***

* **URL:** 您配置的回调 URL(ex: [***https://mycallback.com/cb***](https://mycallback.com/cb))
* **Method:** POST
* **Headers:** `X-Request-Signature`, `Content-Type`, `Accept`

## Request parameters

<ParamField body="command" type="string" required>
  此回调类型始终为 `"bet"`
</ParamField>

<ParamField body="transactionId" type="long" required>
  我们系统中创建的交易唯一引用。用于保证幂等性
</ParamField>

<ParamField body="playerId" type="string" required>
  您系统中玩家的唯一标识
</ParamField>

<ParamField body="roundId" type="long" required>
  游戏局的唯一引用
</ParamField>

<ParamField body="providerId" type="number" required>
  我们系统中游戏提供商的唯一标识
</ParamField>

<ParamField body="gameCode" type="int" required>
  我们系统中该游戏的唯一游戏 ID
</ParamField>

<ParamField body="currency" type="string" required>
  玩家货币代码，符合 ISO-4217（例如 `EUR`、`USD`）
</ParamField>

<ParamField body="amount" type="number" required>
  需从玩家余额中扣除的投注金额
</ParamField>

<ParamField body="isBonusBusy" type="bool" required>
  表示玩家是否获得奖金。
</ParamField>

<ParamField body="bonusId" type="long" required>
  0：无奖金，否则为相关奖金 ID
</ParamField>

<ParamField body="timestamp" type="number" required>
  请求的 Unix 时间戳
</ParamField>

## Response fields

您的服务器必须以 HTTP 200 响应，并在 JSON 正文中包含以下字段：

<ResponseField name="balance" type="number" required>
  扣除投注后玩家的更新余额
</ResponseField>

<ResponseField name="statusCode" type="string" required>
  操作结果。成功时必须为 `"OK"`。所有可能的值见下方状态码表
</ResponseField>

## Status codes

| 状态码                          | 说明        |
| :--------------------------- | :-------- |
| `OK`                         | 请求成功      |
| `ERR_NOT_AUTHENTICATED`      | 玩家未通过身份验证 |
| `ERR_NOT_ENOUGH_MONEY`       | 玩家账户资金不足  |
| `ERR_INTEGRITY_CHECK_FAILED` | 消息完整性校验失败 |
| `ERR_UNKNOWN`                | 内部服务器错误   |

<Warning>
  您的响应必须在 3 秒内 返回。若请求超时或返回错误，我们不会重试——而是会发送 `cancel` 回调以回滚该游戏局。投注失败也会取消当前局，阻止玩家继续进行。
</Warning>

## Examples

<CodeGroup>
  ```json Request theme={null}
  {
    "command": "bet",
    "transactionId": "SP215202",
    "playerId": "player_88888",
    "roundId": "65215842315484512",
    "providerId": 1,
    "gameCode": 655,
    "amount": 10,
    "isBonusBusy": false,
    "bonusId": 0,
    "timestamp": 1586335186372
  }
  ```

  ```json Success response theme={null}
  {
    "balance": 19839891,
    "statusCode": "OK"
  }
  ```

  ```json Error response theme={null}
  {
    "statusCode": "ERR_NOT_ENOUGH_MONEY",
    "balance": 19839895
  }
  ```
</CodeGroup>
