From cd98958c90597019058562730527e9c8809ecc06 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 23 Feb 2021 09:37:01 +1300 Subject: [PATCH] [REF] Simplfiy parameter Rather than pass in contributionParams & params & combine in the function, combine when passing in. Note receive_date is always 'now' in this workflow as it is specifically the card payment workflow (for recurring) being altered here & that field is not displayed on credit card payments --- CRM/Member/Form.php | 15 +++++++++++++++ CRM/Member/Form/Membership.php | 19 +++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 5398405b6d..85532438fd 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -503,4 +503,19 @@ 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; + } + } diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index f5e5e7c251..5f74f2f801 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1254,8 +1254,7 @@ DESC limit 1"); // add all the additional payment params we need $formValues['amount'] = $params['total_amount']; - // @todo this is a candidate for beginPostProcessFunction. - $formValues['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency; + $formValues['currencyID'] = $this->getCurrency(); $formValues['description'] = ts("Contribution submitted by a staff person using member's credit card for signup"); $formValues['invoiceID'] = $this->getInvoiceID(); $formValues['financial_type_id'] = $params['financial_type_id']; @@ -1296,6 +1295,12 @@ DESC limit 1"); 'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)), 'payment_instrument_id' => $paymentInstrumentID, 'financial_type_id' => $params['financial_type_id'], + 'receive_date' => CRM_Utils_Time::date('YmdHis'), + 'tax_amount' => $params['tax_amount'] ?? NULL, + 'invoice_id' => $this->getInvoiceID(), + 'currency' => $this->getCurrency(), + 'is_pay_later' => $params['is_pay_later'] ?? 0, + 'skipLineItem' => $params['skipLineItem'] ?? 0, ] ); @@ -1863,16 +1868,6 @@ DESC limit 1"); $receiptDate = $now; } - $contributionParams = array_merge([ - 'receive_date' => !empty($params['receive_date']) ? CRM_Utils_Date::processDate($params['receive_date']) : CRM_Utils_Time::date('YmdHis'), - 'tax_amount' => $params['tax_amount'] ?? NULL, - 'invoice_id' => $this->getInvoiceID(), - 'currency' => $params['currencyID'], - 'is_pay_later' => $params['is_pay_later'] ?? 0, - //setting to make available to hook - although seems wrong to set on form for BAO hook availability - 'skipLineItem' => $params['skipLineItem'] ?? 0, - ], $contributionParams); - if ($this->getSubmittedValue('send_receipt')) { $contributionParams += [ 'receipt_date' => $receiptDate, -- 2.25.1