0

我正在尝试使用 PayPal 的经典 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;
}

} ?>

4

1 回答 1

0

谢谢@安德鲁。刚刚发现我在 VERSION 前面缺少一个 & 所以它正在编译 METHOD=TransactionSearchVERSION.... 而不是 METHOD=TransactionSearch&VERSION...

如果其他人发现它对使用 PayPal NVP 很有用,我会保留它。大脑多么痛苦!

于 2014-03-20T15:05:23.767 回答