使用2方集成模型进行PHP主卡集成

时间:2014-06-09 12:19:00

标签: php mastercard

我正在使用2-Party集成模型进行MIGS与php的集成。我已经在网上下载了一些优秀的pdf,除了给出了如何完成集成的草图,没有解释了代码方面的集成,从而使初学者很难遵循或理解..

这是我的表格,它收集客户的信用卡详细信息以及其他结算信息:

<form action="" method="post">

<table>
<tr>
<td>Cardholder's First Name:</td>
<td><input type="text" name="First_Name"></td>
</tr><tr>
<td>Cardholder's Last Name:</td>
<td><input type="text" name="Last_Name"></td>
</tr><tr>
<td>Credit Card Number:</td>
<td><input type="text" name="Card_Num"></td>
</tr><tr>
<td colspan="2" align="center">
<small>Please enter the expiration date as follows:
two digits of month and two digits of year.
For instance, January 2008 has to be entered as 0108:</small></td>
</tr><tr>
<td>Exp. date (mmyy):</td>
<td><input type="text" name="Exp_Date" maxlength="4"></td>
</tr><tr>
<td colspan="2" align="center">
<small>The Card Verification Code (Card ID or CVV2)
is required for American Express,Visa and MasterCard.
Please enter: for American Express - 4 digits on front of card;
for Visa and Mastercard - last 3 digits on back of card:</small>
</td>
</tr><tr>
<td>Card Number:</td>
<td><input type="text" name="Card_Code"></td>
</tr><tr>
<td colspan="2" align="center"><small>
Please enter the address at which the credit card bills are received:
</small></td>
</tr><tr>
<td>Street Address:</td>
<td><input type="text" name="Address"></td>
</tr><tr>
<td>City:</td>
<td><input type="text" name="City"></td>
</tr><tr>
<td>State/Province:</td>
<td><input type="text" name="State"></td>
</tr><tr>
<td>Zip/Postal Code:</td>
<td><input type="text" name="Zip"></td>
</tr><tr>
<td>Country:</td>
<td><input type="text" name="Country"></td>
</tr><tr>
<td colspan="2" align="center">
<input type="submit" value="Submit payment">
</td>
</tr>
</table>
</form>

这里是php集成代码:

$accessCode    =  "";//value from migs payment gateway
$merchantId    =  "";//value from migs payment gateway
$amount = 1000;
$unique_id = rand(999999,8988888888);//this is a sample random no
$order = rand(10,100);

$testarr = array(
"vpc_Amount" => $amount*100,//Final price should be multifly by 100
"vpc_Currency" => 'KES',
"vpc_AccessCode" => $accessCode,//Put your access code here
"vpc_Command"=> "pay",
"vpc_Locale"=> "en",
"vpc_MerchTxnRef"=> $unique_id , //This should be something unique number, i have used the session id for this
"vpc_Merchant"=> $merchantId,//Add your merchant number here
"vpc_OrderInfo"=> $order,//this also better to be a unique number
"vpc_ReturnURL"=> "http:/mydomain/mastercard/success.php",
"vpc_Version"=> "1");

ksort($testarr);

$SECURE_SECRET =  ""; //value from migs payment gateway

$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");

然后我在我的返回网址 var_dump($ _ GET); 上执行转储,返回以下内容:

mydomain/mastercard/success.php?vpc_Amount=100000&vpc_BatchNo=0&vpc_Command=pay&vpc_Locale=en&vpc_MerchTxnRef=5204024700&vpc_Merchant=$merchantId&vpc_Message=Merchant+[$merchantId]+does+not+exist&vpc_OrderInfo=97&vpc_TransactionNo=0&vpc_TxnResponseCode=7&vpc_Version=1

它会返回一条消息,说商家不存在......这是我遇到的问题之一。

所以我的问题编号:

  1. 我将哪个网址作为我的动作&#39;在用户输入详细信息后,其详细信息由付款服务器处理,如何将表单与付款服务器集成?

  2. 为什么我收到的商家不存在&#39;响应

1 个答案:

答案 0 :(得分:1)

您需要在此处更改一些内容:

生成交易/订单ID

这些数字不需要是随机的,但它们应该是唯一的。如果您使用mysql数据库来存储订单,最简单的解决方案是使用DB的自动增量字段来生成订单和交易ID。

  • 将订单记录插入数据库,状态为&#34;待定&#34; (在订单表中)
  • 记下插入的ID
  • 将交易记录插入数据库(在交易表中),状态为&#34;待定&#34;
  • 记下插入的交易ID

然后,使用您刚刚为请求插入的行的订单和交易ID。 会话ID不是唯一的 - 它们会重复。此外,10-100之间的随机数将非常频繁地重复。

发送付款信息

您目前无法将信用卡信息发送到付款网关 - 您需要将信用卡信息包含在您发送的数据中。

$testarr['vpc_CardNum'] = $_POST['Card_Num'];
$testarr['vpc_CardExp'] $_POST['Card_Exp'];

传输数据:

两方集成并不涉及客户端浏览器 - 您目前正在将它们重定向到MIGS网站,这对于此集成方法不正确。

相反,您希望使用curl将数据直接传输到支付网关。

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

$response = curl_exec($ch);
// process response here

使用双方身份验证时,付款表单的操作应指向您用于将付款信息发送到MIGS服务器的PHP脚本。

你最有可能找到一个未被发现的商家&#34;错误,因为您试图通过GET而不是POST发送付款请求。