Remove usage of deprecated function and duplicated code in getPayment()
authorMatthew Wire <devel@mrwire.co.uk>
Sat, 28 Apr 2018 15:16:27 +0000 (16:16 +0100)
committerMatthew Wire <devel@mrwire.co.uk>
Sat, 28 Apr 2018 15:32:33 +0000 (16:32 +0100)
CRM/Financial/BAO/PaymentProcessor.php
CRM/Utils/VersionCheck.php

index 636706852c6a757a12bb124fef02ecfb40a27793..86addccd3e950f3856a6a314d652127c7ffe46bd 100644 (file)
@@ -218,34 +218,6 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
   public static function getPayment($paymentProcessorID, $mode = 'based_on_id') {
     $capabilities = ($mode == 'test') ? array('TestMode') : array();
     $processors = self::getPaymentProcessors($capabilities, array($paymentProcessorID));
-    $processor = $processors[$paymentProcessorID];
-    $fields = array(
-      'id',
-      'name',
-      'payment_processor_type_id',
-      'user_name',
-      'password',
-      'signature',
-      'url_site',
-      'url_api',
-      'url_recur',
-      'url_button',
-      'subject',
-      'class_name',
-      'is_recur',
-      'billing_mode',
-      'is_test',
-      'payment_type',
-      'is_default',
-    );
-    // Just to prevent e-Notices elsewhere we set all fields.
-    foreach ($fields as $name) {
-      if (!isset($processor)) {
-        $processor[$name] = NULL;
-      }
-    }
-    $processor['payment_processor_type'] = CRM_Core_PseudoConstant::paymentProcessorType(FALSE,
-      $processor['payment_processor_type_id'], 'name');
     return $processors[$paymentProcessorID];
   }
 
@@ -326,7 +298,25 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
 
     $processors = civicrm_api3('payment_processor', 'get', $retrievalParameters);
     foreach ($processors['values'] as $processor) {
-      $fieldsToProvide = array('user_name', 'password', 'signature', 'subject', 'is_recur');
+      $fieldsToProvide = array(
+        'id',
+        'name',
+        'payment_processor_type_id',
+        'user_name',
+        'password',
+        'signature',
+        'url_site',
+        'url_api',
+        'url_recur',
+        'url_button',
+        'subject',
+        'class_name',
+        'is_recur',
+        'billing_mode',
+        'is_test',
+        'payment_type',
+        'is_default',
+      );
       foreach ($fieldsToProvide as $field) {
         // Prevent e-notices in processor classes when not configured.
         if (!isset($processor[$field])) {
@@ -548,7 +538,8 @@ INNER JOIN civicrm_contribution       con ON ( mp.contribution_id = con.id )
         // The function looks to load the payment processor ID from the contribution page, which
         // can support multiple processors.
       }
-      $paymentProcessor['payment_processor_type'] = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, $paymentProcessor['payment_processor_type_id'], 'name');
+
+      $paymentProcessor['payment_processor_type'] = CRM_Core_PseudoConstant::getName('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', $paymentProcessor['payment_processor_type_id']);
       $result = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor);
     }
     return $result;
index 23d13e0ba7f3f25c0becafc85dca0435a2467095..2abd563bc2f69d9af1f81534673a4031054ae14e 100644 (file)
@@ -179,11 +179,10 @@ class CRM_Utils_VersionCheck {
     $dao->find();
     $ppTypes = array();
 
-    // Get title and id for all processor types
-    $ppTypeNames = CRM_Core_PseudoConstant::paymentProcessorType();
-
+    // Get title for all processor types
+    // FIXME: This should probably be getName, but it has always returned translated label so we stick with that for now as it would affect stats
     while ($dao->fetch()) {
-      $ppTypes[] = $ppTypeNames[$dao->payment_processor_type_id];
+      $ppTypes[] = CRM_Core_PseudoConstant::getLabel('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', $dao->payment_processor_type_id);
     }
     // add the .-separated list of the processor types
     $this->stats['PPTypes'] = implode(',', array_unique($ppTypes));