duande9301 2014-08-23 11:15
浏览 49

PayPal PHP帐户信息

I was wondering how I would go about getting the balance of my paypal, total amount of transactions and total income.

I have the following to get the balance, but I cannot find anything else about getting the total amount of transactions and total income.

<?php
$environment = 'live';   // 'sandbox', 'beta-sandbox', or 'live'
$config = array(
'username'  => 'removed',
'password'  => 'removed',
'signature' => 'removed',
'version'   => '51.0'
);
$action = 'GetBalance';
switch ($environment) {
case 'sandbox':
case 'beta-sandbox':
    $url = "https://api-3t.$environment.paypal.com/nvp";
    break;
default:
    $url = "https://api-3t.paypal.com/nvp";
}
foreach ($config as &$value) {
$value = urlencode($value);
}
$request = http_build_query(array(
"METHOD"    => $action,
"VERSION"   => $config['version'],
"USER"      => $config['username'],
"PWD"       => $config['password'],
"SIGNATURE" => $config['signature'],
"RETURNALLCURRENCIES" => 1,
));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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);    
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
if (!$response) {
echo 'Failed to retrieve paypal balance: ' . curl_error($ch) . ' (' . curl_errno($ch) .     ')';
exit;
}
parse_str($response, $result);
foreach ($result as &$value) {
$value = urldecode($value);
}
if (!isset($result['ACK']) || $result['ACK'] != "Success") {
echo "{$result['L_SEVERITYCODE0']} {$result['L_ERRORCODE0']}:     {$result['L_SHORTMESSAGE0']}
{$result['L_LONGMESSAGE0']}
";
exit;
}
$amount = $result['L_AMT0'];
?>

I cannot find the correct action to get the information I need, any help is appreciated.

  • 写回答

1条回答 默认 最新

  • duanbin198788 2014-08-23 12:15
    关注

    Managed to solve my issue, found out some information and was able to find all information out by getting a list of transactions.

    Here's a class I made specifically for these operations

        <?php
        class PayPalAPI {
            private $_config, 
                    $_url,
                    $_result;
            public function __construct($configuration) {
                $this->_config = $configuration;    
                $this->_url = "https://api-3t.paypal.com/nvp";
            }
            public function method($method, $params) {
                foreach ($this->_config as $value => $vo) {
                    $this->_config[$value] = urlencode($vo);
                }
                $holding = array(
                    "METHOD"    => $method,
                    "VERSION" => $this->_config['version'],
                    "USER" => $this->_config['username'],
                    "PWD" => $this->_config['password'],
                    "SIGNATURE" => $this->_config['signature']
                );
                foreach($params as $param => $object) {
                    $holding[$param] = $object;
                }
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $this->_url);
                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);    
                curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($holding));
                $response = curl_exec($ch);
                if(!$response)
                    $this->_result = false;
                parse_str($response, $result);
                foreach($result as $value => $vo){
                    $result[$value] = urldecode($vo);   
                }
                if (!isset($result['ACK']) || $result['ACK'] != "Success")
                    $this->_result = false;
                else
                    $this->_result = $result;
            }
            public function result(){
                return $this->_result;
            }
        }
    

    ?>

    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错