9.1.12

Migs payment gateway integration php








MIGS(MasterCard Internet Gateway Service) payment gateway Integration



  • Integrating Migs is very simple.
  • Need to get two accounts on for test and other for Production.
  • we need Migs Merchant ID ,Migs AccessCode, and Migs Signature for implementing the payment gateway in our application
  • After submiting the Buy button we need to validate the details provided by the user after the validation insert those details to DB and in the server side we need to generate the url that we need to post the details

/*"vpc_AccessCode" the accesscode given by Migs
"vpc_Amount" Amount that is multiplied by 100
"vpc_Command" ='pay',default pay
"vpc_Locale" = 'en' // language
"vpc_MerchTxnRef"  orderId // Should be Unique for each payment
"vpc_Merchant"  // merchant ID
"vpc_OrderInfo"  // Desc or and details of Product
"vpc_ReturnURL" // SuccessUrl
"vpc_Version" = '1'
&vpc_SecureHash = // create MD5 of all the values that are passed  */

Creating Url

        $SECURE_SECRET = "YEOCOEN29B0785F1FF1E3C0FA8A3FUJK";  
            $accessCode = '546484645';
            $merchantId = '5465465288';
            if($migs_testmode ==1) {
                $SECURE_SECRET = "YEOCOEN29B0785F1FF1E3C0FA8A3FUJK";
                $accessCode = '98989645';
                $merchantId = '56456456489';
            }
         $amount ='10.00';
        $unique_id = rand(999999,8988888888);//this is a sample random no
            $postdata = array(
                    "vpc_AccessCode" => $accessCode,
                    "vpc_Amount" => ($amount*100),
                    "vpc_Command" => 'pay',
                    "vpc_Locale" => 'en',
                    "vpc_MerchTxnRef" => $unique_id,
                    "vpc_Merchant" => $merchantId,
                    "vpc_OrderInfo" => 'this is a product',
                    "vpc_ReturnURL" => "https://mywebsite.com/success.php",
                    "vpc_Version" => '1');

          
            $vpcURL = 'https://migs.mastercard.com.au/vpcpay?';
            $md5Hash = $SECURE_SECRET;
            $appendAmp = 0;


            foreach ($wpay_postdata as $key => $value) {

                if (strlen($value) > 0) {
  
                    if ($appendAmp == 0) {
                        $vpcURL .= urlencode($key) . '=' . urlencode($value);
                        $appendAmp = 1;
                    } else {
                        $vpcURL .= '&' . urlencode($key) . "=" . urlencode($value);
                    }
                    $md5Hash .= $value;
                }
            }

            if (strlen($SECURE_SECRET) > 0) {
                $vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5Hash));
            }
            header("Location: " . $vpcURL)

or

$HashData =$vpc_AccessCode.$vpc_Amount.'pay'.'en'.$orderid.$vpc_Merchant.$desc.'successurl'.'1';
$URL = "https://migs.mastercard.com.au/vpcpay?vpc_AccessCode=$vpc_AccessCode&vpc_Amount=$vpc_Amount&vpc_Command=pay&vpc_Locale=en&vpc_MerchTxnRef=$orderid&vpc_Merchant=$vpc_Merchant&vpc_OrderInfo=$desc&vpc_ReturnURL=successurl&vpc_Version=1&vpc_SecureHash=".strtoupper(md5($HashData));

header("Location: " . $URL);

After Payment 

  • After the Successfull Payment the user will be redirected to our successUrl in that url some other variables are also posted

$transactionKey = $resp_data['vpc_TransactionNo'];//transaction number form payment Gateway
$cartId         = $resp_data['vpc_MerchTxnRef'];//reference from shop OrderId
$transStatus    = $resp_data['vpc_TxnResponseCode']; //Status Of Payment
$statusmessage  = $resp_data['vpc_Message'];//response form payment
  • find the details of the User with $cartId and Update Table Accordingly

 if($transStatus  == "0" && $statusmessage == 'Approved') {//success
}else{
// Failed}