Tidy up getContributionPaymentLinks
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 10 Feb 2022 01:40:16 +0000 (14:40 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 10 Feb 2022 02:04:43 +0000 (15:04 +1300)
- removes an unused variable.
- fixes to not show 'record Refund' for pending contributions (is displayed
on the expand payments section of a contribution

CRM/Contribute/BAO/Contribution.php

index 126527ebf9d126c44fb6725056546d337ebf4031..5434ee955f9b794561ed1990979c8e20d384d7db 100644 (file)
@@ -3634,7 +3634,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
       $info['transaction'] = self::getContributionTransactionInformation($contributionId, $contribution['financial_type_id']);
     }
 
-    $info['payment_links'] = self::getContributionPaymentLinks($id, $paymentBalance, $info['contribution_status']);
+    $info['payment_links'] = self::getContributionPaymentLinks($id, $info['contribution_status']);
     return $info;
   }
 
@@ -4275,7 +4275,6 @@ LIMIT 1;";
    * then a refund link.
    *
    * @param int $id
-   * @param float $balance
    * @param string $contributionStatus
    *
    * @return array
@@ -4283,7 +4282,7 @@ LIMIT 1;";
    *     -url
    *     -title
    */
-  protected static function getContributionPaymentLinks($id, $balance, $contributionStatus) {
+  protected static function getContributionPaymentLinks(int $id, string $contributionStatus): array {
     if ($contributionStatus === 'Failed' || !CRM_Core_Permission::check('edit contributions')) {
       // In general the balance is the best way to determine if a payment can be added or not,
       // but not for Failed contributions, where we don't accept additional payments at the moment.
@@ -4314,15 +4313,17 @@ LIMIT 1;";
         'title' => ts('Submit Credit Card payment'),
       ];
     }
-    $actionLinks[] = [
-      'url' => CRM_Utils_System::url('civicrm/payment', [
-        'action' => 'add',
-        'reset' => 1,
-        'id' => $id,
-        'is_refund' => 1,
-      ]),
-      'title' => ts('Record Refund'),
-    ];
+    if ($contributionStatus !== 'Pending') {
+      $actionLinks[] = [
+        'url' => CRM_Utils_System::url('civicrm/payment', [
+          'action' => 'add',
+          'reset' => 1,
+          'id' => $id,
+          'is_refund' => 1,
+        ]),
+        'title' => ts('Record Refund'),
+      ];
+    }
     return $actionLinks;
   }