首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Paypal Masspay API Masspay输入解析错误

Paypal Masspay API Masspay输入解析错误
EN

Stack Overflow用户
提问于 2014-07-06 18:02:44
回答 1查看 1.2K关注 0票数 0

我在php中使用Paypal MassPay API。

我的代码运行良好,但现在我得到了这个错误。

代码语言:javascript
复制
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 

有人知道我现在为什么会犯这个错误吗?如果需要的话我可以提供代码。

这是主要的课程:

代码语言:javascript
复制
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文件调用该类:

代码语言:javascript
复制
<?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));
    }
?>

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-07 04:14:22

我解决了我的问题。我将要发送的金额从"0.001“更改为”0.001“,此代码有效。可能是贝宝MassPay API不处理小数点后有超过两位数的数量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24598739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档