Ahmed Elakkad
Ahmed Elakkad

Reputation: 21

MIGS payment gateway integration

I need someone help me to integrate MIG Payment Gateway into my website, i received 3 files from the bank

vpc_php_serverhost_do.php 
vpc_php_serverhost_dr.php
vpc_php_serverhost.html

what the use of these files and how to use them , and how i generate the URL, please can someone help and explain in details the steps to do.

Thanks

Upvotes: 1

Views: 2737

Answers (1)

Emad ElShafie
Emad ElShafie

Reputation: 11

Here's my PHP of MIGS

<?
$SECURE_SECRET = "YOU_GET_THIS_FROM_THE_BANK";
$accessCode = 'YOU_GET_THIS_FROM_THE_BANK';
$merchantId = 'YOU_GET_THIS_FROM_THE_BANK';
$merchinvno = GENERATED_ID_OF_PURCHASE; //example 123456
$amount = 20;
$vpcinfo = 'Purchase of Item 1';



            $postdata = array(
                    "vpc_AccessCode" => $accessCode,
                    "vpc_Amount" => ($amount*100),
                    "vpc_Command" => 'pay',
                    "vpc_Locale" => 'en',
                    "vpc_MerchTxnRef" => $merchinvno,
                    "vpc_Merchant" => $merchantId,
                    "vpc_OrderInfo" => $vpcinfo,
                    "vpc_ReturnURL" => "https://www.YOUR_DOMAIN.com/PAYMENT_RESULT_PAGE.php",
                    "vpc_Version" => '1');


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


            foreach ($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)
?>

Then in your PAYMENT_RESULT_PAGE.php you check the response you got from the bank, if the response = 00, then payment is successful, other numbers indicate payment failure, you'll find the codes with their corresponding error in the documents they give you

Example of PAYMENT_RESULT_PAGE.php

<?
$response = $_GET['vpc_TxnResponseCode'];
$message = $_GET['vpc_Message'];

if ($response == '00') {

  echo 'Payment Successful';

} else {
  echo 'Payment Failed: '.$message;
}
?>

Upvotes: 1

Related Questions