 <?php
date_default_timezone_set('Asia/Jakarta');
date_default_timezone_get();

 //Request Body//
	$body['name'] = "Teguh Aljauza"; 
	$body['email']  = "teguhaljz@gmail.com";
    $body['product']    = array('Biaya Formulir PPDB','Biaya Transaksi');
    $body['qty']        = array('1', '1');
    $body['price']      = array('250000', '3500');
	//$body['weight']  = array('1', '1', '1');
	$body['buyerName'] = "Teguh Aljauza"; 
	$body['buyerEmail']  = "teguhaljz@gmail.com";
	$body['buyerPhone']  = "082216172317";
	$body['paymentMethod']  = "va";
	$body['paymentChannel']  = "bni";
    $body['returnUrl']  = 'http://localhost/ipaymu/?p=thankyou';
    $body['cancelUrl']  = 'http://localhost/ipaymu/?p=cancel';
    $body['notifyUrl']  = 'http://localhost/ipaymu/?p=notify';
    $body['comments']  = 'Ini Hanya Transaksi Percobaan';
    $body['referenceId']  = 'INV-12345';	

// SETTING
$va           			= '1179002216172317'; //get on iPaymu dashboard
$secret    			= '1422F4CA-D3F7-4D51-9A3F-A7A4AE18A211'; //get on iPaymu dashboard
$url         	 		= 'https://sandbox.ipaymu.com/api/v2/payment/direct'; //url
$method       		= 'POST'; //method
$jsonBody     	= json_encode($body, JSON_UNESCAPED_SLASHES);
$requestBody  	= strtolower(hash('sha256', $jsonBody));
$stringToSign 	= strtoupper($method) . ':' . $va . ':' . $requestBody . ':' . $secret;
$signature   	 	= hash_hmac('sha256', $stringToSign, $secret);
$timestamp    	= Date('YmdHis');


	
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => $method,
  CURLOPT_POSTFIELDS =>$body,
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'signature: ' . $signature,
   'va: ' . $va,
     'timestamp: ' . $timestamp
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;