Enotice fix on payment processor browse
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 18 Aug 2022 22:27:47 +0000 (10:27 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 18 Aug 2022 22:34:24 +0000 (10:34 +1200)
CRM/Admin/Page/PaymentProcessor.php
templates/CRM/Admin/Page/PaymentProcessor.tpl

index 1fb115f8e81481eae5ef91e9edde405bcf61fd62..c0758c53375ea7af788367cdfe44dbf5c6818d3b 100644 (file)
@@ -15,6 +15,8 @@
  * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 
+use Civi\Api4\PaymentProcessor;
+
 /**
  * Page for displaying list of payment processors.
  */
@@ -105,53 +107,43 @@ class CRM_Admin_Page_PaymentProcessor extends CRM_Core_Page_Basic {
    * Browse all payment processors.
    *
    * @param null $action
+   *
+   * @throws \API_Exception
    */
-  public function browse($action = NULL) {
-    // get all custom groups sorted by weight
-    $paymentProcessor = [];
-    $dao = new CRM_Financial_DAO_PaymentProcessor();
-    $dao->is_test = 0;
-    $dao->domain_id = CRM_Core_Config::domainID();
-    $dao->orderBy('name');
-    $dao->find();
-
-    while ($dao->fetch()) {
-      $paymentProcessor[$dao->id] = [];
-      CRM_Core_DAO::storeValues($dao, $paymentProcessor[$dao->id]);
-      $paymentProcessor[$dao->id]['payment_processor_type'] = CRM_Core_PseudoConstant::getLabel(
-        'CRM_Financial_DAO_PaymentProcessor', 'payment_processor_type_id', $dao->payment_processor_type_id
-      );
+  public function browse($action = NULL): void {
+    $paymentProcessors = PaymentProcessor::get(FALSE)
+      ->addWhere('is_test', '=', 0)
+      ->addWhere('domain_id', '=', CRM_Core_Config::domainID())
+      ->setSelect(['id', 'name', 'description', 'title', 'is_active', 'is_default', 'payment_processor_type_id:label'])
+      ->addOrderBy('name')->execute()->indexBy('id');
+
+    foreach ($paymentProcessors as $paymentProcessorID => $paymentProcessor) {
+      // Annoyingly Smarty can't handle the colon syntax (or a .)
+      $paymentProcessors[$paymentProcessorID]['payment_processor_type'] = $paymentProcessor['payment_processor_type_id:label'];
 
       // form all action links
       $action = array_sum(array_keys($this->links()));
+      $action -= $paymentProcessor['is_active'] ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
 
-      // update enable/disable links.
-      if ($dao->is_active) {
-        $action -= CRM_Core_Action::ENABLE;
-      }
-      else {
-        $action -= CRM_Core_Action::DISABLE;
-      }
-
-      $paymentProcessor[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
-        array('id' => $dao->id),
+      $paymentProcessors[$paymentProcessorID]['action'] = CRM_Core_Action::formLink($this->links(), $action,
+        ['id' => $paymentProcessorID],
         ts('more'),
         FALSE,
         'paymentProcessor.manage.action',
         'PaymentProcessor',
-        $dao->id
+        $paymentProcessorID
       );
-      $paymentProcessor[$dao->id]['financialAccount'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($dao->id, NULL, 'civicrm_payment_processor', 'financial_account_id.name');
+      $paymentProcessors[$paymentProcessorID]['financialAccount'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($paymentProcessorID, NULL, 'civicrm_payment_processor', 'financial_account_id.name');
 
       try {
-        $paymentProcessor[$dao->id]['test_id'] = CRM_Financial_BAO_PaymentProcessor::getTestProcessorId($dao->id);
+        $paymentProcessors[$paymentProcessorID]['test_id'] = CRM_Financial_BAO_PaymentProcessor::getTestProcessorId($paymentProcessorID);
       }
       catch (CiviCRM_API3_Exception $e) {
-        CRM_Core_Session::setStatus(ts('No test processor entry exists for %1. Not having a test entry for each processor could cause problems', [$dao->name]));
+        CRM_Core_Session::setStatus(ts('No test processor entry exists for %1. Not having a test entry for each processor could cause problems', [$paymentProcessor['name']]));
       }
     }
 
-    $this->assign('rows', $paymentProcessor);
+    $this->assign('rows', $paymentProcessors);
   }
 
   /**
index 92dffc63a2a724f150886fb3b0f51454acaeea60..94e84730f1d1bd634e52a027dcd976b7c652c4ca 100644 (file)
@@ -34,7 +34,7 @@
             <th></th>
         </tr>
         {foreach from=$rows item=row}
-        <tr id="payment_processor-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"}{if !empty($row.class)} {$row.class}{/if}{if NOT $row.is_active} disabled{/if}">
+        <tr id="payment_processor-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {if NOT $row.is_active} disabled{/if}">
             <td class="crmf-id center">{$row.id}</td>
             <td class="crmf-test_id center">{$row.test_id}</td>
             <td class="crmf-name">{$row.name}</td>