Move function only used by bin/ContributionProcessor to that class
authoreileen <emcnaughton@wikimedia.org>
Mon, 14 Sep 2020 00:39:16 +0000 (12:39 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 14 Sep 2020 00:39:16 +0000 (12:39 +1200)
We should find a way to move this out of core - it seems likely it's never used but since being moved out
of svn it's had about 40 commits - all of which are just 'general maintenance' - licensing, coding standards etc.

There is an overhead in maintaining it....

CRM/Contribute/BAO/Contribution/Utils.php
bin/ContributionProcessor.php

index 683b92c6a618826c9e695dbc7246b00f23371b13..af50415499f95453e200e256f74fe366076e0c74 100644 (file)
@@ -345,78 +345,6 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     }
   }
 
-  /**
-   * @param array $params
-   * @param string $type
-   *
-   * @return bool
-   */
-  public static function _fillCommonParams(&$params, $type = 'paypal') {
-    if (array_key_exists('transaction', $params)) {
-      $transaction = &$params['transaction'];
-    }
-    else {
-      $transaction = &$params;
-    }
-
-    $params['contact_type'] = 'Individual';
-
-    $billingLocTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Billing', 'id', 'name');
-    if (!$billingLocTypeId) {
-      $billingLocTypeId = 1;
-    }
-    if (!CRM_Utils_System::isNull($params['address'])) {
-      $params['address'][1]['is_primary'] = 1;
-      $params['address'][1]['location_type_id'] = $billingLocTypeId;
-    }
-    if (!CRM_Utils_System::isNull($params['email'])) {
-      $params['email'] = [
-        1 => [
-          'email' => $params['email'],
-          'location_type_id' => $billingLocTypeId,
-        ],
-      ];
-    }
-
-    if (isset($transaction['trxn_id'])) {
-      // set error message if transaction has already been processed.
-      $contribution = new CRM_Contribute_DAO_Contribution();
-      $contribution->trxn_id = $transaction['trxn_id'];
-      if ($contribution->find(TRUE)) {
-        $params['error'][] = ts('transaction already processed.');
-      }
-    }
-    else {
-      // generate a new transaction id, if not already exist
-      $transaction['trxn_id'] = md5(uniqid(rand(), TRUE));
-    }
-
-    if (!isset($transaction['financial_type_id'])) {
-      $contributionTypes = array_keys(CRM_Contribute_PseudoConstant::financialType());
-      $transaction['financial_type_id'] = $contributionTypes[0];
-    }
-
-    if (($type == 'paypal') && (!isset($transaction['net_amount']))) {
-      $transaction['net_amount'] = $transaction['total_amount'] - CRM_Utils_Array::value('fee_amount', $transaction, 0);
-    }
-
-    if (!isset($transaction['invoice_id'])) {
-      $transaction['invoice_id'] = $transaction['trxn_id'];
-    }
-
-    $source = ts('ContributionProcessor: %1 API',
-      [1 => ucfirst($type)]
-    );
-    if (isset($transaction['source'])) {
-      $transaction['source'] = $source . ':: ' . $transaction['source'];
-    }
-    else {
-      $transaction['source'] = $source;
-    }
-
-    return TRUE;
-  }
-
   /**
    * @param int $contactID
    *
index a3a22d632cbe76a59e2306160bf1d2d20a34b9a4..a6c7bee51d019b71bfd2f7d83fd9ee79a607771d 100644 (file)
@@ -353,7 +353,7 @@ class CiviContributeProcessor {
         $params += $transaction;
       }
 
-      CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
+      self::_fillCommonParams($params, $type);
 
       return $params;
     }
@@ -383,7 +383,7 @@ class CiviContributeProcessor {
         $params += $transaction;
       }
 
-      CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
+      self::_fillCommonParams($params, $type);
 
       return $params;
     }
@@ -457,6 +457,78 @@ class CiviContributeProcessor {
     return TRUE;
   }
 
+  /**
+   * @param array $params
+   * @param string $type
+   *
+   * @return bool
+   */
+  public static function _fillCommonParams(&$params, $type = 'paypal') {
+    if (array_key_exists('transaction', $params)) {
+      $transaction = &$params['transaction'];
+    }
+    else {
+      $transaction = &$params;
+    }
+
+    $params['contact_type'] = 'Individual';
+
+    $billingLocTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Billing', 'id', 'name');
+    if (!$billingLocTypeId) {
+      $billingLocTypeId = 1;
+    }
+    if (!CRM_Utils_System::isNull($params['address'])) {
+      $params['address'][1]['is_primary'] = 1;
+      $params['address'][1]['location_type_id'] = $billingLocTypeId;
+    }
+    if (!CRM_Utils_System::isNull($params['email'])) {
+      $params['email'] = [
+        1 => [
+          'email' => $params['email'],
+          'location_type_id' => $billingLocTypeId,
+        ],
+      ];
+    }
+
+    if (isset($transaction['trxn_id'])) {
+      // set error message if transaction has already been processed.
+      $contribution = new CRM_Contribute_DAO_Contribution();
+      $contribution->trxn_id = $transaction['trxn_id'];
+      if ($contribution->find(TRUE)) {
+        $params['error'][] = ts('transaction already processed.');
+      }
+    }
+    else {
+      // generate a new transaction id, if not already exist
+      $transaction['trxn_id'] = md5(uniqid(rand(), TRUE));
+    }
+
+    if (!isset($transaction['financial_type_id'])) {
+      $contributionTypes = array_keys(CRM_Contribute_PseudoConstant::financialType());
+      $transaction['financial_type_id'] = $contributionTypes[0];
+    }
+
+    if (($type == 'paypal') && (!isset($transaction['net_amount']))) {
+      $transaction['net_amount'] = $transaction['total_amount'] - CRM_Utils_Array::value('fee_amount', $transaction, 0);
+    }
+
+    if (!isset($transaction['invoice_id'])) {
+      $transaction['invoice_id'] = $transaction['trxn_id'];
+    }
+
+    $source = ts('ContributionProcessor: %1 API',
+      [1 => ucfirst($type)]
+    );
+    if (isset($transaction['source'])) {
+      $transaction['source'] = $source . ':: ' . $transaction['source'];
+    }
+    else {
+      $transaction['source'] = $source;
+    }
+
+    return TRUE;
+  }
+
 }
 
 // bootstrap the environment and run the processor