+ /**
+ * Get payment links as they relate to a contribution.
+ *
+ * If a payment can be made then include a payment link & if a refund is appropriate
+ * then a refund link.
+ *
+ * @param int $id
+ * @param float $balance
+ * @param string $contributionStatus
+ *
+ * @return array $actionLinks Links array containing:
+ * -url
+ * -title
+ */
+ protected static function getContributionPaymentLinks($id, $balance, $contributionStatus) {
+ 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.
+ // (in some cases the contribution is 'Pending' and only the payment is failed. In those we
+ // do accept more payments agains them.
+ return array();
+ }
+ $actionLinks = array();
+ if ((int) $balance > 0) {
+ if (CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()) {
+ $actionLinks[] = array(
+ 'url' => CRM_Utils_System::url('civicrm/payment', array(
+ 'action' => 'add',
+ 'reset' => 1,
+ 'id' => $id,
+ 'mode' => 'live',
+ )),
+ 'title' => ts('Submit Credit Card payment'),
+ );
+ }
+ $actionLinks[] = array(
+ 'url' => CRM_Utils_System::url('civicrm/payment', array(
+ 'action' => 'add',
+ 'reset' => 1,
+ 'id' => $id,
+ )),
+ 'title' => ts('Record Payment'),
+ );
+ }
+ elseif ((int) $balance < 0) {
+ $actionLinks[] = array(
+ 'url' => CRM_Utils_System::url('civicrm/payment', array(
+ 'action' => 'add',
+ 'reset' => 1,
+ 'id' => $id,
+ )),
+ 'title' => ts('Record Refund'),
+ );
+ }
+ return $actionLinks;
+ }
+