简体   繁体   中英

PayPal PHP Account Information

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']}\n{$result['L_LONGMESSAGE0']}\n";
exit;
}
$amount = $result['L_AMT0'];
?>

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

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;
        }
    }

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM