我已经创建了一个Paypal大规模付费应用程序,但它的响应是“资金不足”错误。
代码如下:
<?php
$environment = 'sandbox'; // or 'beta-sandbox' or 'live'
function PPHttpPost($methodName_, $nvpStr_) {
global $environment;
$API_UserName = urlencode('myusername-facilitator_api1.gmail.com');
$API_Password = urlencode('1363173069');
$API_Signature = urlencode('AIocgW-6xeVUBXWE8pFoChIyO4ClAMlqzb9NjIHfm7tgCjquZayeYDUC');
$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_";
//print_r($nvpreq);exit;
// 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' => "bhavin.radidya@gmailcom",
'amount' => "10",
'uniqueID' => "13",
'note' => "test Payment");
$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));
}
我已正确配置所有参数,但仍会返回此错误响应。 我必须在PayPal帐户上调整设置吗?
答案 0 :(得分:0)
您发送的帐户(通常与API来电者相同)需要有足够的余额资金才能发送大量付款。
我看到你正在使用默认的'辅导员'帐户;这个通常仅用于测试REST API。
继续通过应用程序&gt;创建测试帐户沙盒帐户并给它一个10万美元的慷慨余额。这应该解决。
答案 1 :(得分:0)
我遇到了与上述相同的问题。这是我解决问题的方法。
第1步: 转到相应的沙盒帐户,然后查看帐户余额的资金标签。 (如果您有0美元,您可以轻松创建新用户并分配足够的金额作为余额,比如$ 10K)
第2步: 将API凭据切换到具有足够余额的新用户。现在再次进行API调用。
此API请求也给了我足够的资金,因为我在我的帐户中添加了10K SGD,并且在进行API调用时我进行了20美元的交易。
因此请检查您的货币以及该货币的相应余额。
答案 2 :(得分:0)
导致此问题的另一种情况可能对某人有所帮助:
我的发送帐户似乎只适用于大量付款的英镑,我发送的是美元(必须按照设置的方式)。有趣,因为同一个帐户可以使用REST API接受美元付款,这就是为什么我花了一段时间才弄明白。