weixin_33736048 2019-11-27 05:58 采纳率: 0%
浏览 65

万事达卡MIGS API

I want to integrate the payment partal without displaying the MasterCard interface to user the will only fill their information on my web here

my portal

enter image description here

and not here

mastercard portal

enter image description here

I am trying to implement CommWeb on my PHP site using curl. It isn't working. I am getting following error message:

if ($_SERVER["REQUEST_METHOD"] == "GET") {
    if (!isset($_GET['id']) || !isset($_GET['motif']) || !isset($_GET['code'])){
        die("Invalid request");
    }

    $amount = 10000;
    $id = 2;
    $motif = 'save';
    $action_code = 'ookkk';
    $orderInfo = 'fhhsd'.$id;
    $MerchTxnRef = $orderInfo.'-'.generateMerchTxnRef();
    $accountData = array(
        'merchant_id' => 'TESTID', // for test card
        'access_code' => '77867878', // for test card
        'secret'      => 'TYUJHGFDFGHJ87654567GFDFGHGF' // for test card

    );

    $currency_str = "USD";
    $mult = 100;

    $queryData = array(
        'vpc_AccessCode' => $accountData['access_code'],
        'vpc_Merchant' => $accountData['merchant_id'],
        'vpc_Amount' => 1000000, // Multiplying by 100 to convert to the smallest unit
        'vpc_OrderInfo' => $orderInfo,
        'vpc_MerchTxnRef' => $MerchTxnRef,
        'vpc_Command' => 'pay',
        'vpc_Currency' => $currency_str,
        'vpc_Locale' => 'en',
        'vpc_Version' => 2,
        'vpc_ReturnURL' => ('http://theeventsfactory.biz/the_events_factory/logics/payment_return.php?id='.$id.'&motif='.$motif.'&code='.$action_code),
        'vpc_SecureHashType' => 'SHA256',
        'vpc_CardNum' => '5123456789012346',
        'vpc_CardExp' => '0521',
        'vpc_CardSecurityCode'=> '123'
    );

    // Add secure secret after hashing
    // $queryData['vpc_SecureHash'] = generateSecureHash($accountData['secret'], $queryData);

    // $migsUrl = 'https://migs.mastercard.com.au/vpcpay?'.http_build_query($queryData);


    $ch = curl_init("https://migs.mastercard.com.au/vpcdps");
        curl_setopt_array($ch, array(
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $queryData,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER => false
        ));

        $response = curl_exec($ch);

    print_r($response);

}

function generateMerchTxnRef() {
    $txnRef = rand(9, 9999999999999999);

    // Saved in the database associated with the order id

    return $txnRef;
}

function generateSecureHash($secret, array $params) {
    $secureHash = "";

    // Sorting params first based on the keys
    ksort($params);

    foreach ($params as $key => $value)
    {        
        // Check if key equals to vpc_SecureHash or vpc_SecureHashType to discard it
        if(in_array($key, array('vpc_SecureHash', 'vpc_SecureHashType'))) continue;

        // If key either starts with vpc_ or user_
        if(substr( $key, 0, 4 ) === "vpc_" || substr($key, 0, 5) === "user_") {

            $secureHash .= $key."=".$value."&";
        }
    }

    // Remove the last `&` character from string
    $secureHash = rtrim($secureHash, "&");

    //
    return strtoupper(hash_hmac('sha256', $secureHash, pack('H*', $secret)));
}

This is the response i am receiving

vpc_Amount=0&vpc_BatchNo=0&vpc_Locale=en&vpc_Message=Required+field+vpc_Merchant+was+not+present+in+the+request&vpc_TransactionNo=0&vpc_TxnResponseCode=7 

How will i solve this problem

  • 写回答

1条回答 默认 最新

  • 笑故挽风 2020-02-25 16:53
    关注

    You need to convert the array to a url encoded string with http_build_query

    after setting the queryData array, add

    $queryData_string = http_build_query($queryData);
    

    Then the curlpost would be set to that

    CURLOPT_POSTFIELDS => $queryData_string,
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog