用paypal MassPay Paypal支付我的网站用户

时间:2014-09-12 08:44:17

标签: php cakephp paypal masspay

我正在尝试从我的网站向用户支付Paypal MassPay API。

public function PPHttppost($methodName,$nvpstr){
        $setting = $this->globalsetting();
        // Set up your API credentials, PayPal end point, and API version.
        $API_Username = $setting->paypal_api_username;
        $API_Password = $setting->paypal_api_password;
        $API_Signature = $setting->paypal_api_signature;
        $API_Environment = $setting->paypal_mode;

        $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
        $API_Version = '116.0';
        if('sandbox' === $API_Environment || 'beta-sandbox' === $API_Environment){
            $API_Endpoint = "https://api-3t.$API_Environment.paypal.com/nvp";
        }
        $version = urlencode($API_Version);
        //set curl paramaeter
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);

        //Turn of server and pakagemanager
        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,API signature in requrest

        $nvpreq = "METHOD=$methodName&VERSION=$version&PWD=$API_Password&USER=$API_Username&SIGNATURE=$API_Signature&$nvpstr";
        //set the request as POST field for curl
        curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

        //get the response from server

        $httpResponse = curl_exec($ch);

        if(!$httpResponse){
            exit("$methodName failed:".curl_error($ch).'('.curl_errno($ch).')');
        }

        //Extract the response details

        $httpResponseArray = explode('&', $httpResponse);

        $httpParsedResponseArray = array();

        foreach ($httpResponseArray as $i=>$value){
            $tmpArray = explode('=', $value);
            if(sizeof($tmpArray) > 1){
                $httpParsedResponseArray[$tmpArray[0]] = $tmpArray[1];
            }
        }
        if((0 == sizeof($httpParsedResponseArray)) || !array_key_exists('ACK',$httpParsedResponseArray)){
            exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
        }
        return $httpParsedResponseArray;
    }

$nvpstr = "RECEIVERTYPE=EmailAddress&EMAILSUBJECT=Your withdraw request was processed&L_EMAIL0=seller@gmail.com&L_AMT0=$amt&CURRENCYCODE=$currency";

public function doMassPay($nvpstr){
    $httpParsedResponseArray = $this->PPHttppost('MassPay', $nvpstr);
    pr($httpParsedResponseArray);exit;
    }

当我打电话给PayPal的MassPay api时,它会让我成功

Array
(
    [TIMESTAMP] => 2014%2d09%2d12T07%3a18%3a12Z
    [CORRELATIONID] => c4c61215cdd72
    [ACK] => Success
    [VERSION] => 116%2e0
    [BUILD] => 12786467
)

但是当我查看我的帐户日志时,它显示收件人无法接受ammount,交易被拒绝。

我用不同的测试帐户检查过,每次返回相同的响应。任何人都可以指导我在哪里以及我做错了什么?我正在使用cakephp框架并且没有使用库来调用Paypal API。

0 个答案:

没有答案