CRM_Core_Error::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).'));
}
- $ppIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID);
- $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($ppIds, $this->_mode);
+ $paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID);
- $this->set('paymentProcessors', $this->_paymentProcessors);
-
- //set default payment processor
- if (!empty($this->_paymentProcessors) && empty($this->_paymentProcessor)) {
- foreach ($this->_paymentProcessors as $ppId => $values) {
- if ($values['is_default'] == 1 || (count($this->_paymentProcessors) == 1)) {
- $defaultProcessorId = $ppId;
- break;
- }
- }
- }
+ $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($paymentProcessorIDs, $this->_mode);
- if (isset($defaultProcessorId)) {
- $this->_paymentProcessor = Civi\Payment\System::singleton()->getByProcessor($defaultProcessorId, $this->_mode);
- $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor);
- }
-
- if (!CRM_Utils_System::isNull($this->_paymentProcessors)) {
- foreach ($this->_paymentProcessors as $eachPaymentProcessor) {
- // check selected payment processor is active
- if (empty($eachPaymentProcessor)) {
- CRM_Core_Error::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
- }
+ $this->set('paymentProcessors', $this->_paymentProcessors);
- $this->_paymentObject = Civi\Payment\System::singleton()->getByProcessor($eachPaymentProcessor);
- }
+ if (!empty($this->_paymentProcessors)) {
+ foreach ($this->_paymentProcessors as $paymentProcessorID => $paymentProcessorDetail) {
+ if (($processor = Civi\Payment\System::singleton()->getByProcessor($paymentProcessorDetail)) != FALSE) {
+ // We don't really know why we do this.
+ $this->_paymentObject = $processor;
+ }
+
+ if (empty($this->_paymentProcessor) && $paymentProcessorDetail['is_default'] == 1 || (count
+ ($this->_paymentProcessors) == 1)
+ ) {
+ $this->_paymentProcessor = $processor;
+ $this->assign('paymentProcessor', $this->_paymentProcessor);
+ }
+ }
+ if (empty($this->_paymentObject)) {
+ throw new CRM_Core_Exception(ts('No valid payment processor'));
+ }
+ }
+ else {
+ throw new CRM_Core_Exception(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
}
}
require_once str_replace('_', DIRECTORY_SEPARATOR, $paymentClass) . '.php';
}
- $this->cache[$id] = new $paymentClass(!empty($processor['is_test']) ? 'test' : 'live', $processor);
- if ($this->cache[$id]->checkConfig()) {
- $this->cache[$id] = NULL;
+ $processorObject = new $paymentClass(!empty($processor['is_test']) ? 'test' : 'live', $processor);
+ if ($processorObject->checkConfig()) {
+ $processorObject = NULL;
}
- }
+ else {
+ $processorObject->setPaymentProcessor($processor);
+ }
+}
+ $this->cache[$id] = $processorObject;
}
return $this->cache[$id];
}