/**
  * @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;
 }
 /**
  * Add embedded payment buttons to page. This only works in confirmation page.
  *
  * @param array $params name value pair of Payment processor data
  * @param string $component name of CiviCRM component that is using this Payment Processor (contribute or event)
  */
 public function embeddPaymentButtons(&$params, $component)
 {
     $this->paytrailConfig->setPaymentProcessorParams($params);
     //Load payment processor
     $paymentProcessorID = $params['payment_processor'];
     $processorDAO = new CRM_Financial_DAO_PaymentProcessor();
     $processorDAO->get("id", $paymentProcessorID);
     $merchantId = $processorDAO->user_name;
     $merchantSecret = $processorDAO->password;
     $result = $this->processPayment($params, $component, $merchantId, $merchantSecret);
     CRM_Core_Resources::singleton()->addScriptFile('com.github.anttikekki.payment.paytrail', 'payment-widget-v1.0-custom.js');
     CRM_Core_Resources::singleton()->addScriptFile('com.github.anttikekki.payment.paytrail', 'initPaymentWidget.js');
     CRM_Core_Resources::singleton()->addSetting(array('paytrail' => array('token' => $result->getToken())));
 }
示例#3
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);
     }
 }
示例#4
0
 /**
  * Save a payment processor.
  *
  * @param $values
  * @param int $domainID
  * @param $test
  *
  * @return void
  */
 public function updatePaymentProcessor(&$values, $domainID, $test)
 {
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->id = $test ? $this->_testID : $this->_id;
     $dao->domain_id = $domainID;
     $dao->is_test = $test;
     $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0);
     $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
     $dao->name = $values['name'];
     $dao->description = $values['description'];
     $dao->payment_processor_type_id = $values['payment_processor_type_id'];
     foreach ($this->_fields as $field) {
         $fieldName = $test ? "test_{$field['name']}" : $field['name'];
         $dao->{$field['name']} = trim(CRM_Utils_Array::value($fieldName, $values));
         if (empty($dao->{$field['name']})) {
             $dao->{$field['name']} = 'null';
         }
     }
     // also copy meta fields from the info DAO
     $dao->is_recur = $this->_ppDAO->is_recur;
     $dao->billing_mode = $this->_ppDAO->billing_mode;
     $dao->class_name = $this->_ppDAO->class_name;
     $dao->payment_type = $this->_ppDAO->payment_type;
     $dao->save();
     //CRM-11515
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
     $params = array('entity_table' => 'civicrm_payment_processor', 'entity_id' => $dao->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $values['financial_account_id']);
     CRM_Financial_BAO_FinancialTypeAccount::add($params);
 }
示例#5
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;
 }
示例#6
0
文件: Payment.php 项目: hguru/224Civi
 /**
  * {@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]);
 }
示例#7
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));
 }
 /**
  * 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);
 }
示例#10
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['payment_processor'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }