问题描述
我正在尝试使用PayPal的Classic API进行TransactionSearch.我不断收到错误81002未指定的方法:不支持指定的方法.当然,贝宝(PayPal)的文档很有帮助".有人对我可能做错了什么有什么想法?
I'm trying to use PayPal's Classic API to do a TransactionSearch. I keep getting an Error 81002 Unspecified Method: Method specified is not supported. Of course PayPal's documentation is "so" helpful. Anyone have any ideas on what I might be doing wrong?
这是我正在使用的类... API凭据是从$ this-> config加载的...
Here is the class I'm using... API credentials are loaded from $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;
}
}?>
推荐答案
感谢@Andrew.刚发现我错过了&在VERSION之前,因此它正在编译METHOD = TransactionSearchVERSION ....而不是METHOD = TransactionSearch& VERSION ...
Thanks @Andrew. Just figured out I was missing an & in front of VERSION so it was compiling METHOD=TransactionSearchVERSION.... instead of METHOD=TransactionSearch&VERSION...
如果其他人发现使用PayPal NVP有用,请不要理会.大脑多么痛苦!
Gonna leave this up in case someone else finds it useful for working with PayPal NVP. What a pain in the brain!
这篇关于不支持贝宝经典API TransactionSearch方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!