Unshare another toxic function
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 21 Nov 2023 05:37:55 +0000 (18:37 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 21 Nov 2023 05:40:16 +0000 (18:40 +1300)
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/Contribution/Confirm.php

index 827f73e3e214959eaf280e42f36d6cc07a4e803c..feeb89306b25f72d79b23f6ee3c5f6ba724a8405 100644 (file)
@@ -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.
    *
index c35b1d809b29ad693c796c0a9fd2f537adab7120..d9631af3d484d8b84d6a1e405dc9b0cdc5c2ef5e 100644 (file)
@@ -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
       );