我在php中使用Paypal MassPay API。
我的代码工作正常,但现在我收到了这个错误。
MassPay failed:
Array ( [TIMESTAMP] => 2014/07/06T17%3a27%3a04Z
[CORRELATIONID] => 5d6bf81231859
[ACK] => Failure
[VERSION] => 51%2e0
[BUILD] => 11753088
[L_ERRORCODE0] => 10314
[L_SHORTMESSAGE0] => Masspay input parse error
[L_LONGMESSAGE0] =>The input to the masspay server is incorrect e Please make sure that you are using a correctly formatted input e
[L_SEVERITYCODE0] => Error
任何人都知道为什么我现在收到这个错误?如果需要,我可以提供代码。
这是主要课程:
Paypal_class.php
<?php
class Paypal {
public function __construct($username, $password, $signature) {
$this->username = urlencode($username);
$this->password = urlencode($password);
$this->signature = urlencode($signature);
$this->version = urlencode("51.0");
$this->api = "https://api-3t.paypal.com/nvp";
//The functions can be modified but need to be urlencoded
$this->type = urlencode("EmailAddress");
$this->currency = urlencode("USD");
$this->subject = urlencode("Instant Paypal Payment");
}
public function pay($email, $amount, $note="Instant Payment") {
$string = "&EMAILSUBJECT=".$this->subject."&RECEIVERTYPE=".$this->type."&CURRENCYCODE=".$this->currency;
$string .= "&L_EMAIL0=".urlencode($email)."&L_Amt0=".urlencode($amount)."&L_NOTE0=".urlencode($note);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->api);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
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);
$request = "METHOD=MassPay&VERSION=".$this->version."&PWD=".$this->password."&USER=".$this->username."&SIGNATURE=".$this->signature."$string";
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("MassPay failed: ".curl_error($ch).'('.curl_errno($ch).')');
}
$httpResponseArray = explode("&", $httpResponse);
$httpParsedResponse = array();
foreach ($httpResponseArray as $i => $value) {
$tempArray = explode("=", $value);
if(sizeof($tempArray) > 1) {
$httpParsedResponse[$tempArray[0]] = $tempArray[1];
}
}
if((0 == sizeof($httpParsedResponse)) || !array_key_exists('ACK', $httpParsedResponse)) {
exit("Invalid HTTP Response for POST request($request) to ".$this->api);
}
return $httpParsedResponse;
}
}
?>
使用example.php文件调用此类:
<?php
require "paypal_class.php";
$paypal = new Paypal("example.com", "xyz, "abc");
$send_payment = $paypal->pay("abc@gmail.com", ".001", "Thanks for an amazing service");
if("SUCCESS" == strtoupper($send_payment["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($send_payment["ACK"])) {
exit('MassPay Completed Successfully: '.print_r($send_payment, true));
} else {
exit('MassPay failed: ' . print_r($send_payment, true));
}
?>
由于
答案 0 :(得分:0)
我能够解决我的问题。我改变了从&#34; 0.001&#34;发送的金额。至&#34; 0.01&#34;,此代码有效。 也许Paypal MassPay API不会处理小数点后超过两位数的金额。