<?php
$request_body = file_get_contents('php://input');
$data = json_decode($request_body,true);
 //echo json_encode($data);
// exit();
if(isset($data['validationKey']) && $data['validationKey'] == 'validate@saliq'){

require_once('AfricasTalkingGateway.php');

// Specify your login credentials
//$username   = "nessinfortech";
//$apikey     = "dc013d9e2725ed67257387c35f61d209c775482b93aab364e9dddd18a1431a30";
//$username   = "mkirani";
//$apikey     = "40ff3a0b92ab19cb20a9b52c3358b16ee06b2ab4a8d37b64ddc669561a7e8e59";
$username= $data["username"];
$apikey=$data["apikey"];
// Create a new instance of our awesome gateway class
$gateway    = new AfricasTalkingGateway($username, $apikey);

try
{
  // Fetch the data from our USER resource and read the balance
  $data = $gateway->getUserData();
  $accBalance= $data->balance;
  $reply=array('status'=>"success",'balance'=>$accBalance);
                     echo json_encode($reply);

  // The result will have the format=> KES XXX
}
catch ( AfricasTalkingGatewayException $e )
{
  $reply=array('status'=>"failed",'balance'=>0);
                     echo json_encode($reply);
}
}
?>
