Пример #1
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $config =& CRM_Core_Config::singleton();
     if ($params['api_environment'] == 'live') {
         $savePath = $config->paymentCertPath['live'];
     } else {
         $savePath = $config->paymentCertPath['test'];
     }
     $certName = $this->controller->exportValue($this->_name, 'uploadFile');
     $cert = file_get_contents($certName);
     require_once 'Services/PayPal.php';
     require_once 'Services/PayPal/Profile/Handler/File.php';
     require_once 'Services/PayPal/Profile/API.php';
     $handler =& ProfileHandler_File::getInstance(array('path' => $savePath, 'charset' => 'iso-8859-1'));
     $pid = ProfileHandler::generateID();
     $profile =& new APIProfile($pid, $handler);
     $certFile = "{$savePath}{$pid}.cert";
     $fd = fopen($certFile, "w");
     if (!$fd) {
         CRM_Core_Error::fatal(ts("Could not open %1 file for writing", array(1 => $certFile)));
     }
     if (!fwrite($fd, $cert)) {
         CRM_Core_Error::fatal("Could not write into {$certFile}<p>");
     }
     if (!fclose($fd)) {
         CRM_Core_Error::fatal("Could not close {$certFile}<p>");
     }
     $profile->setAPIUsername($params['api_username']);
     $profile->setSubject($params['api_subject']);
     $profile->setEnvironment($params['api_environment']);
     $profile->setCertificateFile($certFile);
     $result = $profile->save();
     if (Services_PayPal::isError($result)) {
         CRM_Core_Error::statusBounce("Could not create new profile: " . $result->getMessage());
     } else {
         if ($params['api_environment'] == 'live') {
             $name = 'CIVICRM_CONTRIBUTE_PAYMENT_KEY';
         } else {
             $name = 'CIVICRM_CONTRIBUTE_PAYMENT_TEST_KEY';
         }
         $message = ts('Your %1 value is: "%2". This value must be entered in the Payment Processor section of the CiviCRM configuration file.', array(1 => $name, 2 => $pid));
         CRM_Core_Session::setStatus($message);
     }
 }
Пример #2
0
 /** 
  * Constructor 
  * 
  * @param string $mode the mode of operation: live or test
  *
  * @return void 
  */
 function CRM_Utils_Payment_PayPal($mode)
 {
     require_once 'Services/PayPal.php';
     require_once 'Services/PayPal/Profile/Handler/File.php';
     require_once 'Services/PayPal/Profile/API.php';
     $config =& CRM_Core_Config::singleton();
     $this->_handler =& ProfileHandler_File::getInstance(array('path' => $config->paymentCertPath[$mode], 'charset' => CRM_UTILS_PAYMENT_PAYPAL_CHARSET));
     if (Services_PayPal::isError($handler)) {
         return CRM_Utils_Payment_PayPal::error($handler);
     }
     $this->_profile =& APIProfile::getInstance($config->paymentKey[$mode], $this->_handler);
     if (Services_PayPal::isError($this->_profile)) {
         return CRM_Utils_Payment_PayPal::error($this->_profile);
     }
     $this->_profile->setAPIPassword($config->paymentPassword[$mode]);
     $this->_caller =& Services_PayPal::getCallerServices($this->_profile);
     if (Services_PayPal::isError($this->_caller)) {
         $ret = CRM_Utils_Payment_PayPal::error($this->_caller);
         $this->_caller = null;
         return $ret;
     }
 }