I am trying to integrate Telenor EasyPay payment gateway with my online store but no matter what I do I get "Invalid Request" error on EasyPay server. Here is a snapshot of the problem.
Here is my code request code for staging account:
<form id="easypay" target="_blank" name="easypay" method="post" action="https://easypaystg.easypaisa.com.pk/easypay/Index.jsf">
<input type="hidden" name="storeId" value="my_store_id_here" />
<input type="hidden" name="amount" value="10" />
<input type="hidden" name="postBackURL" value="https://my-store.com/post-back.php" />
<input type="hidden" name="orderRefNum" value="5555"/>
<input type="hidden" name="expiryDate" value="20201115 05:10:00" />
<input type="hidden" name="autoRedirect" value="1" />
<input type="hidden" name="paymentMethod" value="MA_PAYMENT_METHOD" />
<input type="hidden" name="emailAddr" value="client_email@gmail.com" />
<input type="hidden" name="mobileNum" value="client_mob_num" />
<input type="hidden" name="merchantHashedReq" value="<?php echo $hashedRequest;?>" />
<input type = "submit" value="Pay With EasyPay">
</form>
Another piece of code in PHP that I use for hashing my request parameters is:
function getHashedRequest($hKey, $orderId, $amt, $autoRed, $expiryDate, $storeId, $merchantConfirmPage,$paymentMode,$phone,$email) {
$hashRequest = '';
if(strlen($hKey) > 0 && (strlen($hKey) == 16 || strlen($hKey) == 24 || strlen($hKey) == 32 )) {
// Create Parameter map
//error_log('Order INFO: '. $orderId);
$paramMap = array();
$paramMap['amount'] = $amt ;
$paramMap['autoRedirect'] = $autoRed ;
$paramMap['expiryDate'] = $expiryDate;
$paramMap['mobileNum'] = $phone ;
$paramMap['emailAddr'] = $email ;
$paramMap['orderRefNum'] = $orderId;
$paramMap['paymentMethod'] = $paymentMode;
$paramMap['postBackURL'] = $merchantConfirmPage;
$paramMap['storeId'] = $storeId;
//Creating string to be encoded
$mapString = '';
foreach ($paramMap as $key => $val) {
$mapString .= $key.'='.$val.'&';
}
$mapString = substr($mapString , 0, -1);
// error_log('MAPString: '.$mapString);
// Encrypting mapString
function pkcs5_pad($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
$alg = 'MCRYPT_RIJNDAEL_128'; // AES
$mode = 'MCRYPT_MODE_ECB'; // ECB
//////////////////////////////////////////
//$key previously generated safely, ie: openssl_random_pseudo_bytes
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($mapString, 'aes-256-ctr', $hKey, $options=OPENSSL_RAW_DATA, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, $hKey, $as_binary=true);
$hashRequest = base64_encode( $iv.$hmac.$ciphertext_raw);
}
return $hashRequest;
}
I don't know what I am doing wrong. Any help would be appreciated. Thanks