Use getCurrency() function for currency retrieval
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 23 Nov 2023 21:46:53 +0000 (10:46 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 28 Nov 2023 20:26:40 +0000 (09:26 +1300)
CRM/Contribute/Form/AbstractEditPayment.php
CRM/Contribute/Form/Contribution.php
CRM/Core/Form.php
CRM/Event/Form/Participant.php
CRM/Member/Form.php

index 6628f040857ab414c9ca6885f3e80713aebde285..408a4b7a563638faced5dee3391929679f722298 100644 (file)
@@ -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');
   }
 
   /**
index 8c7e9f78b1e11ad659b40b3e829f7f2550442fc0..8db797ae7b63458ff63e0b0fe9a2af03b4e5af1b 100644 (file)
@@ -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,
       ];
index aef1a07c02d125d998fdc36c4ba593cb316f8d1e..539f85b6e048a26a5c7265c4742cab03240b244e 100644 (file)
@@ -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)) {
index 2632d3b0b2eefb462a33d27b8cb7d0dbbc81c723..60ec4555209e44f0110c9ca0c732867d54d8c88f 100644 (file)
@@ -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)'),
index 8779cfb41f9d0ee620e904ffe1e8b6b9bfe59f51..269010d3948fb8e030c429ba56ab86d1a631f697 100644 (file)
@@ -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.
    *