From a050fa6b37b83de4eccdfe1d98f910cc6a660f4d Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Thu, 4 Apr 2019 11:05:21 +0100 Subject: [PATCH] Extract assignPaymentFields --- CRM/Contribute/Form/ContributionBase.php | 103 ++++++++++++----------- 1 file changed, 53 insertions(+), 50 deletions(-) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index c8e488f34b..3e40cafd8f 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -580,56 +580,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $locTypeId = array_keys($this->_params['onbehalf_location']['email']); $this->assign('onBehalfEmail', $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']); } - - //fix for CRM-3767 - $isMonetary = FALSE; - if ($this->_amount > 0.0) { - $isMonetary = TRUE; - } - elseif (!empty($this->_params['selectMembership'])) { - $memFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params['selectMembership'], 'minimum_fee'); - if ($memFee > 0.0) { - $isMonetary = TRUE; - } - } - - // The concept of contributeMode is deprecated. - // The payment processor object can provide info about the fields it shows. - if ($isMonetary && is_a($this->_paymentProcessor['object'], 'CRM_Core_Payment')) { - /** @var $paymentProcessorObject \CRM_Core_Payment */ - $paymentProcessorObject = $this->_paymentProcessor['object']; - - $paymentFields = $paymentProcessorObject->getPaymentFormFields(); - foreach ($paymentFields as $index => $paymentField) { - if (!isset($this->_params[$paymentField])) { - unset($paymentFields[$index]); - continue; - } - if ($paymentField === 'credit_card_exp_date') { - $date = CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $this->_params)); - $date = CRM_Utils_Date::mysqlToIso($date); - $this->assign('credit_card_exp_date', $date); - } - elseif ($paymentField === 'credit_card_number') { - $this->assign('credit_card_number', - CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $this->_params)) - ); - } - elseif ($paymentField === 'credit_card_type') { - $this->assign('credit_card_type', CRM_Core_PseudoConstant::getLabel( - 'CRM_Core_BAO_FinancialTrxn', - 'card_type_id', - CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'card_type_id', $this->_params['credit_card_type']) - )); - } - else { - $this->assign($paymentField, $this->_params[$paymentField]); - } - } - $this->assign('paymentFieldsetLabel', CRM_Core_Payment_Form::getPaymentLabel($paymentProcessorObject)); - $this->assign('paymentFields', $paymentFields); - - } + $this->assignPaymentFields(); $this->assign('email', $this->controller->exportValue('Main', "email-{$this->_bltID}") @@ -806,6 +757,58 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } } + public function assignPaymentFields() { + //fix for CRM-3767 + $isMonetary = FALSE; + if ($this->_amount > 0.0) { + $isMonetary = TRUE; + } + elseif (!empty($this->_params['selectMembership'])) { + $memFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params['selectMembership'], 'minimum_fee'); + if ($memFee > 0.0) { + $isMonetary = TRUE; + } + } + + // The concept of contributeMode is deprecated. + // The payment processor object can provide info about the fields it shows. + if ($isMonetary && is_a($this->_paymentProcessor['object'], 'CRM_Core_Payment')) { + /** @var $paymentProcessorObject \CRM_Core_Payment */ + $paymentProcessorObject = $this->_paymentProcessor['object']; + + $paymentFields = $paymentProcessorObject->getPaymentFormFields(); + foreach ($paymentFields as $index => $paymentField) { + if (!isset($this->_params[$paymentField])) { + unset($paymentFields[$index]); + continue; + } + if ($paymentField === 'credit_card_exp_date') { + $date = CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $this->_params)); + $date = CRM_Utils_Date::mysqlToIso($date); + $this->assign('credit_card_exp_date', $date); + } + elseif ($paymentField === 'credit_card_number') { + $this->assign('credit_card_number', + CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $this->_params)) + ); + } + elseif ($paymentField === 'credit_card_type') { + $this->assign('credit_card_type', CRM_Core_PseudoConstant::getLabel( + 'CRM_Core_BAO_FinancialTrxn', + 'card_type_id', + CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'card_type_id', $this->_params['credit_card_type']) + )); + } + else { + $this->assign($paymentField, $this->_params[$paymentField]); + } + } + $this->assign('paymentFieldsetLabel', CRM_Core_Payment_Form::getPaymentLabel($paymentProcessorObject)); + $this->assign('paymentFields', $paymentFields); + + } + } + /** * Display ReCAPTCHA warning on Contribution form */ -- 2.25.1