From bbf90f6a5859b18a04eb1f661ac66444da8c4dd1 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 10 Jul 2023 12:16:26 +1200 Subject: [PATCH] Minor cleanup on handling of financial type The frontend & back office contribution forms both pass financialType as an option to processRecurringContribution, no other place calls this function. The value is taken from params & then overwritten from the object. This simplifies by setting in the calling function as an array. The function should be split up & returned to the forms that call it (& refactored into nothingness) but I think it makes sense to stop passing financialType as a first step --- CRM/Contribute/Form/Contribution.php | 9 +++++++-- CRM/Contribute/Form/Contribution/Confirm.php | 18 +++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 9ee904c5a8..d1dc1816aa 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -10,6 +10,7 @@ */ use Civi\Api4\Contribution; +use Civi\Api4\FinancialType; use Civi\Payment\Exception\PaymentProcessorException; /** @@ -1292,9 +1293,13 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP if (!isset($params['is_email_receipt']) && $isEmailReceipt) { $params['is_email_receipt'] = $isEmailReceipt; } + // We may no longer need to set params['is_recur'] - it used to be used in processRecurringContribution $params['is_recur'] = $isRecur; $params['payment_instrument_id'] = $contributionParams['payment_instrument_id'] ?? NULL; - $recurringContributionID = CRM_Contribute_Form_Contribution_Confirm::processRecurringContribution($form, $params, $contactID, $financialType); + $recurringContributionID = !$isRecur ? NULL : CRM_Contribute_Form_Contribution_Confirm::processRecurringContribution($form, $params, [ + 'contact_id' => $contactID, + 'financial_type_id' => $financialType->id, + ]); $now = date('YmdHis'); $receiptDate = $params['receipt_date'] ?? NULL; @@ -1844,7 +1849,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $toType = $submittedValues['financial_type_id'] ?? NULL; $fromType = $this->_defaults['financial_type_id'] ?? NULL; if (($this->_action & CRM_Core_Action::UPDATE) && ($toType != $fromType) && ($submittedValues['non_deductible_amount'] ?? NULL)) { - $deductible = \Civi\Api4\FinancialType::get(TRUE) + $deductible = FinancialType::get(TRUE) ->addSelect('is_deductible') ->addWhere('id', 'IN', [$toType, $fromType]) ->execute()->indexBy('id')->column('is_deductible'); diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 5b28abd7af..b94fb82343 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1070,9 +1070,13 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr if (!isset($params['is_email_receipt']) && $isEmailReceipt) { $params['is_email_receipt'] = $isEmailReceipt; } + // We may no longer need to set params['is_recur'] - it used to be used in processRecurringContribution $params['is_recur'] = $isRecur; $params['payment_instrument_id'] = $contributionParams['payment_instrument_id'] ?? NULL; - $recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $financialType); + $recurringContributionID = !$isRecur ? NULL : self::processRecurringContribution($form, $params, [ + 'contact_id' => $contactID, + 'financial_type_id' => $financialType->id, + ]); $now = date('YmdHis'); $receiptDate = $params['receipt_date'] ?? NULL; @@ -1175,24 +1179,17 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr * * @param CRM_Core_Form $form * @param array $params - * @param int $contactID - * @param string $contributionType + * @param array $recurParams * * @return int|null */ - public static function processRecurringContribution($form, $params, $contactID, $contributionType) { - - if (empty($params['is_recur'])) { - return NULL; - } + public static function processRecurringContribution($form, $params, $recurParams) { - $recurParams = ['contact_id' => $contactID]; $recurParams['amount'] = $params['amount'] ?? NULL; $recurParams['auto_renew'] = $params['auto_renew'] ?? NULL; $recurParams['frequency_unit'] = $params['frequency_unit'] ?? NULL; $recurParams['frequency_interval'] = $params['frequency_interval'] ?? NULL; $recurParams['installments'] = $params['installments'] ?? NULL; - $recurParams['financial_type_id'] = $params['financial_type_id'] ?? NULL; $recurParams['currency'] = $params['currency'] ?? NULL; $recurParams['payment_instrument_id'] = $params['payment_instrument_id']; @@ -1226,7 +1223,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $recurParams['is_email_receipt'] = (bool) ($params['is_email_receipt'] ?? FALSE); // We set trxn_id=invoiceID specifically for paypal IPN. It is reset this when paypal sends us the real trxn id, CRM-2991 $recurParams['processor_id'] = $recurParams['trxn_id'] = ($params['trxn_id'] ?? $params['invoiceID']); - $recurParams['financial_type_id'] = $contributionType->id; $campaignId = $params['campaign_id'] ?? $form->_values['campaign_id'] ?? NULL; $recurParams['campaign_id'] = $campaignId; -- 2.25.1