Migs(MasterCard虚拟支付客户端)集成PHP

9

有人能帮我解决如何在php网站中集成migs(MasterCard虚拟支付客户端)的问题吗?

我已经阅读了参考指南,但没有什么帮助!

4个回答

7

//这个值将提交到MIGS支付网关

        $SECURE_SECRET =  $signature; //value from migs payment gateway
        $accessCode    =  $accesscode;//value from migs payment gateway
        $merchantId    =  $merchantid;//value from migs payment gateway
        $paymentdata = array(
                 "vpc_AccessCode" => $accessCode,
                 "vpc_Amount" => ($amount*100),//our product price , must multipy by 100
                 "vpc_Command" => 'pay',
                 "vpc_Locale" => 'en',// order id
                 "vpc_MerchTxnRef" => random_unique_value(like session),
                 "vpc_Merchant" => $merchantId,
                 "vpc_OrderInfo" => "Some Comment",
                 "vpc_ReturnURL" => "htps://yoursite.com/returnpoint",//here code for db updation, return variable here
                 "vpc_Version" => '1'
                           );

        $actionurl = 'https://migs.mastercard.com.au/vpcpay' . "?";
        $HashData = $SECURE_SECRET;
        $str = 0;
        foreach ($paymentdata as $key => $value) {
            // create the md5 input and URL
            if (strlen($value) > 0) {
                // this ensures the first paramter of the URL is preceded by the '?' char
                if ($appendAmp == 0) {
                    $actionurl .= urlencode($key) . '=' . urlencode($value);
                    $str = 1;
                } else {
                    $actionurl .= '&' . urlencode($key) . "=" . urlencode($value);
                }
                $HashData .= $value;
            }
        }

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

Sorry, could you please provide the content to be translated?
the return url will be like

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

我该如何获取这个返回值?我应该把它放在代码的哪里? - Pulkit Pithva
@PulkitPithva,MIGS网关将向您的返回URL https://yoursite.com/returnpoint 发送HTTP请求。您需要编写代码来处理该页面中的查询字符串。 - Concrete Gannet
如何在所有参数都返回URL的情况下提供安全性? - Byndd IT
我知道这是一个相当老的帖子,但我从哪里获取vpc_accesscode? - snowflakes74

3
在实现MIGS支付网关时,我们需要将以下数据发布到此URL:https://migs.mastercard.com.au/vpcpay。请保留HTML标签。
    /*"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  */

创建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)

详细的结果在这里可以查看。


Akhilraj,我正在使用你的代码,当我尝试提供卡号、卡过期和卡安全码时,它会给我发送此错误:HTTP状态-400,我该如何解决这个问题。帮帮我。 - okconfused
还有,我该如何在你的代码中提交多个订单并将它们添加到购物车中? - okconfused
1
foreach循环中的错误。您引用了“$wpay_postdata”,但实际上应该是“$postdata”。 - Dss
这个在我把 $wpay_postdata 改成 $postdata 后就可以工作了。谢谢。 - Riffaz Starr
我可以获取文档吗? - Hilar AK

3
你可以使用Omnipay PHP库,该库支持MIGS网关
离线支付处理(3方)的示例如下:
use Omnipay\Omnipay;

$gateway = Omnipay::create('Migs_ThreeParty');
$gateway->setMerchantId('foo');
$gateway->setMerchantAccessCode('foo');
$gateway->setSecureHash('foo');

$response = $gateway->purchase(array('amount' => '10.00', 'currency' => 'AUD'))->send();

if ($response->isRedirect()) {
    // redirect to offsite payment gateway
    $response->redirect();
} else {
    // payment failed: display message to customer
    echo $response->getMessage();
}

