From 3f5597d53cefed11680972aa5512ebf6f6927f6b Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 21 Nov 2023 18:37:55 +1300 Subject: [PATCH] Unshare another toxic function --- CRM/Contribute/Form/Contribution.php | 60 +++++++++++++++++++- CRM/Contribute/Form/Contribution/Confirm.php | 10 ++-- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 827f73e3e2..feeb89306b 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1415,9 +1415,8 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } if (isset($params['amount'])) { - $contributionParams = array_merge(CRM_Contribute_Form_Contribution_Confirm::getContributionParams( - $params, $financialType->id, - NULL, $receiptDate, + $contributionParams = array_merge($this->getContributionParams( + $params, $financialType->id, $receiptDate, $recurringContributionID), $contributionParams ); $contributionParams['non_deductible_amount'] = CRM_Contribute_Form_Contribution_Confirm::getNonDeductibleAmount($params, $financialType, FALSE, $form); @@ -1513,6 +1512,61 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return $recurring->id; } + /** + * Set the parameters to be passed to contribution create function. + * + * Previously shared function. + * + * @param array $params + * @param int $financialTypeID + * @param string $receiptDate + * @param int $recurringContributionID + * + * @return array + * @throws \CRM_Core_Exception + */ + private function getContributionParams( + $params, $financialTypeID, $receiptDate, $recurringContributionID) { + $contributionParams = [ + 'financial_type_id' => $financialTypeID, + 'receive_date' => !empty($params['receive_date']) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), + 'tax_amount' => $params['tax_amount'] ?? NULL, + 'amount_level' => $params['amount_level'] ?? NULL, + 'invoice_id' => $params['invoiceID'], + 'currency' => $params['currencyID'], + 'is_pay_later' => $params['is_pay_later'] ?? 0, + //configure cancel reason, cancel date and thankyou date + //from 'contribution' type profile if included + 'cancel_reason' => $params['cancel_reason'] ?? 0, + 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : NULL, + 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : NULL, + //setting to make available to hook - although seems wrong to set on form for BAO hook availability + 'skipLineItem' => $params['skipLineItem'] ?? 0, + ]; + + if (!empty($params["is_email_receipt"])) { + $contributionParams += [ + 'receipt_date' => $receiptDate, + ]; + } + + if ($recurringContributionID) { + $contributionParams['contribution_recur_id'] = $recurringContributionID; + } + + $contributionParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); + if (isset($contributionParams['invoice_id'])) { + $contributionParams['id'] = CRM_Core_DAO::getFieldValue( + 'CRM_Contribute_DAO_Contribution', + $contributionParams['invoice_id'], + 'id', + 'invoice_id' + ); + } + + return $contributionParams; + } + /** * Generate the data to construct a snippet based pane. * diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index c35b1d809b..d9631af3d4 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -144,16 +144,15 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr * * @param array $params * @param int $financialTypeID - * @param array $paymentProcessorOutcome * @param string $receiptDate * @param int $recurringContributionID * * @return array * @throws \CRM_Core_Exception */ - public static function getContributionParams( + private function getContributionParams( $params, $financialTypeID, - $paymentProcessorOutcome, $receiptDate, $recurringContributionID) { + $receiptDate, $recurringContributionID) { $contributionParams = [ 'financial_type_id' => $financialTypeID, 'receive_date' => !empty($params['receive_date']) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), @@ -1039,9 +1038,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } if (isset($params['amount'])) { - $contributionParams = array_merge(self::getContributionParams( - $params, $financialType->id, - NULL, $receiptDate, + $contributionParams = array_merge($this->getContributionParams( + $params, $financialType->id, $receiptDate, $recurringContributionID), $contributionParams ); -- 2.25.1