Пример #1
0
 /**
  * @param $id
  *
  * @return mixed
  */
 function delete($id)
 {
     $paymentProcessor = new CRM_Financial_DAO_PaymentProcessor();
     $paymentProcessor->id = $id;
     if ($paymentProcessor->find(TRUE)) {
         $result = $paymentProcessor->delete();
     }
     return $result;
 }
Пример #2
0
 /**
  * Function to get the payment processor details
  *
  * @param  int    $paymentProcessorID payment processor id
  * @param  string $mode               payment mode ie test or live
  *
  * @return array  associated array with payment processor related fields
  * @static
  * @access public
  */
 static function getPayment($paymentProcessorID, $mode)
 {
     if (!$paymentProcessorID) {
         CRM_Core_Error::fatal(ts('Invalid value passed to getPayment function'));
     }
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->id = $paymentProcessorID;
     $dao->is_active = 1;
     if (!$dao->find(TRUE)) {
         return NULL;
     }
     if ($mode == 'test') {
         $testDAO = new CRM_Financial_DAO_PaymentProcessor();
         $testDAO->name = $dao->name;
         $testDAO->is_active = 1;
         $testDAO->is_test = 1;
         if (!$testDAO->find(TRUE)) {
             CRM_Core_Error::fatal(ts('Could not retrieve payment processor details'));
         }
         return self::buildPayment($testDAO, $mode);
     } else {
         return self::buildPayment($dao, $mode);
     }
 }
Пример #3
0
 /**
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = array();
     if ($this->_ppType) {
         $defaults['payment_processor_type_id'] = $this->_ppType;
     }
     if (!$this->_id) {
         $defaults['is_active'] = $defaults['is_default'] = 1;
         $defaults['url_site'] = $this->_ppDAO->url_site_default;
         $defaults['url_api'] = $this->_ppDAO->url_api_default;
         $defaults['url_recur'] = $this->_ppDAO->url_recur_default;
         $defaults['url_button'] = $this->_ppDAO->url_button_default;
         $defaults['test_url_site'] = $this->_ppDAO->url_site_test_default;
         $defaults['test_url_api'] = $this->_ppDAO->url_api_test_default;
         $defaults['test_url_recur'] = $this->_ppDAO->url_recur_test_default;
         $defaults['test_url_button'] = $this->_ppDAO->url_button_test_default;
         return $defaults;
     }
     $domainID = CRM_Core_Config::domainID();
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->id = $this->_id;
     $dao->domain_id = $domainID;
     if (!$dao->find(TRUE)) {
         return $defaults;
     }
     CRM_Core_DAO::storeValues($dao, $defaults);
     // now get testID
     $testDAO = new CRM_Financial_DAO_PaymentProcessor();
     $testDAO->name = $dao->name;
     $testDAO->is_test = 1;
     $testDAO->domain_id = $domainID;
     if ($testDAO->find(TRUE)) {
         $this->_testID = $testDAO->id;
         foreach ($this->_fields as $field) {
             $testName = "test_{$field['name']}";
             $defaults[$testName] = $testDAO->{$field['name']};
         }
     }
     $defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($dao->id, 'civicrm_payment_processor', 'financial_account_id');
     return $defaults;
 }
Пример #4
0
 /**
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = array();
     if (!$this->_id) {
         $defaults['is_active'] = $defaults['is_default'] = 1;
         $defaults['url_site'] = $this->_ppDAO->url_site_default;
         $defaults['url_api'] = $this->_ppDAO->url_api_default;
         $defaults['url_recur'] = $this->_ppDAO->url_recur_default;
         $defaults['url_button'] = $this->_ppDAO->url_button_default;
         $defaults['test_url_site'] = $this->_ppDAO->url_site_test_default;
         $defaults['test_url_api'] = $this->_ppDAO->url_api_test_default;
         $defaults['test_url_recur'] = $this->_ppDAO->url_recur_test_default;
         $defaults['test_url_button'] = $this->_ppDAO->url_button_test_default;
         $defaults['payment_instrument_id'] = $this->_ppDAO->payment_instrument_id;
         // When user changes payment processor type, it is passed in via $this->_ppType so update defaults array.
         if ($this->_ppType) {
             $defaults['payment_processor_type_id'] = $this->_ppType;
         }
         return $defaults;
     }
     $domainID = CRM_Core_Config::domainID();
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->id = $this->_id;
     $dao->domain_id = $domainID;
     if (!$dao->find(TRUE)) {
         return $defaults;
     }
     CRM_Core_DAO::storeValues($dao, $defaults);
     // When user changes payment processor type, it is passed in via $this->_ppType so update defaults array.
     if ($this->_ppType) {
         $defaults['payment_processor_type_id'] = $this->_ppType;
     }
     $cards = json_decode(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $this->_id, 'accepted_credit_cards'), TRUE);
     $acceptedCards = array();
     if (!empty($cards)) {
         foreach ($cards as $card => $val) {
             $acceptedCards[$card] = 1;
         }
     }
     $defaults['accept_credit_cards'] = $acceptedCards;
     unset($defaults['accepted_credit_cards']);
     // now get testID
     $testDAO = new CRM_Financial_DAO_PaymentProcessor();
     $testDAO->name = $dao->name;
     $testDAO->is_test = 1;
     $testDAO->domain_id = $domainID;
     if ($testDAO->find(TRUE)) {
         $this->_testID = $testDAO->id;
         foreach ($this->_fields as $field) {
             $testName = "test_{$field['name']}";
             $defaults[$testName] = $testDAO->{$field['name']};
         }
     }
     $defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($dao->id, 'civicrm_payment_processor', 'financial_account_id');
     return $defaults;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function onPreUninstall(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 not registered.');
     }
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->payment_processor_type_id = $paymentProcessorTypes[$info->key];
     $dao->find();
     while ($dao->fetch()) {
         throw new CRM_Extension_Exception_DependencyException('payment');
     }
     $this->_runPaymentHook($info, 'uninstall');
     return CRM_Financial_BAO_PaymentProcessorType::del($paymentProcessorTypes[$info->key]);
 }
Пример #6
0
 /**
  * Get active payment processor types
  */
 private function payProcStats()
 {
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->is_active = 1;
     $dao->find();
     $ppTypes = array();
     // Get title and id for all processor types
     $ppTypeNames = CRM_Core_PseudoConstant::paymentProcessorType();
     while ($dao->fetch()) {
         $ppTypes[] = $ppTypeNames[$dao->payment_processor_type_id];
     }
     // add the .-separated list of the processor types
     $this->stats['PPTypes'] = implode(',', array_unique($ppTypes));
 }
