# Cancel Bonus

Cancels a bonus given with **Create Bonus**, and gives back to your agent balance what it has not paid.

- **Waiting** (its round has not started): canceled at once, and all of `amount` comes back.
- **Running** (the user is in its round): it can be canceled only once the user has left that round alone for a day. Then the round is ended, and what the bonus has not paid comes back. Before that, the cancel fails with `BONUS_IN_PROGRESS`.
- **Finished or canceled**: nothing left to cancel.

### Endpoint

```
POST https://api.nexusggr.com
```

**Content-Type:** `application/json`

### Request

**Method:** `bonus_cancel`

```json
{
    "method": "bonus_cancel",
    "agent_code": "your_agent_code",
    "agent_token": "your_agent_token",
    "user_code": "test",
    "game_code": "vs20doghouse",
    "bonus_id": "bonus_777"
}
```

| Field         | Type   | Required | Description                                           |
| ------------- | ------ | -------- | ----------------------------------------------------- |
| `method`      | string | Yes      | Must be `bonus_cancel`                                |
| `agent_code`  | string | Yes      | Your agent code                                       |
| `agent_token` | string | Yes      | Your agent API token                                  |
| `user_code`   | string | Yes      | The user the bonus was given to                       |
| `game_code`   | string | Yes      | The game the bonus was given on                       |
| `bonus_id`    | string | Yes      | The `bonus_id` sent in `bonus_create`                 |

`user_code`, `game_code` and `bonus_id` must all match the bonus as it was created.

### Response

#### Success

```json
{
    "status": 1,
    "code": 7777777,
    "msg": "SUCCESS",
    "bonus_id": "bonus_777",
    "user_code": "test",
    "provider_code": "PRAGMATIC",
    "game_code": "vs20doghouse",
    "total_win": 0,
    "canceled_money": 50000
}
```

| Field            | Type   | Description                                                    |
| ---------------- | ------ | -------------------------------------------------------------- |
| `total_win`      | number | What the bonus paid before it was canceled                     |
| `canceled_money` | number | What came back to your agent balance with this cancel          |

#### Failure

```json
{
    "status": 0,
    "code": 7770027,
    "msg": "There is no such bonus."
}
```

```json
{
    "status": 0,
    "code": 7770502,
    "msg": "External Error : BONUS_IN_PROGRESS"
}
```

| Code      | Description                                                                                         |
| --------- | --------------------------------------------------------------------------------------------------- |
| `7770027` | No bonus with this `bonus_id` for this user and game, or it is already over. `msg` then says how, for example `There is no such bonus. (bonus_id bonus_777 is finished)` |
| `7770407` | The bonus's provider no longer exists                                                               |
| `7770500` | Internal error                                                                                      |
| `7770502` | The game server did not cancel the bonus. The text after `External Error : ` says why (table below) |

| Reason                                   | Description                                                            |
| ---------------------------------------- | ---------------------------------------------------------------------- |
| `BONUS_IN_PROGRESS`                      | The user is in the bonus round and was active in it within the last day |
| `BONUS_NOT_FOUND`                        | The game server has no open bonus with this `bonus_id`                 |
| `PLAYER_BUSY`                            | The user's game was busy with a request. Try again                     |
| `bonus_id <id> is still being created, try again later` | The create of this bonus has not finished yet           |
