Fix issues with retrieving supportsTestMode/supportsLiveMode for payment processors
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Thu, 19 Sep 2019 14:48:17 +0000 (15:48 +0100)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 17 Jan 2020 14:41:53 +0000 (14:41 +0000)
CRM/Contribute/Form/AbstractEditPayment.php
CRM/Core/Form.php
CRM/Core/Payment.php
CRM/Core/Payment/Dummy.php
CRM/Financial/BAO/PaymentProcessor.php

index 04be631bb13810d842ab22bbbae5b12b9e5b7a15..7469609f7fbcaf2fc35f40f3e8a639005888a976 100644 (file)
@@ -372,19 +372,12 @@ WHERE  contribution_id = {$id}
     }
     $this->_processors = [];
     foreach ($this->_paymentProcessors as $id => $processor) {
-      // @todo review this. The inclusion of this IF was to address test processors being incorrectly loaded.
-      // However the function $this->getValidProcessors() is expected to only return the processors relevant
-      // to the mode (using the actual id - ie. the id of the test processor for the test processor).
-      // for some reason there was a need to filter here per commit history - but this indicates a problem
-      // somewhere else.
-      if ($processor['is_test'] == ($this->_mode == 'test')) {
-        $this->_processors[$id] = $processor['name'];
-        if (!empty($processor['description'])) {
-          $this->_processors[$id] .= ' : ' . $processor['description'];
-        }
-        if ($processor['is_recur']) {
-          $this->_recurPaymentProcessors[$id] = $this->_processors[$id];
-        }
+      $this->_processors[$id] = $processor['name'];
+      if (!empty($processor['description'])) {
+        $this->_processors[$id] .= ' : ' . $processor['description'];
+      }
+      if ($processor['is_recur']) {
+        $this->_recurPaymentProcessors[$id] = $this->_processors[$id];
       }
     }
     // CRM-21002: pass the default payment processor ID whose credit card type icons should be populated first
index 5eb5167b312547b67ee642697452616bf82392e9..782f72ca44f03096bb47e9381f02e232a94bd9c5 100644 (file)
@@ -776,10 +776,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * @throws \CRM_Core_Exception
    */
   protected function assignPaymentProcessor($isPayLaterEnabled) {
-    $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(
-      [ucfirst($this->_mode) . 'Mode'],
-      $this->_paymentProcessorIDs
-    );
+    $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors([ucfirst($this->_mode) . 'Mode'], $this->_paymentProcessorIDs);
     if ($isPayLaterEnabled) {
       $this->_paymentProcessors[0] = CRM_Financial_BAO_PaymentProcessor::getPayment(0);
     }
index 1af72a2301f03e52b8dbd79952d03d886dea4fe9..18d89d958920eb4b93b6f78707671c6228ae2520 100644 (file)
@@ -354,7 +354,7 @@ abstract class CRM_Core_Payment {
    * @return bool
    */
   protected function supportsLiveMode() {
-    return TRUE;
+    return empty($this->_paymentProcessor['is_test']) ? TRUE : FALSE;
   }
 
   /**
@@ -363,7 +363,7 @@ abstract class CRM_Core_Payment {
    * @return bool
    */
   protected function supportsTestMode() {
-    return TRUE;
+    return empty($this->_paymentProcessor['is_test']) ? FALSE : TRUE;
   }
 
   /**
index d7c39838ee89103cc69cb64e701f3d0378b2c339..e0a079a8f1b8b48218c9811bdc6e9354531e7d66 100644 (file)
@@ -132,17 +132,6 @@ class CRM_Core_Payment_Dummy extends CRM_Core_Payment {
     return $params;
   }
 
-  /**
-   * Are back office payments supported.
-   *
-   * E.g paypal standard won't permit you to enter a credit card associated with someone else's login.
-   *
-   * @return bool
-   */
-  protected function supportsLiveMode() {
-    return TRUE;
-  }
-
   /**
    * Does this payment processor support refund?
    *
index 65dae3da36241ca4ec63b36b561654afa8705904..b2508ec8653427b978c45ec31b27c1ec2f887b8f 100644 (file)
@@ -379,8 +379,8 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    *   available processors
    */
   public static function getPaymentProcessors($capabilities = [], $ids = FALSE) {
-    $testProcessors = in_array('TestMode', $capabilities) ? self::getAllPaymentProcessors('test') : [];
     if (is_array($ids)) {
+      $testProcessors = in_array('TestMode', $capabilities) ? self::getAllPaymentProcessors('test') : [];
       $processors = self::getAllPaymentProcessors('all', FALSE, FALSE);
       if (in_array('TestMode', $capabilities)) {
         $possibleLiveIDs = array_diff($ids, array_keys($testProcessors));