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

# Rollback

> This API is used to rollback a player's transaction. The Operator is expected to find the referenced transaction, roll back its effects.

```http theme={null}
  POST  /transaction/rollback
```

## Common causes includes

* Server failure

* Bet processed after the round started

* Internal server errors

* Invalid or incorrect data

## Headers

<ParamField header="x-api-key" type="string" required>
  A unique identifier associated with operator calling API.
</ParamField>

<ParamField header="x-signature" type="string" required>
  A SHA256 HMAC signature generated using the request body and timestamp.
  Format: HMAC\_SHA256(JSON.stringify(data) + '|' + timestamp), signed using the
  provided secret key.
</ParamField>

<ParamField header="x-timestamp" type="string" required>
  An Unix timestamp (milliseconds) when the request was sent. Ensure the same
  value is used in signature generation.
</ParamField>

<ParamField header="content-type" type="string" required>
  Must be set to `application/json`
</ParamField>

## Request Body

<ParamField body="transactions" type="array" required>
  <Expandable title="properties">
    <ParamField body="transactionId" type="string" required>
      The unique transaction identifier. An action with same transactionId shouldn't be processed more than once.
    </ParamField>

    <ParamField body="refTransactionId" type="string" required>
      An identifier of the transaction that this transaction is referencing. this field will contain transactionId of the transaction which needs to be rolled back, it can be any transaction like bet, payout  etc.
    </ParamField>

    <ParamField body="sessionId" type="string" required>
      An identifier for the player session in which this transaction happened.
    </ParamField>

    <ParamField body="playerId" type="string" required>
      Unique identifier for the player.
    </ParamField>

    <ParamField body="gameId" type="string" required>
      Unique identifier for the game.
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="status" type="string" required>
  Code indicates status of the request weather it is succeed or failed. We have listed error codes <a href="/introduction#error-codes">here</a>
</ResponseField>

<ResponseField name="data" type="Data Array">
  <Expandable title="properties">
    <ResponseField name="status" type="string" required example="RS_OK">
      Status of the individual transaction.
    </ResponseField>

    <ResponseField name="transactionId" type="string" required example="21848853-1198-4dde-9a21-bb9598398a8c">
      The unique transaction identifier.
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash Shell theme={null}
  curl --request POST \
    --url 'https://partner-platform-url/transaction/rollback' \
    --header 'content-type: application/json' \
    --header 'x-api-key: <x-api-key>' \
    --header 'x-signature: <x-signature>' \
    --header 'x-timestamp: <x-timestamp>' \
    --data '{
      "transactions": [
        {
          "transactionId": "21848853-1198-4dde-9a21-bb9598398a8c",
          "refTransactionId": "dd96bda3-9990-4aed-9679-f451a4b82ac4",
          "sessionId": "9f9ea8fd09face7f2b44c819665d09a32250e150c6e95c7d0ba9af774740c98w30041199695697d324efbe3ffc1e0a79",
          "playerId": "18865671",
          "gameId": "G1720761376617",
        }
      ]
  }'
  ```

  ```javascript NodeJS theme={null}
  const axios = require('axios');

  const url = 'https://partner-platform-url/transaction/rollback';
  const headers = {
      'content-type': 'application/json',
      'x-api-key': '<x-api-key>',
      'x-signature': '<x-signature>',
      'x-timestamp': '<x-timestamp>'
  };
  const data = {
      transactions: [
          {
              transactionId: "21848853-1198-4dde-9a21-bb9598398a8c",
              refTransactionId: "dd96bda3-9990-4aed-9679-f451a4b82ac4",
              sessionId:"9f9ea8fd09face7f2b44c819665d09a32250e150c6e95c7d0ba9af774740c98w30041199695697d324efbe3ffc1e0a79"
              playerId: "18865671",
              gameId: "G1720761376617"
          }
      ]
  };

  axios.post(url, data, { headers })
      .then(response => console.log(response.data))
      .catch(error => console.error(error));

  ```

  ```python Python theme={null}
  import requests

  url = "https://partner-platform-url/transaction/rollback"
  headers = {
      "content-type": "<content-type>",
      "x-api-key": "<x-api-key>",
      "x-signature": "<x-signature>",
      "x-timestamp": "<x-timestamp>"
  }
  data = {
      "transactions": [
          {
              "transactionId": "21848853-1198-4dde-9a21-bb9598398a8c",
              "refTransactionId": "dd96bda3-9990-4aed-9679-f451a4b82ac4",
              "sessionId":"9f9ea8fd09face7f2b44c819665d09a32250e150c6e95c7d0ba9af774740c98w30041199695697d324efbe3ffc1e0a79"
              "playerId": "18865671",
              "gameId": "G1720761376617"
          }
      ]
  }

  response = requests.post(url, headers=headers, json=data)
  print(response.json())

  ```

  ```php PHP theme={null}
  <?php
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://partner-platform-url/transaction/rollback",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
      "content-type: <content-type>",
      "x-api-key: <x-api-key>",
      "x-signature: <x-signature>",
      "x-timestamp: <x-timestamp>"
    ],
    CURLOPT_POSTFIELDS => json_encode([
      "transactions" => [
        {
          "transactionId" => "21848853-1198-4dde-9a21-bb9598398a8c",
          "refTransactionId" => "dd96bda3-9990-4aed-9679-f451a4b82ac4",
          "playerId" => "18865671",
          "gameId" => "G1720761376617"
          "sessionId" => "9f9ea8fd09face7f2b44c819665d09a32250e150c6e95c7d0ba9af774740c98w30041199695697d324efbe3ffc1e0a79"
        }
      ]
    ]),
  ]);

  $response = curl_exec($curl);
  curl_close($curl);

  echo $response;
  ?>

  ```
</RequestExample>

<ResponseExample>
  ```json SUCCESS theme={null}
  {
      "status": "RS_OK",
      "data": [
        {
          "status": "RS_OK",
          "transactionId": "21848853-1198-4dde-9a21-bb9598398a8c"
        }
      ]
  }
  ```

  ```json SUCCESS FAILURE 1 theme={null}
  {
      "status": "RS_OK",
      "data": [
        {
          "status": "RS_ERROR_DUPLICATE_TRANSACTION",
          "transactionId": "21848853-1198-4dde-9a21-bb9598398a8c",
          "balance": 5000000
        }
      ]
  }
  ```

  ```json FAILURE theme={null}
  {
    "status": "RS_ERROR",
    "message": "Oops! Something went wrong. Please refresh the page or try again in a moment"
  }
  ```
</ResponseExample>
