From c7d9325ab221b6f3b6ee19e46ce1bb7f7f858e65 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 12 Apr 2019 08:09:43 +1000 Subject: [PATCH] Switch to using ContributionRecur.cancel api from CancelSubscription form The function cancelRecurContribution is only called from the form ant from the api. This makes it so the form uses the api, which we have started to add unit testing to. Follow ing this we can use the api for transaction handling and move more of the form logic into the api, making it available to others & allowing us to better move to a new form layer later without as much logic in the forms --- CRM/Contribute/Form/CancelSubscription.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CRM/Contribute/Form/CancelSubscription.php b/CRM/Contribute/Form/CancelSubscription.php index 2289628909..67573c108a 100644 --- a/CRM/Contribute/Form/CancelSubscription.php +++ b/CRM/Contribute/Form/CancelSubscription.php @@ -207,10 +207,13 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib CRM_Core_Error::displaySessionError($cancelSubscription); } elseif ($cancelSubscription) { - $cancelStatus = CRM_Contribute_BAO_ContributionRecur::cancelRecurContribution( - ['id' => $this->_subscriptionDetails->recur_id, 'membership_id' => $this->_mid, 'processor_message' => $message]); + try { + civicrm_api3('ContributionRecur', 'cancel', [ + 'id' => $this->_subscriptionDetails->recur_id, + 'membership_id' => $this->_mid, + 'processor_message' => $message, + ]); - if ($cancelStatus) { $tplParams = []; if ($this->_mid) { $inputParams = ['id' => $this->_mid]; @@ -276,7 +279,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); } } - else { + catch (CiviCRM_API3_Exception $e) { $msgType = 'error'; $msgTitle = ts('Error'); if ($params['send_cancel_request'] == 1) { -- 2.25.1