Giter Club home page Giter Club logo

betable-browser-sdk's Introduction

This SDK is deprecated. Please use the Betable Canvas SDK.

Betable Browser SDK

Once a Betable API client has been authorized by a player, browser-based games should use the Betable Browser SDK to place bets directly from the browser so Betable can determine whether the player is allowed to gamble.

The various Betable OAuth SDKs ultimately produce an access token which should be sent from the server to the browser to configure the Betable Browser SDK. With a game ID and that access token, the browser will be able to send bets directly to the Betable API.

Requirements

The Betable Browser SDK requires browsers modern enough to support XMLHttpRequest in some form and the native JSON.parse method. Specifically, these are Chrome 3+, Firefox 3+, and IE 8+.

In order to support browsers that do not have JSON.parse or JSON.stringify please include Crockford's JSON2 https://github.com/douglascrockford/JSON-js/blob/master/json2.js on your webpage.

Due to a limitation of Internet Explorer 8 and 9, Cross-site requests are made using XDomainRequests. This requires that your website use SSL.

Usage

Configure the Betable Browser SDK:

var betable = new Betable('YOUR_GAME_ID', 'AN_ACCESS_TOKEN')

Each method takes two final arguments that are both functions: a callback which in case of success receives the parsed response structure and an errback which in case of failure receives the parsed error, description, and details.

Check whether the player can gamble:

betable.canIGamble(
    function(response) {
        //
        // response:
        //
        //     {
        //         "can_gamble": true
        //       , "country": "Great Britain"
        //       , "country_code": "GB"
        //     }
        //
    }
  , function(error) {
        console.log(error)
    }
)

This is not strictly necessary but it makes for a nicer player experience to tell players that can't gamble as early as possible.

Get the player's account, which includes their first and last name:

betable.account(
    function(response) {
        //
        // response:
        //
        //     {
        //         "id": "A4n7V5UL3gKx8ms2"
        //       , "first_name": "Charles"
        //       , "last_name": "Fey"
        //     }
        //
    }
  , function(error) {
        console.log(error)
    }
)

Get the player's wallet, which includes their real-money balance:

betable.wallet(
    function(response) {
        //
        // response:
        //
        //     {
        //       , "real": {
        //             "balance": "0.00"
        //           , "currency": "GBP"
        //           , "economy": "real"
        //         }
        //       , "sandbox": {
        //             "balance": "0.00"
        //           , "currency": "GBP"
        //           , "economy": "sandbox"
        //         }
        //     }
        //
    }
  , function(error) {
        console.log(error)
    }
)

If a player needs to deposit, send them to https://betable.com/#/wallet/deposit.

Place a bet:

betable.bet(
    {
        currency: 'GBP'
      , economy: 'real'
      , paylines: [[1, 1, 1, 1, 1]]
      , wager: '0.01'
    }
  , function(response) {
        //
        // response:
        //
        //     {
        //       , "currency":"GBP"
        //       , "outcomes": [
        //             {
        //                 "outcome": "win"
        //               , "payline": [1, 1, 1, 1, 1]
        //               , "payout":"0.05"
        //               , "symbols":["A","B","A","B","A"]
        //              }
        //         ]
        //       , "payout": "0.05"
        //       , "stops": [3, 26, 18, 18, 1]
        //       , "window": [
        //             ["C", "C", "D", "A", "B"]
        //           , ["A", "B", "A", "B", "A"]
        //           , ["C", "A", "D", "B", "A"]
        //         ]
        //     }
        //
    }
  , function(error) {
        console.log(error)
    }
)

The first argument and the response change form according to the type of game on which bets are being placed. This example happens to be for a slot machine. Full documentation of the available options may be found at https://developers.betable.com/docs/.

Place an unbacked bet:

betable.unbackedBet(
    {
        paylines: [[1, 1, 1, 1, 1]]
      , wager: '0.01'
    }
  , function(response) {
        //
        // response:
        //
        //     {
        //       , "outcomes": [
        //             {
        //                 "outcome": "win"
        //               , "payline": [1, 1, 1, 1, 1]
        //               , "payout":"0.05"
        //               , "symbols":["A","B","A","B","A"]
        //              }
        //         ]
        //       , "payout": "0.05"
        //       , "stops": [3, 26, 18, 18, 1]
        //       , "window": [
        //             ["C", "C", "D", "A", "B"]
        //           , ["A", "B", "A", "B", "A"]
        //           , ["C", "A", "D", "B", "A"]
        //         ]
        //     }
        //
    }
  , function(error) {
        console.log(error)
    }
)

The first argument and the response change form according to the type of game on which bets are being placed. This example happens to be for a slot machine. Full documentation of the available options may be found at https://developers.betable.com/docs/.

Bet with credits

betable.betCredits(
    game_id
  , {
        currency: 'GBP'
      , economy: 'real'
      , paylines: [[1, 1, 1, 1, 1]]
      , wager: '0.01'
    }
  , function(response) {
        //
        // response:
        //
        //     {
        //       , "currency":"GBP"
        //       , "outcomes": [
        //             {
        //                 "outcome": "win"
        //               , "payline": [1, 1, 1, 1, 1]
        //               , "payout":"0.05"
        //               , "symbols":["A","B","A","B","A"]
        //              }
        //         ]
        //       , "payout": "0.05"
        //       , "stops": [3, 26, 18, 18, 1]
        //       , "window": [
        //             ["C", "C", "D", "A", "B"]
        //           , ["A", "B", "A", "B", "A"]
        //           , ["C", "A", "D", "B", "A"]
        //         ]
        //     }
        //
    }
  , function(error) {
        console.log(error)
    }
)

If a player has earned credits for a game, they are able to bet with those credits by calling betCredits with the first argument being the game id.

Example

https://github.com/betable/betable-browser-sdk/blob/master/index.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.