From ca574dc9964e337d02ce755dc188f07472141d17 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 15 Apr 2022 11:08:06 +1200 Subject: [PATCH] Always use cancelSubscription form for cancelling recurring contributions This is https://github.com/civicrm/civicrm-core/pull/18196 without the bit I was uncomfortable with --- CRM/Contribute/Form/CancelSubscription.php | 10 +++++++++- CRM/Contribute/Page/Tab.php | 9 ++------- .../CRM/Contribute/Form/CancelSubscriptionTest.php | 11 ++++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CRM/Contribute/Form/CancelSubscription.php b/CRM/Contribute/Form/CancelSubscription.php index 4bcf840841..529de295e0 100644 --- a/CRM/Contribute/Form/CancelSubscription.php +++ b/CRM/Contribute/Form/CancelSubscription.php @@ -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) { diff --git a/CRM/Contribute/Page/Tab.php b/CRM/Contribute/Page/Tab.php index 56411d1bc0..f8ab5c536e 100644 --- a/CRM/Contribute/Page/Tab.php +++ b/CRM/Contribute/Page/Tab.php @@ -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'), diff --git a/tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php b/tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php index fab2a8e1fb..9f40b4ad9b 100644 --- a/tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php @@ -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']); } } -- 2.25.1