Documentations
ZainCash
Check transaction

Check transaction

Sometimes transactions go pending due to connectivity issue ove the customer's end, in such cases you can check for the status of the transaction as explained in the following simple example.

require_once('credentials.php');
  require_once('includes/autoload.php');
  use \Firebase\JWT\JWT;
  
  // ----------------- Request Details --------------------------
  // The ID for the transaction you want to check
  $id = '61ac94f43c22082431672b27';
  
  //building data
  $data = [
    'id'  => $id,                
    'msisdn'  => $msisdn,
    'iat'  => time(),
    'exp'  => time()+60*60*4
  ];
  
  //Encoding Token
  $newtoken = JWT::encode(
  $data, //Data to be encoded in the JWT
  $secret ,'HS256'
  );
  
  //Check if test or production mode
  if($production_cred){
    $rUrl = 'https://api.zaincash.iq/transaction/get';
  }else{
    $rUrl = 'https://test.zaincash.iq/transaction/get';
  }
  
  //POST data to ZainCash API
  $data_to_post = array();
  $data_to_post['token'] = urlencode($newtoken);
  $data_to_post['merchantId'] = $merchantid;
  $options = array(
  'http' => array(
  'header' => "Content-type: application/x-www-form-urlencoded\r\n",
  'method' => 'POST',
  'content' => http_build_query($data_to_post),
  ),
  );
  $context = stream_context_create($options);
  $response = file_get_contents($rUrl, false, $context);
  
  echo $response;