PHP SDK Notes
2/26/2006

1.  Important global variables:

$_SESSION['pphandler']
$_SESSION['pphandler_params']

$_FILES['certificate_file']


2.  WebConsole/api_create.php:

	This section of code creates a profile:
	
	    if(empty($errors))
    {
        $handlerinst =& _getHandlerInstance($_SESSION['pphandler'], $_SESSION['pphandler_params']);

        if(!Services_PayPal::isError($handlerinst))
        {
            $pid = ProfileHandler::generateID();

            $profile = new APIProfile($pid, $handlerinst);

            $save_file = "$cert_save_path/$pid.cert";

            if(!move_uploaded_file($_FILES['certificate_file']['tmp_name'],
                                   $save_file))
            {
                $errors['unknown'][] = "Could not store uploaded certificate '{$_FILES['certificate_file']['tmp_name']}'";
            }

            $profile->setAPIUsername($_POST['api_username']);
            $profile->setSubject($_POST['api_subject']);
            $profile->setEnvironment($_POST['environment']);
            $profile->setCertificateFile($save_file);

            $result = $profile->save();

            if(Services_PayPal::isError($result))
            {
                $errors['unknown'][] = "Could not create new profile: ".$result->getMessage();
            }
        }
        else
        {
            $errors['unknown'][] = "Could not create a new Profile Handler: ". $handlerinst->getMessage();
        }
        
3.  Logging

- Only called in PayPal/CallerServices.php
- See getLogger() and setLogger() methods.

    function &getLogger()
    {
        if (!$this->_logger) {
            $file = $this->_logDir . '/' . date('Ymd') . '.PayPal.log';
            if (is_link($file) || (file_exists($file) && !is_writable($file))) {
                // Don't overwrite symlinks.
                return Services_PayPal::raiseError('bad logfile');
            }

            $this->_logger = &Log::singleton('file', $file, $this->_profile->getAPIUsername(), array('append' => true));
        }

        return $this->_logger;
    }

    function _logTransaction($operation, $elapsed, $response)
    {
        $logger =& $this->getLogger();
        if (Services_PayPal::isError($logger)) {
            return $logger;
        }

        switch ($this->_logLevel) {
        case PEAR_LOG_DEBUG:
            $logger->log('Request XML: ' . $this->_sanitizeLog($this->__last_request), PEAR_LOG_DEBUG);
            $logger->log('Response XML: ' . $this->_sanitizeLog($this->__last_response), PEAR_LOG_DEBUG);

        case PEAR_LOG_INFO:
            $ack = is_object($response) && method_exists($response, 'getAck') ? ', Ack: ' . $response->getAck() : '';
            $logger->log($operation . ', Elapsed: ' . $elapsed . 'ms' . $ack, PEAR_LOG_INFO);

        case PEAR_LOG_ERR:
            if (Services_PayPal::isError($response)) {
                $logger->log($response, PEAR_LOG_ERR);
            }
        }
    }
    
    4.  Constructing CallerServices:
    
    $caller =& Services_PayPal::getCallerServices($_SESSION['APIProfile']);
    