2
我尝试在Python Django中使用MIGS Mastercard集成。我遇到了很多问题。下面是我将MIGS集成到我的Web应用程序中的经验。我使用的是VPC Integration reference 3.1.21.1。
  1. 在实施Mode1 VPC时,我遇到了400 Bad request错误。这是由于我的情况下安全哈希代码有问题导致的。如果用户发送错误的字段名称或未排序的顺序,则会出现此错误。
  2. 一旦我解决了Mode1错误,我使用了外部付款选择(EPS),其中我发送了Mode1 VPC参数的VPC_card和VPC_gateway附加字段。我又得到了400 Bad request错误。因此,在与MIGS支持团队进行长时间的讨论后,我们通过将vpc_card更改为vpc_Card和vpc_Gateway来解决了这个问题,这是文件错误。
  3. 一旦我能够绕过卡类型页面,我就尝试完成Mode 2 VPC实现。因此,在这种情况下,我添加了vpc_CardNum、vpc_vpc_CardExp和vpc_CardSecurityCode等额外字段,并发送GET请求。它不起作用。对于卡详情或Mode2,我们必须使用POST请求。
  4. 对于Mode2 VPC,我们应该使用HTTPS而不是HTTP进行POST请求。自签名证书可以用。因此,我发送了带有附加参数的HTTPS POST请求。但它仍然不起作用,我得到了403 forbidden错误。因为我的ajax调用Content-type是application/json。所以使用默认POST Content-type后它工作正常。
Python开发人员的示例代码: 在migs.config.app中,我添加了与Migs无关的系统变量。因此用户可以忽略它。
import hashlib
import urllib, urllib2
from migs.config.app_config import *


'''
This method is for sorting the fields and creating an MD5 secure hash.
@param fields is a map of all the incoming hey-value pairs from the VPC
@param buf is the hash being returned for comparison to the incoming hash
'''


class MigsClient(object):

def __init__(self, secure_token, vpc_url, server_name):
    self.secure_secret  = secure_token
    self.vpcURL = vpc_url
    self.server_name = server_name    

def hash_all_fields(self,fields):
    buf = ""
    # create a list and sort it
    fieldNames = fields.keys();
    fieldNames.sort()
    # create a buffer for the md5 input and add the secure secret first
    buf = buf + self.secure_secret
    for key in fieldNames:
        print key,fields[key]
        buf = buf + fields[key] 
    # iterate through the list and add the remaining field values
    # create the md5 hash and UTF-8 encode it
    try:
        m = hashlib.md5()
        m.update(buf)
        ba = m.hexdigest()
        ba = ba.upper()
        return ba

    except Exception,e:
        import traceback 
        traceback.print_exc()


def setup(self, fields,additional_fields=None):
    #The Page does a redirect to the Virtual Payment Client
    #retrieve all the parameters into a hash map
    # no need to send the vpc url, EnableAVSdata and submit button to the vpc

    '''
    Retrieve the order page URL from the incoming order page and add it to 
    the hash map. This is only here to give the user the easy ability to go 
    back to the Order page. This would not be required in a production system
    NB. Other merchant application fields can be added in the same manner
    '''

    '''
    Create MD5 secure hash and insert it into the hash map if it was created
    created. Remember if self.secure_secret = "" it will not be created
    '''
    if self.secure_secret:
        secureHash = self.hash_all_fields(fields);
        fields["vpc_SecureHash"] = secureHash;

    # Create a redirection URL
    buf = self.vpcURL+'?';
    if not additional_fields:
        buf  = buf + urllib.urlencode(fields)
    else:
        buf  = buf + urllib.urlencode(fields)+"&"+urllib.urlencode(additional_fields) 
    return buf
    #return fields["vpc_ReturnURL"], buf


def post_setup(self,fields, additional_fields=None):

    try:
        if self.secure_secret:
            secureHash = self.hash_all_fields(fields);
            fields["vpc_SecureHash"] = secureHash;

        return self.vpcURL,fields
    except:
        import traceback
        traceback.print_exc()

以下是用户可以使用的示例代码,用于对请求进行排序、创建Get请求和POST请求,并发布字典。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接