【问题标题】:Paypal Masspay API Masspay input parse errorPaypal Masspay API Masspay 输入解析错误
【发布时间】:2014-08-27 05:39:37
【问题描述】:

我在 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));
    }
?>

谢谢

【问题讨论】:

  • 似乎在告诉您您的请求不正确。需要查看帮助请求的示例。
  • 谢谢!我正在为这个问题添加代码。
  • 我不是要代码示例,而是要从该代码生成的原始 API 请求的示例。基本上,您为 $request 获得并实际传递给 CURL 的最终值。 PayPal 显然不喜欢它收到的东西,所以我们需要看看它有什么问题。

标签: php paypal masspay


【解决方案1】:

我能够解决我的问题。我将要发送的金额从“0.001”更改为“0.01”,此代码有效。 可能是 Paypal MassPay API 不处理小数点后两位以上的金额。

【讨论】:

    猜你喜欢
    • 2013-08-30
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 2011-12-04
    • 2016-09-03
    • 2014-10-03
    • 2018-06-18
    • 2013-01-14
    相关资源
    最近更新 更多