Always use cancelSubscription form for cancelling recurring contributions
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 14 Apr 2022 23:08:06 +0000 (11:08 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 14 Apr 2022 23:39:38 +0000 (11:39 +1200)
This is https://github.com/civicrm/civicrm-core/pull/18196 without the bit I was uncomfortable with

CRM/Contribute/Form/CancelSubscription.php
CRM/Contribute/Page/Tab.php
tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php

index 4bcf8408412d1e7dacbc2568a841ab3f041bfa39..529de295e0936dd21163b4ef23d92f202b92895b 100644 (file)
@@ -100,8 +100,16 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
     $this->setTitle($this->_mid ? ts('Cancel Auto-renewal') : ts('Cancel Recurring Contribution'));
     $this->assign('mode', $this->_mode);
 
+    if ($this->isSelfService() || !$this->_paymentProcessorObj->supports('cancelRecurring')) {
+      // If we are self service (contact is cancelling for themselves via a cancel link)
+      // or the processor does not support cancellation then remove the fields
+      // specifying whether to notify the processor.
+      unset($this->entityFields['send_cancel_request']);
+    }
     if ($this->isSelfService()) {
-      unset($this->entityFields['send_cancel_request'], $this->entityFields['is_notify']);
+      // Arguably the is_notify field should be removed in self-service mode.
+      // Historically this has been the case...
+      unset($this->entityFields['is_notify']);
     }
 
     if ($this->getSubscriptionDetails()->contact_id) {
index 56411d1bc0e0c2288f8a2e27cfa45b8b8fe8366f..f8ab5c536e1c52402169fde3b970876f5f65f7bb 100644 (file)
@@ -82,15 +82,10 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
     $links[CRM_Core_Action::DISABLE] = [
       'name' => ts('Cancel'),
       'title' => ts('Cancel'),
-      'ref' => 'crm-enable-disable',
+      'url' => 'civicrm/contribute/unsubscribe',
+      'qs' => 'reset=1&crid=%%crid%%&cid=%%cid%%&context=' . $context,
     ];
 
-    if ($paymentProcessorObj->supports('cancelRecurring')) {
-      unset($links[CRM_Core_Action::DISABLE]['extra'], $links[CRM_Core_Action::DISABLE]['ref']);
-      $links[CRM_Core_Action::DISABLE]['url'] = "civicrm/contribute/unsubscribe";
-      $links[CRM_Core_Action::DISABLE]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
-    }
-
     if ($paymentProcessorObj->supports('UpdateSubscriptionBillingInfo')) {
       $links[CRM_Core_Action::RENEW] = [
         'name' => ts('Change Billing Details'),
index fab2a8e1fb257f2c7a19ff0e61e1679db857f34a..9f40b4ad9bcc95dd9d59c0466e2e9f283773ae6e 100644 (file)
@@ -56,9 +56,12 @@ class CRM_Contribute_Form_CancelSubscriptionTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test if the full fledged form is displayed on cancelling the Recurring Contribution with a payment processor which does not support cancelling a Recurring Contribution
+   * Test if the full fledged form is displayed on cancelling the Recurring
+   * Contribution with a payment processor which does not support cancelling a
+   * Recurring Contribution
    *
-   * @throws \CRM_Core_Exception|\API_Exception
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function testCancelSubscriptionForm(): void {
     $this->addContribution();
@@ -74,10 +77,8 @@ class CRM_Contribute_Form_CancelSubscriptionTest extends CiviUnitTestCase {
     ]);
 
     $actions = CRM_Contribute_Page_Tab::recurLinks($this->getContributionRecurID());
-    // Using "crm-enable-disable"
-    $this->assertEquals($actions[CRM_Core_Action::DISABLE]['ref'], 'crm-enable-disable');
     // Using "Cancel Recurring" form
-    // $this->assertEquals($actions[CRM_Core_Action::DISABLE]['url'], 'civicrm/contribute/unsubscribe');
+    $this->assertEquals('civicrm/contribute/unsubscribe', $actions[CRM_Core_Action::DISABLE]['url']);
   }
 
 }