pandoragames

Provably fair games by Pandora games

Usage no npm install needed!

<script type="module">
  import pandoragames from 'https://cdn.skypack.dev/pandoragames';
</script>

README

Installing

Using npm:

$ npm install pandoragames

Integration data provided by Game Aggregator

  1. Merchant ID
  2. Merchant Key
  3. Base API URL

Please, contact on mailto:contact@pandoragames.io

Integrator's transaction structure

transaction = {
    action, //(string) ex: "bet", "win", "refund"
    amount, //(number) ex: 34.12345678
    currency, //(string) ex: "btc", "eth"...
    game_uuid, //(string) ex: "dice", "plinko"...
    player_id, //(string)
    session_id, //(string) ex: "eb20dd0a-de8e-42cf-98da-f3ddaa409502"
    transaction_id, //(string) pandora's provided transaction id, ex: "5f5757d79a5173055449d5dc"
    left_balance, //(number) ex 43.12345678
    bet_transaction_id, //(string) sent only when action is "win" or "refund", ex: "5f5757d79a5173055449d5dc"
};

Example

const pg = require("pandoragames");

/*
    pandoragames module setup
*/
pg.setup(/*merchant_id*/, /*merchant_key*/, /*aggregator_url*/);

/*
    create route listener on "/gamesApi"
*/
YOUR_ROUTER.post("/gamesApi", pg.onRemoteCall);

/*
    Start game
*/
pg.gameStart(
    "your_unique_id" /*session_id*/,
    "dice" /*game_uuid*/,
    "player123" /*player_id*/,
    "player123" /*player_name*/,
    "btc" /*currency*/,
    "en" /*language*/,
    false /*demo*/,
    false /*validate*/
).then((result)=>{
    //navigate to result.url to open requested game
});

/*
    Get player's balance
*/
pg.setOnBalanceGet(async (player_id, currency, session_id) => {
    const balance = ...//get balance...

    if (/*error happened while checking balance*/) return { error: true };

    return { balance };
});


/*
    Change balance by provided delta (can also be negative or zero) and store transaction into your database
*/
pg.setOnCreateTransaction(async (action, amount, currency, game_uuid, player_id, session_id, transaction_id, bet_transaction_id, delta) => {
    const balance = ...; //get balance...

    if (/*error happened while checking balance*/) return { error: true };

    const left_balance = balance + delta; //left balance after applying delta

    if (action === "bet" && left_balance < 0 /*not enough funds*/) return { balance_changed: false }

    //change balance, store transaction (you must also store "left_balance" inside transaction!)

    if (/*error happened while changing or storing (reverted all operations)*/) return { error: true }

    return {
        balance_changed: true,
        left_balance,
        transaction_id /*your system generated unique id while storing transaction*/,
    };
});

/*
    Search transaction in your database by querying with the provided selector
    selector format while "bet"/"win": {transaction_id: "5f575aec5e9bb04170304e77"}
    selector format while "refund": {bet_transaction_id: "5f575aec5e9bb04170304e77"}
*/
pg.setOnGetTransactionData(async (selector) => {
    /*make search transaction...*/

    if (/*encountered error while searching*/) return { error: true };

    if (/*transaction does not exist*/) return { transaction_id: null };

    return {
        left_balance /*post balance stored inside transaction*/,
        transaction_id /*your system generated unique id while storing transaction*/,
        amount /*amount stored inside transaction*/
    };
});

/*
    Contest finished event
*/
pg.setOnStoreContest(async (contest_id, winners, percentages, amount) => {
    /*
        contest_id: "5e8c65951c96592ff1b5a89e"
        winners: [
            {
                position: 1,
                player_id: "user234"
                vendor: "client1",
                wager: 12.00000271,
                bet_count: 1854,
                won_amount: 500.00000000
            },
            ...
        ]
        percentages: [50,25,25]
        amount: 1000.00000000
    */
    //logic on awarding winners...
    if (/*encountered error while processing contest results*/) return { error: true };
    return { error: false };
});


/*
    Get list of games
*/
pg.getGames().then(array => {
    /*
        [
            {
                name: "sicbo",
                active: true,
                image: "https://res.cloudinary.com/dez0s9s32/image/upload/v1576414996/pandora/games/sicbo/sicbo_320x240.png",
                release_date: 1594152000000,
                is_mobile: true,
                is_desktop: true,
                game_type: "board",
            },
            ...
        ]
    */
});

/*
    Get contest's leader board. Leader board is cached on the aggregator's side and is updated every 1 minute.
*/
pg.getLeaderboard(contest_id).then(array =>{
    /*
        [
            {
                position: 1,
                player_id: "user234",
                shared: false,
                wager: 123.12345678,
                bet_count: 3027
            },
            ...
        ]
    */
});

/*
    Get player's position in specified leader board
*/
pg.getLeaderboardPosition(player_id, contest_id).then(data => {
    /*
        {
            position: 1,
            player_id: "user234",
            wager: 123.12345678,
            bet_count: 3027
        }
    */
});

/*
    Get the list of the contests
*/
pg.getContests().then(data => {
    /*
        {
            server_time: 1600676640839,
            expired: [
                contest_id: "5e8c65951c96592ff1b5a89e",
                name: "New Year BTC, ETH Contest",
                description: "Play and win",
                image0: "https://...",
                image1: null,
                image2: null,
                url: "https://...",
                amount: 5000,
                currencies: ["btc", "eth"],
                time_from: 1600670000000,
                time_to: 1600670100000,
                games: ["sicbo", "dice"],
                percentages: [ 12.50, 11.67, 10.83, 10.00, 9.17, 8.33, 7.50, 6.67, 5.83, 5.00, 4.17, 3.33, 2.50, 1.67, 0.83 ],
                t: 1600676640839,
                winners: [
                    {
                        position: 1,
                        player_id: "user234",
                        shared: false,
                        wager: 98.12345678,
                        bet_count: 348,
                        won_amount: 625
                    }
                    ...
                ]
            ],
            active: [
                ...
            ],
            pending: [
                ...
            ]
        }
    */
});