Betshop API

From BetgamesTV
Jump to navigation Jump to search

Scheme of work

BetShop API.png

Partner server sends API requests to BetGames.TV API server. BetGames.TV server responses accordingly.

Text encoding

All data sent and received should be in encoded in UTF-8.

Data Format

Both request and response data is JSON encoded.

Security

All authorized Interactions with BetGames.TV API servers should go through HTTPS only.

All the requests and responses should be signed using partner unique ID on and secret key credentials. Storing credentials is partner responsibility. It is not recommended embedding credentials into the code. Best practice is to store them in environment variables or config files on your servers.

Secret key could be regenerated at any time on partner request.

API requests should be firewalled by limited range of ip addresses.

Request format

Request URL format: <host>/ext/api/index/<method_name>/<partner_id>

Request example:

{
  "partner_id": 1424,
  "method": "ticket_check",
  "language": "en",
  "timestamp": 1425390869,
  "signature": "4e4c293148af9301c82d3b5bf1068b969819880a8e279d76a7dcb09de7440cff",
  "params": {
    "shop_id": 2347,
    "currency": "eur",
    "barcode": "150327383782"
  }
}

Request parameters:

  • partner_id - your partner id on BetGames.TV server.
  • method - method name you are calling
  • language - language 2-letters code, required for translating response information and messages.
  • timestamp - Unix timestamp, time of the request. BetGames.TV server will validate this time is not older than 10 seconds.
  • signature - request signature, will be generated using partner secret key and a set of sent parameters. Signature generation logic will be explained below.
  • params - array of additional parameters. Set of params depends on method.

Request signature generation Php example:

$signature_base = $partner_id . $method . $language . $timestamp . json_encode($params);
$signature = hash_hmac('sha256', $signature_base, $secret_key);

Response format

Response example:

{{
  "partner_id": 1424,
  "method": "ticket_check",
  "language": "ru",
  "timestamp": 1428499349,
  "signature": "8787a9d985eb461847c0cac2d73d2f86379ed8626c9c40bc6e354fffd0704997",
  "params": {
    "shop_id": 2347,
    "currency": "eur",
    "barcode": "150327383782"
  },
  "response": {
    "ticket_found": false,
    "paid_out": false,
    "amount": false
  },
  "response_code": 200,
  "error_message": false
}

Response parameters:

  • partner_id - your partner id on BetGames.TV server.
  • method - method name you are calling
  • language - language 2-letters code, required for translating response information and messages.
  • timestamp - Unix timestamp, time of the request. BetGames.TV server will validate this time is not older than 10 seconds.
  • signature - request signature, will be generated using partner secret key and a set of sent parameters. Signature generation logic will be explained below.
  • params - array of additional parameters of request.
  • response - array of response return values, depends on request method
  • response_code - code of the response, normally its 200, otherwise its a code of an error
  • error_message - false in case of success or text of an error otherwise.

Response signature generation Php example:

$signature_base = $partner_id . $method . $language . $timestamp . json_encode($params) . json_encode($response);
$signature = hash_hmac('sha256', $signature_base, $secret_key);

Betshop API methods

Common API methods

 

Response error codes

  • 200 - Success code.
  • 500 - Internal server error. Contact BetGames.TV engineer for details.
  • 501 - JSON was badly formed.
  • 502 - "language" param is not set.
  • 503 - "partner_id" param is not set.
  • 504 - "shop_id" param is not set.
  • 505 - "method" param is not set.
  • 506 - method is not allowed.
  • 507 - params object is not set.
  • 508 - params object has wrong structure, something is missing.
  • 509 - signature param is not set.
  • 510 - signature for the request is wrong.
  • 511 - timestamp param is not set.
  • 512 - timestamp is expired.
  • 513 - secret key for this partner is not set (API is disabled).
  • 514 - "ticket_buy" method, badly formed bets object.
  • 515 - too many API requests per second.
  • 516 - Failed to get stream URL. Please try again.
  • 600 - "ticket_payout" method, general error. Contact BetGames.TV engineer for details.
  • 601 - "ticket_payout" method, ticket is not found.
  • 602 - "ticket_payout" method, ticket was already paid out.
  • 603 - "ticket_payout" method, trying to payout ticket in wrong currency.
  • 604 - "ticket_payout" method, ticket is outdated and cant be paid out.
  • 605 - "ticket_payout" method, ticket is not calculated yet.
  • 606 - "ticket_return" method, ticket cant be returned.
  • 607 - "ticket_return" method, ticket cant be returned. Draw has already started.
  • 608 - "ticket_return" method, ticket cant be returned. Some bets have already been calculated.