Documentation
Backend Integration

Backend Integration

This page provides instructions on setting up four webhooks required for integrating your backend with the Hexzard API. These webhooks can be implemented using any server-side language or technology. Below are the details of each webhook:

  1. Game Session Webhook

    This webhook initializes a game session for a client.

    • URL: /session
    • Method: POST
    • Parameters: None

    Logic:

    • Retrieve the unique identifier for your client.
    • Implement the logic to create a game session by utilizing the necessary API endpoint.
    • Send a JSON response with the created session.

    Response:

    The response should be in JSON format with the following structure:

    {
      "result": {
        "data": {
          "json": {
            "createdSession": "<session_data>"
          }
        }
      }
    }

    Replace <session_data> with the actual session data.

  2. Balance Webhook

    This webhook retrieves the balance for a client.

    • URL: /balance
    • Method: POST
    • Parameters:
      • clientId (string): The unique identifier of the client.

    Logic:

    • Verify the game request by implementing the necessary validation steps.
    • Retrieve the client's balance from your backend using the provided clientId.
    • Send a JSON response with the client's balance.

    Response:

    The response should be in JSON format with the following structure:

    {
      "result": {
        "data": {
          "json": {
            "balance": <client_balance>
          }
        }
      }
    }

    Replace <client_balance> with the actual client's balance.

  3. Bet Webhook

    This webhook processes a bet for a client.

    • URL: /bet
    • Method: POST
    • Parameters:
      • betAmount (number): The amount to bet.
      • gameName (string): The name of the game.
      • transactionId (string): The unique identifier for the transaction.
      • clientId (string): The unique identifier of the client.

    Logic:

    • Verify the game request by implementing the necessary validation steps.
    • Retrieve the client's information and perform the required checks, such as balance verification, using the provided clientId.
    • If the bet is allowed, process the bet by deducting the bet amount from the client's balance and storing the bet details.
    • Generate the platform seed required for the game.
    • Send a JSON response indicating whether the bet is allowed and providing the platform seed.

    Response:

    The response should be in JSON format with the following structure:

    {
      "result": {
        "data": {
          "json": {
            "betAllowed": <bet_allowed>,
            "operatorSeed": "<platform_seed>"
          }
        }
      }
    }

    Replace <bet_allowed> with true or false depending on whether the bet is allowed, and <platform_seed> with the actual platform seed if the bet is allowed.

  4. Outcome Webhook

    This webhook handles the outcome of a bet.

    • URL: /outcome
    • Method: POST
    • Parameters:
      • transactionId (string): The unique identifier for the transaction.
      • multiplier (number): The outcome multiplier.

    Logic:

    • Verify the game request by implementing the necessary validation steps.
    • Retrieve the client's information using the provided transactionId.
    • Calculate the

payout based on the bet amount and the outcome multiplier.

  • Update the client's balance with the payout.
  • Send a JSON response indicating that the bet has been paid.

Response:

The response should be in JSON format with the following structure:

{
  "result": {
    "data": {
      "json": {
        "betPaid": true
      }
    }
  }
}

Replace <betPaid> with true to indicate that the bet has been paid.

Server Configuration

To set up the server to handle these webhooks, follow these steps:

  1. Install the required dependencies according to your chosen server-side language or technology.

  2. Create a new file, e.g., server.js, and implement the necessary logic to handle the webhooks.

  3. Replace the placeholder values in the code with the appropriate URLs, secrets, and logic specific to your backend implementation.

  4. Save the file and start the server using the corresponding command or method for your chosen server-side language or technology.

Testing the Webhooks

To test the webhooks, you can use tools like cURL or Postman to send HTTP requests to the server's endpoints.

Make sure to include the necessary headers and request body parameters according to each webhook's requirements.

Example cURL command for the /session webhook:

curl -X POST http://localhost:3001/session

Example cURL command for the /balance webhook:

curl -X POST -H "x-hexzard-signature: <signature>" -H "x-hexzard-request-timestamp: <timestamp>" -H "Content-Type: application/json" -d '{"json": {"clientId": "<client_id>"}}' http://localhost:3001/balance

Replace <signature>, <timestamp>, and <client_id> with the appropriate values.

Repeat the same process for the /bet and /outcome webhooks, adjusting the headers and request body parameters accordingly.

You have now set up the four webhooks required for your service. You can integrate these webhooks into your application or service to handle various events and interactions with the Hexzard API.


Hexzard Docs