Пример #7
0
 /**
  * Delete payment processor.
  *
  * @param int $paymentProcessorID
  *
  * @return null
  */
 public static function del($paymentProcessorID)
 {
     if (!$paymentProcessorID) {
         CRM_Core_Error::fatal(ts('Invalid value passed to delete function.'));
     }
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->id = $paymentProcessorID;
     if (!$dao->find(TRUE)) {
         return NULL;
     }
     $testDAO = new CRM_Financial_DAO_PaymentProcessor();
     $testDAO->name = $dao->name;
     $testDAO->is_test = 1;
     $testDAO->delete();
     $dao->delete();
     Civi\Payment\System::singleton()->flushProcessors();
 }
 /**
  * Browse all payment processors.
  *
  * @param null $action
  *
  * @return void
  * @access public
  * @static
  */
 function browse($action = NULL)
 {
     // get all custom groups sorted by weight
     $paymentProcessor = array();
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->is_test = 0;
     $dao->domain_id = CRM_Core_Config::domainID();
     $dao->orderBy('name');
     $dao->find();
     while ($dao->fetch()) {
         $paymentProcessor[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $paymentProcessor[$dao->id]);
         $paymentProcessor[$dao->id]['payment_processor_type'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType', $paymentProcessor[$dao->id]['payment_processor_type_id']);
         // form all action links
         $action = array_sum(array_keys($this->links()));
         // update enable/disable links.
         if ($dao->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         $paymentProcessor[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), FALSE, 'paymentProcessor.manage.action', 'PaymentProcessor', $dao->id);
         $paymentProcessor[$dao->id]['financialAccount'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($dao->id, 'civicrm_payment_processor');
     }
     $this->assign('rows', $paymentProcessor);
 }