/** * Validates the profile data currently loaded before use. * * @return mixed true if the data is valid, or a PayPal_Error object on failure. */ function validate() { if (empty($this->_username) || empty($this->_password) || empty($this->_certificateFile) || empty($this->_environment)) { return Services_PayPal::raiseError("API Username, Password, Certificate File and Environment must all be set"); } if (!file_exists($this->_certificateFile)) { return Services_PayPal::raiseError("Could not find certificate file '{$this->_certificateFile}'"); } if (!in_array(strtolower($this->_environment), $this->_validEnvironments, true)) { return Services_PayPal::raiseError("Environment '{$this->_environment}' is not a valid environment."); } return true; }
/** * Gets the PEAR Log object to use. * * @return Log A Log object, either provided by the user or * created by this function. */ 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; }
/** * Builds the dynamically generated portion of the CallerServices * API. * * @return string The dynamically generated API functions (PHP code). */ function buildMethods() { $methods = ''; foreach (array_keys($this->services[$this->service]['ports']) as $key) { $portcode = $this->generateProxyCode($this->services[$this->service]['ports'][$key]); if (is_null($portcode)) { return Services_PayPal::raiseError("Failed to generate code for port {$key}"); } $methods .= $portcode; } return $methods; }
/** * Set the Merchant private key file * * @param string The Merchant Private Key File * @return mixed True on success, a PayPal error object on faliure */ function setPrivateKeyFile($filename) { if (!file_exists($filename)) { return Services_PayPal::raiseError("The private key '{$filename}' does not exist"); } $this->_privateKeyFile = $filename; return true; }
/** * Write a new CallerServices.php based on CallerServices.php.in * * @param string $phpFile The full file path to write to. */ function writeCallerServices($phpFile) { $methods = $this->_generator->buildMethods(); if (Services_PayPal::isError($methods)) { return $methods; } $phpTemplate = file_get_contents(dirname(__FILE__) . '/CallerServices.php.in'); if (!$phpTemplate) { return Services_PayPal::raiseError('Unable to read CallerServices template.'); } $phpTemplate = str_replace('@@GENERATED_FUNCTIONS@@', trim($methods), $phpTemplate); $phpTemplate = str_replace('@@WSDL_VERSION@@', $this->_generator->getWSDLVersion(), $phpTemplate); $fp = fopen($phpFile, 'w'); if (!$fp) { return Services_PayPal::raiseError("Unable to write {$phpFile}."); } if (!fwrite($fp, $phpTemplate)) { return Services_PayPal::raiseError("Unable to write {$phpFile}."); } return fclose($fp); }
function &getInstance($params) { return Services_PayPal::raiseError("Cannot call this method from the base ProfileHandler class"); }
/** * Returns the PayPal public certificate filename. * * @param string The environment to get the certificate for. * @return mixed The path and file of the certificate file, or a PayPal error object on failure. */ function getPayPalCertificateFile($environment) { $package_root = Services_PayPal::getPackageRoot(); $cert = $package_root . '/cert/' . strtolower($environment) . '.paypal.com.pem'; if (@(include "{$package_root}/conf/paypal-sdk.php")) { if (isset($__PP_CONFIG['paypal_cert_file']) && !empty($__PP_CONFIG['paypal_cert_file'])) { $cert = $__PP_CONFIG['paypal_cert_file'][$environment]; } } if (!file_exists($cert)) { return Services_PayPal::raiseError("Could not file Paypal public Certificate file '{$cert}'"); } return $cert; }
function validateParams() { if (!isset($this->_params['path'])) { return Services_PayPal::raiseError("You must provide the 'path' parameter for this handler"); } if (file_exists($this->_params['path']) && is_dir($this->_params['path'])) { return true; } return false; }
/** * Set the environment associated with this profile. * * @param string True on success, a Paypal error object on failure */ function setEnvironment($environment) { $environment = strtolower($environment); $envs = $this->getValidEnvironments(); if (Services_PayPal::isError($envs)) { return $envs; } if (in_array($environment, $envs)) { $this->_environment = $environment; return true; } return Services_PayPal::raiseError("Invalid Environment Specified"); }
/** * Get information describing all types provided by the SDK. * @static */ function getTypeList() { $root_dir = Services_PayPal::getPackageRoot(); $types = "{$root_dir}/Type/*.php"; $files = glob($types); if (count($files) < 2) { return Services_PayPal::raiseError("Types not found in package! (Looked for '{$types}')"); } $retval = array(); foreach ($files as $type_files) { $retval[] = basename(substr($type_files, 0, strpos($type_files, '.'))); } return $retval; }