Thursday, January 1, 2015

HSBC - MIGS Payment Gateway Integration - PHP

When you receiving the set of document from the HSBC for the MIGS payment gateway you will feel OMG!!!

But after gone through them and had a very tough time to integrate this to one of the site. but finally when we look at that it looks like a very easy one.

So i thought to share it with all to make your life Easy.

here is the source :
________________________________________________________________
$testarr = array(
"vpc_Amount" => $finalprice*100,//Final price should be multifly by 100
"vpc_AccessCode" => "1234ABCD",//Put your access code here
"vpc_Command"=> "pay",
"vpc_Locale"=> "en",
"vpc_MerchTxnRef"=> "CLI".$session_id, //This should be something unique number, i have used the session id for this
"vpc_Merchant"=> "TEST111111111111",//Add your merchant number here
"vpc_OrderInfo"=> "XXX".$session_id,//this also better to be a unique number
"vpc_ReturnURL"=> "http://mysite.com/response.php",//Add the return url here so you have to code here to capture whether the payment done successfully or not
"vpc_Version"=> "1");

ksort($testarr); // You have to ksort the arry to make it according to the order that it needs

$SECURE_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";//Add the secure secret you have get

$securehash = $SECURE_SECRET;
$url = "";
foreach ($testarr as $key => $value)
{
$securehash .= $value;
$url .= $key."=".urlencode($value)."&";
}

$securehash = md5($securehash);//Encoding
$url .= "vpc_SecureHash=".$securehash;

header("location:https://migs.mastercard.com.au/vpcpay?$url");
_____________________________________________________________

That's it guyz..

15 comments:

  1. Hello,

    Greetings from Singapore!
    May I know where to put all those code to?
    I am having a hard time with the HSBC VPC sample codes.
    Could you please enlight me where to begin with?

    Best Regrds,
    KSM

    ReplyDelete
    Replies
    1. Hi,

      This code should be placed in your system, and you have to replace the details that you get from HSBC to the one i have mentioned.

      This code is from PHP. hope you have the experience in php coding ?

      Delete
  2. Hello,

    What is the url you Send your POST transaction to? The documentation is very unclear what that is. It is stated in the documentation as "Data is sent via a form POST to https://VPC_URL/vpcdps" That url is incorrect.

    ReplyDelete
    Replies
    1. Check above code, i am creating a long url with the values i have to send, that url is https://migs.mastercard.com.au/vpcpay?$url $url having all the data i have to pass

      Delete
  3. Hello,
    Fist thanks for this information. Secondly
    do you know how to send a merchant transaction reference value "vpc_MerchTxnRef" from an application and receive the results for this transaction from MIGS

    Regards,
    Yasser Moaly

    ReplyDelete
    Replies
    1. Hi, vpc_MerchTxnRef should be something unique that you can identify the order with that number so as you can see above that i am sending a url from this variable vpc_ReturnURL so that is the url that all the messages returning from migs are receiving , so you have to use another code to grab that details in that vpc_ReturnURL .

      A trick that you can do is something like below

      $string = "";
      foreach($_POST as $key=>$value)
      {
      $string .= $key."-".$value;
      }

      //Send a mail from this place as your mail body should be $string... then you can get an idea what are the values are passing back from MIGS after the transaction

      Delete
  4. Guyz, send me a email or add me on gtalk for your questions charitharanasingha at gmail dot com

    ReplyDelete
  5. Replies
    1. You do not have to pass the card type at this moment, This code block is to create migs third party link, so once you redirected to that link only the user have to enter the CC details or even you are passing the card number is fine... So AFAIK migs payment gateway automatically detecting the card type according to the card number.

      So once the payment is done MIGS will return the details with the card type , etc details

      Delete
  6. My brother recommended I might like this web site. He was totally right.

    This put up actually made my day. You cann't believe simply how so much time I
    had spent for this info! Thank you!
    http://www.roznoszenie.net

    ReplyDelete
  7. Hi Charitha, I am getting following error after I enter card data and press pay button.An error has occurred processing your payment.

    Undefined System Error
    E5028-02191641: Invalid Digital Receipt Delivery URL

    Did you experience this ?

    ReplyDelete
    Replies
    1. Actually no. but please note that i have done this integration few years back, and i am not sure the process and the params the payment gateway is expecting is changed now. But i just googled this error now..looks like most of the people came across this.

      Delete
  8. I want to make payment integration with MasterCard and visa using NVP with php code.... any help please
    I can't send payment details and also I can't receive the results of payment order

    ReplyDelete
  9. Nice and informative article. This article helps me. Keep doing this.

    ReplyDelete
  10. hi ,

    the above code is for server side payment , what about if i want to use merchant side what will be the code structure.

    ReplyDelete