不支持PayPal Classic API TransactionSearch方法

时间:2014-03-19 22:58:01

标签: php paypal paypal-nvp

我尝试使用PayPal的Classic API来执行TransactionSearch。我一直收到错误81002未指定的方法:不支持指定的方法。当然,PayPal的文档是"所以"很有帮助。任何人对我可能做错了什么都有任何想法?

以下是我使用的课程...... API凭据是从$ this-> config ...

加载的
<?php
class PayPal {
private $base = array();
private $param = array();

public function __construct($registry) {
    $this->config = $registry->get('config');
    $this->request = $registry->get('request');

    // Operate in sandbox or live mode?
    $sandbox = $this->config->get('paypal_sandbox');

    $base = $this->base($sandbox);

    // Set request parameters
    $param['request'] = array(
        'startdate'     => '2014-03-18T00:00:00-07:00Z', // TODO Get search parameter from $this->request
        'enddate'       => '2014-03-19T14:22:23-07:00Z'
        );      

    $transactions = $this->getTransactions($base,$param);
    print_r($transactions);

}

// Set Security // 

public function base($sandbox) {

    if($sandbox=='1') { 
        $base = array(
            'url'       => 'https://api-3t.sandbox.paypal.com/nvp',
            'username'  => $this->config->get('paypal_username'),
            'password'  => $this->config->get('paypal_password'),
            'signature' => $this->config->get('paypal_signature')
            );
    }

    if($sandbox=='0') { 
        $base = array(
            'url'       => 'https://api-3t.paypal.com/nvp',
            'username'  => $this->config->get('paypal_username'),
            'password'  => $this->config->get('paypal_password'),
            'signature' => $this->config->get('paypal_signature')
            );
    }       

    return $base; 
}

public function call($base,$post) {
    $post .= '&PWD='.$base['password'];
    $post .= '&USER='.$base['username'];
    $post .= '&SIGNATURE='.$base['signature'];

    $ch = curl_init($base['url']);
    curl_setopt($ch, CURLOPT_PORT, 443);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);    


    $response = curl_exec($ch);
    if(empty($response)) { return 'No response received.'; }
    else {

        return $response;
    }

    curl_close($ch);
}

// Transactions (Classic API) //

public function getTransactions($base,$param) {
    $post  = 'METHOD=TransactionSearch';
    $post .= 'VERSION=58.0';

    foreach ($param['request'] as $key => $value) {
            $post .= '&' . strtoupper($key) . '=' . $value;
    }

    $transactions = $this->call($base,$post);
    return $transactions;
}

} ?&GT;

1 个答案:

答案 0 :(得分:0)

谢谢@Andrew。刚想通我错过了一个&amp;在VERSION前面所以编译METHOD = TransactionSearchVERSION ....而不是METHOD = TransactionSearch&amp; VERSION ......

如果其他人发现使用PayPal NVP有用,请留下它。大脑多么痛苦啊!