Skip to content

Instantly share code, notes, and snippets.

@infinitbility
Created August 4, 2020 06:07
Show Gist options
  • Save infinitbility/5acc068316653c000dc6368c2ed738ea to your computer and use it in GitHub Desktop.
Save infinitbility/5acc068316653c000dc6368c2ed738ea to your computer and use it in GitHub Desktop.
<?php
# credentials
$url = VPC_URL; // https://migs.mastercard.co.in/vpcpay or https://migs.mastercard.com/vpcpay
$merchantId = MERCHANT_ID; //value get from your bank
$accessCode = ACCESS_CODE; //value get from your bank
$SECURE_SECRET = SECURE_SECRET; //value get from your bank
$baseURL = "localhost/migs";
# amount
$amount = floatval($_POST['amount']) *100;
$unqueId = uniqid();
$md5hash = $accessCode;
$md5hash1 = '';
$params['vpc_AccessCode'] = $accessCode;
$params['vpc_Amount'] = $amount;
$params['vpc_Command'] = 'pay';
$params['vpc_Currency'] = 'INR';
$params['vpc_Locale'] = 'en';
$params['vpc_MerchTxnRef'] = $unqueId; // need all time unique
$params['vpc_Merchant'] = $merchantId;
$params['vpc_OrderInfo'] = 'Infinitbility unique - '.$unqueId; // need all time unique
$params['vpc_ReturnURL'] = $baseURL.'/Response.php';
$params['vpc_TicketNo'] = '';
$params['vpc_TxSourceSubType'] = '';
$params['vpc_Version'] = 1;
$params['vpc_SecureHashType'] = 'SHA256';
ksort($params);
foreach($params as $key => $val )
{
if ( strlen($val) > 0 )
{
$qstr[] = urlencode($key)."=".urlencode($val);
$md5hash .= $val;
if ((strlen($val) > 0) && ((substr($key, 0,4)=="vpc_") || (substr($key,0,5) =="user_")))
{
if(in_array($key, array('vpc_SecureHash', 'vpc_SecureHashType')) )
continue;
$md5hash1 .= $key . "=" . $val . "&";
}
}
}
$md5hash1 = rtrim($md5hash1, '&');
$vpc_url = $url.'?'.implode("&", $qstr);
$vpc_url .= "&vpc_SecureHash=".strtoupper(hash_hmac('SHA256', $md5hash1, pack('H*', $SECURE_SECRET)));
header("Location: " . $vpc_url);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment