<?php

/*

SMALL SCRIPT TO DISPLAY CURRENT BALANCE FOR A LIST OF WALLET ACCOUNTS

*/


/*
 * Set fonctions Matthieu HiPay
 */
// Connexion BDD
require("../shared/functions.php");

$credentials = '6c57a2706509489bc75029fa69d9fa3c:014fbe84ee0ce879669411f83b97ed2c';

$AccountList = array(9394335,
9918839,
9949816,
9949818,
9949820,
9949821,
9949823,
9949827,
9949832,
9949835,
9949837,
9949838,
9949841,
9949842,
9949843,
9949844,
9949845,
9949847,
9949848,
9949851,
9949853,
9949854,
10101728,
10156528,
10161409,
10312590,
);


foreach($AccountList as $AccountID) {


    $curl = curl_init();

    curl_setopt_array($curl, array(
    CURLOPT_URL => "https://merchant.hipaywallet.com/api/user-account/balance.json",
    CURLOPT_USERPWD => $credentials,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
        "php-auth-subaccount-id: $AccountID",
    ),
    ));

    $response = curl_exec($curl);

    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
    echo "cURL Error #:" . $err;
    } else {
        //echo $response;

        $result = json_decode($response);

        echo $AccountID . ";";

        if(isset($result->balances[0]->balance)) {
            echo $result->balances[0]->balance . ";" . $result->balances[0]->money_available_for_withdrawal . "<br />\n";
        }
        else krumo($result);
    }

}