Hello Friends.

Welcome to Infinitbility!

we are going to integrate MIGS ( MasterCard Payment Gateway Service ) Or Also known as VPC ( Virtual Payment Client ) using PHP.

MasterCard's Virtual Payment Client enables merchants to use payment enabled websites, e- commerce or other applications by providing a low effort integration solution. It is suitable for most website hosting environments as merchants can integrate payment capabilities into their application without installing or configuring any payments software.

  • from MIGS Documentation

Documentation

if want read and understand deeply MIGS Payment integration then I have some documentation from MIGS

Virtual Payment Client Reference Guide

Prerequisites

Given By the bank for payment credentials

  1. MERCHANT_ID
  2. ACCESS_CODE
  3. SECURE_SECRET

Integration

create a PHP file copy the below code and replace with your credentials

For VPC_URL try both https://migs.mastercard.co.in/vpcpay or https://migs.mastercard.com/vpcpay it depends on your country and credentials.



<?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);
?>

return Response

https://yoursite.com/returnpoint?vpc_TransactionNo="migs_transaction_number"&vpc_MerchTxnRef="random_unique_value(we post to migs)"&vpc_TxnResponseCode=value&vpc_Message="value"
 if vpc_TxnResponseCode = 0 -- success ,vpc_Message = approved -- paymet is success , All other unsuccessfull payment

Thanks for reading…