通过使用贝宝集中付款API需要通过IPN捕获和存储接收器的详细信息
-
26-09-2019 - |
题
这是一个关于贝宝集中付款IPN问题。我的平台是的 PHP和MySQL 强>
所有通过贝宝支持网站,我发现IPN只有付款。我需要一个IPN类似的线集中付款,但无法找到它。也试图与现有的集中付款NVP代码尝试,但也不能工作。
我所试图做的是,让所有人都为之付款已通过集中付款成功发送收件人,我想记录我自己的数据库表他们的电子邮件,数量和UNIQUE_ID。如果可能的话,我想捕捉的付款状态为好,它是否已经失败的成功,基于同样的,我需要做一些内部处理。
<强>的现有代码集中付款代码如下:强>
<?php
$environment = 'sandbox'; // or 'beta-sandbox' or 'live'
/**
* Send HTTP POST Request
*
* @param string The API method name
* @param string The POST Message fields in &name=value pair format
* @return array Parsed HTTP Response body
*/
function PPHttpPost($methodName_, $nvpStr_) {
global $environment;
// Set up your API credentials, PayPal end point, and API version.
$API_UserName = urlencode('my_api_username');
$API_Password = urlencode('my_api_password');
$API_Signature = urlencode('my_api_signature');
$API_Endpoint = "https://api-3t.paypal.com/nvp";
if("sandbox" === $environment || "beta-sandbox" === $environment) {
$API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
}
$version = urlencode('51.0');
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
}
// Extract the response details.
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}
return $httpParsedResponseAr;
}
// Set request-specific fields.
$emailSubject =urlencode('example_email_subject');
$receiverType = urlencode('EmailAddress');
$currency = urlencode('USD'); // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
// Add request-specific fields to the request string.
$nvpStr="&EMAILSUBJECT=$emailSubject&RECEIVERTYPE=$receiverType&CURRENCYCODE=$currency";
$receiversArray = array();
for($i = 0; $i < 3; $i++) {
$receiverData = array( 'receiverEmail' => "user$i@paypal.com",
'amount' => "example_amount",
'uniqueID' => "example_unique_id",
'note' => "example_note");
$receiversArray[$i] = $receiverData;
}
foreach($receiversArray as $i => $receiverData) {
$receiverEmail = urlencode($receiverData['receiverEmail']);
$amount = urlencode($receiverData['amount']);
$uniqueID = urlencode($receiverData['uniqueID']);
$note = urlencode($receiverData['note']);
$nvpStr .= "&L_EMAIL$i=$receiverEmail&L_Amt$i=$amount&L_UNIQUEID$i=$uniqueID&L_NOTE$i=$note";
}
// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('MassPay', $nvpStr);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
exit('MassPay Completed Successfully: '.print_r($httpParsedResponseAr, true));
} else {
exit('MassPay failed: ' . print_r($httpParsedResponseAr, true));
}
?>
在上面的代码中,如何以及我在哪里添加代码以捕获予上文所要求的字段?任何指示溶液代码高度赞赏。
非常感谢你。
解决方案
我比较熟悉,经常性付款,但我认为IPN响应将发回你正在寻找的值。只要捕获出来的阵列的发回,将它们放置在一些变量,并保存到数据库中。
$email = $httpParsedResponseAr["receiver_email"];
$amount = $httpParsedResponseAr["mc_currency_x"];
下面是用于集中付款变量的值,点击 https://cms.paypal.com/us / cgi-bin目录/?CMD = _render含量&CONTENT_ID =显影剂/ e_howto_html_IPNandPDTVariables
其他提示
通常有两种方式来获得这些数据,一个是看从呼叫您对直接masspay响应,另一种是为您的帐户设置IPN。
您必须设置全球IPN,我不能找到一种方法,在IPN发送听网址作为此调用的变量。
HTH -FT
不隶属于 StackOverflow