From 2c5311b964d72a43238991eef6467229bea625bc Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 29 Jun 2015 01:29:47 +1200 Subject: [PATCH] CRM-16755 fix loading of payment processors (exclude invalid & regression on event --- CRM/Event/Form/Registration.php | 45 ++----------------- CRM/Financial/BAO/PaymentProcessor.php | 32 +++---------- .../CRM/Event/Form/Registration/Register.tpl | 11 +++-- 3 files changed, 16 insertions(+), 72 deletions(-) diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 55566e1b3a..af456ab853 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -288,51 +288,14 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { // check for is_monetary status $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']); $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'is_pay_later'); - //check for variour combination for paylater, payment + //check for various combinations for paylater, payment //process with paid event. if ($isMonetary && (!$isPayLater || !empty($this->_values['event']['payment_processor']))) { - $ppID = CRM_Utils_Array::value('payment_processor', + $this->_paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('payment_processor', $this->_values['event'] - ); - if (!$ppID) { - CRM_Core_Error::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl); - } - $ppIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID); - $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($ppIds, - $this->_mode - ); - $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->assignPaymentProcessor(); - if (isset($defaultProcessorId)) { - $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($defaultProcessorId, $this->_mode); - } - // make sure we have a valid payment class, else abort - if ($this->_values['event']['is_monetary']) { - if (!CRM_Utils_System::isNull($this->_paymentProcessors)) { - foreach ($this->_paymentProcessors as $eachPaymentProcessor) { - // check selected payment processor is active - if (!$eachPaymentProcessor) { - CRM_Core_Error::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.')); - } - // ensure that processor has a valid config - $payment = CRM_Core_Payment::singleton($this->_mode, $eachPaymentProcessor, $this); - $error = $payment->checkConfig(); - if (!empty($error)) { - CRM_Core_Error::fatal($error); - } - } - } - } } //init event fee. self::initEventFee($this, $this->_eventId); diff --git a/CRM/Financial/BAO/PaymentProcessor.php b/CRM/Financial/BAO/PaymentProcessor.php index dab67d793b..edbd08aa50 100644 --- a/CRM/Financial/BAO/PaymentProcessor.php +++ b/CRM/Financial/BAO/PaymentProcessor.php @@ -175,6 +175,8 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces /** * Get the payment processor details. * + * @deprecated Use Civi\Payment\System::singleton->getByID(); + * * @param int $paymentProcessorID * Payment processor id. * @param string $mode @@ -230,32 +232,6 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces )); } - /** - * User getPaymentProcessors. - * - * @deprecated - * - * @param $paymentProcessorIDs - * @param $mode - * - * @return array - * @throws Exception - */ - public static function getPayments($paymentProcessorIDs, $mode) { - if (!$paymentProcessorIDs) { - CRM_Core_Error::fatal(ts('Invalid value passed to getPayment function')); - } - - $payments = array(); - foreach ($paymentProcessorIDs as $paymentProcessorID) { - $payment = self::getPayment($paymentProcessorID, $mode); - $payments[$payment['id']] = $payment; - } - - uasort($payments, 'self::defaultComparison'); - return $payments; - } - /** * Compare 2 payment processors to see which should go first based on is_default * (sort function for sortDefaultFirst) @@ -276,6 +252,8 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces /** * Build payment processor details. * + * @deprecated + * * @param object $dao * Payment processor object. * @param string $mode @@ -284,7 +262,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces * @return array * associated array with payment processor related fields */ - public static function buildPayment($dao, $mode) { + protected static function buildPayment($dao, $mode) { $fields = array( 'id', 'name', diff --git a/templates/CRM/Event/Form/Registration/Register.tpl b/templates/CRM/Event/Form/Registration/Register.tpl index 93ac090e2b..cb8f1db459 100644 --- a/templates/CRM/Event/Form/Registration/Register.tpl +++ b/templates/CRM/Event/Form/Registration/Register.tpl @@ -141,7 +141,7 @@
{* If we have a payment processor, load it - otherwise it happens via ajax *} {if $paymentProcessorID or $isBillingAddressRequiredForPayLater} - {include file="CRM/Event/Form/Registration/Register.tpl" snippet=4} + {include file="CRM/Financial/Form/Payment.tpl" snippet=4} {/if}
{include file="CRM/common/paymentBlock.tpl"} @@ -210,7 +210,7 @@ {/literal} -{/if} + {literal} {/literal} -- 2.25.1