Documentations
ZainCash
Create transaction

Create transaction

This following is a simple example of creating a transaction ID for the ccustomer to submit

Order Details

$amount = 250; // Amount in IQ dinar
 
$service_type = "A book"; //Type of service you provide, like 'Books', 'ecommerce cart', 'Hosting services', ...
 
$order_id = "Bill_1234567890"; // you can use it to help you in tagging transactions with your website IDs, if you have no order numbers in your website, leave it 1
 
$redirection_url = 'http://localhost/redirect.php'; // after a successful or failed order, the user will redirect to this url
Notes about $redirection_url:
in this url, the api will add a new parameter (token) to its end like:
https://example.com/redirect.php?token=XXXXXXXXXXXXXX```

Building data

  $data = [
  'amount'  => $amount,        
  'serviceType'  => $service_type,          
  'msisdn'  => $msisdn, // Your wallet phone number
  'orderId'  => $order_id,
  'redirectUrl'  => $redirection_url,
  'iat'  => time(),
  'exp'  => time()+60*60*4
  ];

Encoding Token

  $token = JWT::encode($data, $secret_key); // $secret_key is your secret key
 
  $tUrl = 'https://test.zaincash.iq/transaction/init';
  $rUrl = 'https://test.zaincash.iq/transaction/pay?id=';

POST data to ZainCash API

$data_to_post = array();
$data_to_post['token'] = urlencode($newtoken);
$data_to_post['merchantId'] = $merchantid; // Your merchant ID is requested from ZainCash
$data_to_post['lang'] = $language;
 
$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($tUrl, false, $context);