예제 #1
0
파일: Payment.php 프로젝트: hguru/224Civi
 /**
  * {@inheritdoc}
  */
 public function onPreInstall(CRM_Extension_Info $info)
 {
     $paymentProcessorTypes = $this->_getAllPaymentProcessorTypes('class_name');
     if (array_key_exists($info->key, $paymentProcessorTypes)) {
         CRM_Core_Error::fatal('This payment processor type is already installed.');
     }
     $ppByName = $this->_getAllPaymentProcessorTypes('name');
     if (array_key_exists($info->name, $ppByName)) {
         CRM_Core_Error::fatal('This payment processor type already exists.');
     }
     $dao = new CRM_Financial_DAO_PaymentProcessorType();
     $dao->is_active = 1;
     $dao->class_name = trim($info->key);
     $dao->title = trim($info->name) . ' (' . trim($info->key) . ')';
     $dao->name = trim($info->name);
     $dao->description = trim($info->description);
     $dao->user_name_label = trim($info->typeInfo['userNameLabel']);
     $dao->password_label = trim($info->typeInfo['passwordLabel']);
     $dao->signature_label = trim($info->typeInfo['signatureLabel']);
     $dao->subject_label = trim($info->typeInfo['subjectLabel']);
     $dao->url_site_default = trim($info->typeInfo['urlSiteDefault']);
     $dao->url_api_default = trim($info->typeInfo['urlApiDefault']);
     $dao->url_recur_default = trim($info->typeInfo['urlRecurDefault']);
     $dao->url_site_test_default = trim($info->typeInfo['urlSiteTestDefault']);
     $dao->url_api_test_default = trim($info->typeInfo['urlApiTestDefault']);
     $dao->url_recur_test_default = trim($info->typeInfo['urlRecurTestDefault']);
     $dao->url_button_default = trim($info->typeInfo['urlButtonDefault']);
     $dao->url_button_test_default = trim($info->typeInfo['urlButtonTestDefault']);
     switch (trim($info->typeInfo['billingMode'])) {
         case 'form':
             $dao->billing_mode = CRM_Core_Payment::BILLING_MODE_FORM;
             break;
         case 'button':
             $dao->billing_mode = CRM_Core_Payment::BILLING_MODE_BUTTON;
             break;
         case 'notify':
             $dao->billing_mode = CRM_Core_Payment::BILLING_MODE_NOTIFY;
             break;
         default:
             CRM_Core_Error::fatal('Billing mode in info file has wrong value.');
     }
     $dao->is_recur = trim($info->typeInfo['isRecur']);
     $dao->payment_type = trim($info->typeInfo['paymentType']);
     $dao->save();
 }
 /**
  * Function to add the payment-processor type in the db
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  *
  * @throws Exception
  * @internal param array $ids the array that holds all the db ids
  *
  * @return object CRM_Financial_DAO_PaymentProcessorType
  * @access public
  * @static
  */
 static function create(&$params)
 {
     $paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
     $paymentProcessorType->copyValues($params);
     /*
     // adapted from CRM_Core_Extensions_Payment::install
     foreach (array(
       'class_name',
       'title',
       'name',
       'description',
       'user_name_label',
       'password_label',
       'signature_label',
       'subject_label',
       'url_site_default',
       'url_api_default',
       'url_recur_default',
       'url_site_test_default',
       'url_api_test_default',
       'url_recur_test_default',
       'url_button_default',
       'url_button_test_default',
       'billing_mode',
       'is_recur',
       'payment_type'
     ) as $trimmable) {
       if (isset($paymentProcessorType->{$trimmable})) {
         $paymentProcessorType->{$trimmable} = trim($paymentProcessorType->{$trimmable});
       }
     }
     */
     if (isset($paymentProcessorType->billing_mode)) {
         // ugh unidirectional manipulation
         if (!is_numeric($paymentProcessorType->billing_mode)) {
             $billingModes = array_flip(self::buildOptions('billing_mode'));
             if (array_key_exists($paymentProcessorType->billing_mode, $billingModes)) {
                 $paymentProcessorType->billing_mode = $billingModes[$paymentProcessorType->billing_mode];
             }
         }
         if (!array_key_exists($paymentProcessorType->billing_mode, self::buildOptions('billing_mode'))) {
             throw new Exception("Unrecognized billing_mode");
         }
     }
     // FIXME handle is_default
     if (!empty($paymentProcessorType->id)) {
         $ppByName = self::getAllPaymentProcessorTypes('name');
         if (array_key_exists($paymentProcessorType->name, $ppByName)) {
             if ($ppByName[$paymentProcessorType->name] != $paymentProcessorType->id) {
                 CRM_Core_Error::fatal('This payment processor type already exists.');
             }
         }
     }
     return $paymentProcessorType->save();
 }
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Financial_DAO_PaymentProcessorType');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Financial_BAO_PaymentProcessorType::del($this->_id);
         return;
     }
     $values = $this->controller->exportValues($this->_name);
     if (!empty($values['is_default'])) {
         $query = "\nUPDATE civicrm_payment_processor SET is_default = 0";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
     $dao = new CRM_Financial_DAO_PaymentProcessorType();
     $dao->id = $this->_id;
     $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0);
     $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
     $dao->is_recur = CRM_Utils_Array::value('is_recur', $values, 0);
     $dao->name = $values['name'];
     $dao->description = $values['description'];
     foreach ($this->_fields as $field) {
         $dao->{$field['name']} = trim($values[$field['name']]);
         if (empty($dao->{$field['name']})) {
             $dao->{$field['name']} = 'null';
         }
     }
     $dao->save();
 }