return $links;
}
+ /**
+ * Get the recur links to return for self service.
+ *
+ * These are the links to present to a logged in user wishing
+ * to service their own
+ *
+ * @param int $recurID
+ *
+ * @return array|array[]
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public static function selfServiceRecurLinks(int $recurID): array {
+ $links = [];
+ $paymentProcessorObj = Civi\Payment\System::singleton()->getById(CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorID($recurID));
+ if ($paymentProcessorObj->supports('cancelRecurring')
+ && $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'cancel')
+ ) {
+ $url = $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'cancel');
+ $links[CRM_Core_Action::DISABLE] = [
+ 'url' => $url,
+ 'name' => ts('Cancel'),
+ 'title' => ts('Cancel'),
+ // Only display on-site links in a popup.
+ 'class' => (stripos($url, 'http') !== FALSE) ? 'no-popup' : '',
+ ];
+ }
+
+ if ($paymentProcessorObj->supports('UpdateSubscriptionBillingInfo')
+ && $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'billing')
+ ) {
+ $url = $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'billing');
+ $links[CRM_Core_Action::RENEW] = [
+ 'name' => ts('Change Billing Details'),
+ 'title' => ts('Change Billing Details'),
+ 'url' => $url,
+ // Only display on-site links in a popup.
+ 'class' => (stripos($url, 'http') !== FALSE) ? 'no-popup' : '',
+ ];
+ }
+
+ if (($paymentProcessorObj->supports('ChangeSubscriptionAmount')
+ || $paymentProcessorObj->supports('EditRecurringContribution'))
+ && $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'update')
+ ) {
+ $url = $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'update');
+ $links[CRM_Core_Action::UPDATE] = [
+ 'name' => ts('Edit'),
+ 'title' => ts('Edit Recurring Payment'),
+ 'url' => $url,
+ // Only display on-site links in a popup.
+ 'class' => (stripos($url, 'http') !== FALSE) ? 'no-popup' : '',
+ ];
+ }
+ return $links;
+ }
+
+ /**
+ * Get recurring links appropriate to viewing a user dashboard.
+ *
+ * A contact should be able to see links appropriate to them (e.g
+ * payment processor cancel page) if viewing their own dashboard and
+ * links appropriate to the contact they are viewing, if they have
+ * permission, if viewing another user.
+ *
+ * @param int $recurID
+ * @param int $contactID
+ *
+ * @return array|array[]
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public static function dashboardRecurLinks(int $recurID, int $contactID): array {
+ $links = [];
+ if ($contactID && $contactID === CRM_Core_Session::getLoggedInContactID()) {
+ $links = self::selfServiceRecurLinks($recurID);
+ }
+ $links += self::recurLinks($recurID, 'dashboard');
+ return $links;
+ }
+
/**
* called when action is browse.
*
$values['recur_status'] = $recurStatus[$values['contribution_status_id']];
$recurRow[$values['id']] = $values;
- $action = array_sum(array_keys(CRM_Contribute_Page_Tab::recurLinks((int) $recur->id, 'dashboard')));
+ $action = array_sum(array_keys(CRM_Contribute_Page_Tab::dashboardRecurLinks((int) $recur->id, (int) $recur->contact_id)));
$details = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($recur->id, 'recur');
$hideUpdate = $details->membership_id & $details->auto_renew;
$action -= CRM_Core_Action::UPDATE;
}
- $recurRow[$values['id']]['action'] = CRM_Core_Action::formLink(CRM_Contribute_Page_Tab::recurLinks((int) $recur->id, 'dashboard'),
+ $recurRow[$values['id']]['action'] = CRM_Core_Action::formLink(CRM_Contribute_Page_Tab::dashboardRecurLinks((int) $recur->id, (int) $this->_contactId),
$action, [
'cid' => $this->_contactId,
'crid' => $values['id'],
$page = new CRM_Contribute_Page_UserDashboard();
$page->run();
- $expected = '<span><a href="/index.php?q=civicrm/contact/view/contributionrecur&reset=1&id=1&cid=3&context=contribution" class="action-item crm-hover-button" title=\'View Recurring Payment\' >View</a><a href="/index.php?q=civicrm/contribute/updaterecur&reset=1&action=update&crid=1&cid=3&context=contribution" class="action-item crm-hover-button" title=\'Edit Recurring Payment\' >Edit</a></span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="/index.php?q=civicrm/contribute/unsubscribe&reset=1&crid=1&cid=3&context=contribution" class="action-item crm-hover-button" title=\'Cancel\' >Cancel</a></li><li><a href="/index.php?q=civicrm/contribute/updatebilling&reset=1&crid=1&cid=3&context=contribution" class="action-item crm-hover-button" title=\'Change Billing Details\' >Change Billing Details</a></li></ul></span>';
+ $expected = '<span><a href="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=sunil._1183377782_biz_api1.webaccess.co.in" class="action-item crm-hover-button no-popup" title=\'Cancel\' >Cancel</a>'
+ . '<a href="/index.php?q=civicrm/contact/view/contributionrecur&reset=1&id=1&cid=3&context=dashboard" class="action-item crm-hover-button" title=\'View Recurring Payment\' >View</a>'
+ . '</span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="/index.php?q=civicrm/contribute/updaterecur&reset=1&action=update&crid=1&cid=3&context=dashboard" class="action-item crm-hover-button" title=\'Edit Recurring Payment\' >Edit</a></li><li><a href="/index.php?q=civicrm/contribute/updatebilling&reset=1&crid=1&cid=3&context=dashboard" class="action-item crm-hover-button" title=\'Change Billing Details\' >Change Billing Details</a></li></ul></span>';
$this->assertEquals(
$expected,
- $this->getActionHtml()
+ $this->getDashboardActionHtml()
);
}
->get_template_vars()['activeRecurRows'][1]['action'];
}
+ /**
+ * Get the html assigned as actions.
+ *
+ * @return string
+ */
+ protected function getDashboardActionHtml(): string {
+ return CRM_Core_Smarty::singleton()
+ ->get_template_vars()['recurRows'][1]['action'];
+ }
+
}