From ee65d667aa3e5f6ea38de4e3560cbef34562421a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 24 Nov 2023 10:46:53 +1300 Subject: [PATCH] Use getCurrency() function for currency retrieval --- CRM/Contribute/Form/AbstractEditPayment.php | 10 ++++++---- CRM/Contribute/Form/Contribution.php | 11 ++++++++++- CRM/Core/Form.php | 7 +------ CRM/Event/Form/Participant.php | 8 ++++---- CRM/Member/Form.php | 15 --------------- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 6628f04085..408a4b7a56 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -404,15 +404,17 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor); } + /** - * Get current currency from DB or use default currency. + * Get the currency in use. * - * @param array $submittedValues + * This just defaults to getting the default currency + * where the form does not have better currency support. * * @return string */ - public function getCurrency($submittedValues = []) { - return $submittedValues['currency'] ?? $this->_values['currency'] ?? CRM_Core_Config::singleton()->defaultCurrency; + public function getCurrency(): string { + return (string) \Civi::settings()->get('defaultCurrency'); } /** diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 8c7e9f78b1..8db797ae7b 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -555,6 +555,15 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return $defaults; } + /** + * Get submitted currency, or use default. + * + * @return string + */ + public function getCurrency(): string { + return (string) $this->getSubmittedValue('currency') ?: CRM_Core_Config::singleton()->defaultCurrency; + } + /** * Build the form object. * @@ -1963,7 +1972,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $params = [ 'contact_id' => $this->_contactID, - 'currency' => $this->getCurrency($submittedValues), + 'currency' => $this->getCurrency(), 'skipCleanMoney' => TRUE, 'id' => $this->_id, ]; diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index aef1a07c02..539f85b6e0 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -2937,14 +2937,9 @@ class CRM_Core_Form extends HTML_QuickForm_Page { * historic, possible handling in here. As we clean that up we should * add deprecation notices into here. * - * @param array $submittedValues - * Array allowed so forms inheriting this class do not break. - * Ideally we would make a clear standard around how submitted values - * are stored (is $this->_values consistently doing that?). - * * @return string */ - public function getCurrency($submittedValues = []) { + public function getCurrency() { $currency = $this->_values['currency'] ?? NULL; // For event forms, currency is in a different spot if (empty($currency)) { diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 2632d3b0b2..60ec455520 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1037,7 +1037,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment } } unset($params['note']); - $contributionParams['currency'] = \Civi::settings()->get('defaultCurrency');; + $contributionParams['currency'] = $this->getCurrency(); $contributionParams['contact_id'] = $this->_contactID; if ($this->_id) { @@ -1423,7 +1423,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment } else { //lets carry currency, CRM-4453 - $params['fee_currency'] = \Civi::settings()->get('defaultCurrency'); + $params['fee_currency'] = $this->getCurrency(); if (!isset($lineItem[0])) { $lineItem[0] = []; } @@ -1506,7 +1506,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment 'tax_amount' => $params['tax_amount'], 'amount_level' => $params['amount_level'], 'invoice_id' => $params['invoiceID'], - 'currency' => \Civi::settings()->get('defaultCurrency'), + 'currency' => $this->getCurrency(), 'source' => $this->getSourceText(), 'is_pay_later' => FALSE, 'campaign_id' => $this->getSubmittedValue('campaign_id'), @@ -1582,7 +1582,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment 'fee_level' => $params['amount_level'] ?? NULL, 'is_pay_later' => FALSE, 'fee_amount' => $params['fee_amount'] ?? NULL, - 'fee_currency' => \Civi::settings()->get('defaultCurrency'), + 'fee_currency' => $this->getCurrency(), 'campaign_id' => $this->getSubmittedValue('campaign_id'), 'note' => $this->getSubmittedValue('note'), 'is_test' => ($this->_mode === 'test)'), diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 8779cfb41f..269010d394 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -642,21 +642,6 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { ]; } - /** - * Get the currency in use. - * - * This just defaults to getting the default currency - * as other currencies are not supported on the membership - * forms at the moment. - * - * @param array $submittedValues - * - * @return string - */ - public function getCurrency($submittedValues = []): string { - return CRM_Core_Config::singleton()->defaultCurrency; - } - /** * Get the relevant payment instrument id. * -- 2.25.1