X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FForm%2FCancelSubscription.php;h=f8be875bd1297b84c85ec0907aebea40faa440ff;hb=ec57bf8741042cc600a7d0daa38b514700fbce88;hp=69c682756a1943a420b0adc3d8d11635810fbc79;hpb=7695e8592d7b36471bc0880dc259c31e1e5fbf26;p=civicrm-core.git diff --git a/CRM/Contribute/Form/CancelSubscription.php b/CRM/Contribute/Form/CancelSubscription.php index 69c682756a..f8be875bd1 100644 --- a/CRM/Contribute/Form/CancelSubscription.php +++ b/CRM/Contribute/Form/CancelSubscription.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 5 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2019 | + | Copyright CiviCRM LLC (c) 2004-2020 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -28,7 +28,7 @@ /** * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2019 + * @copyright CiviCRM LLC (c) 2004-2020 */ /** @@ -40,7 +40,18 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib protected $_mode = NULL; - protected $_selfService = FALSE; + /** + * Should custom data be suppressed on this form. + * + * We override to suppress custom data because historically it has not been + * shown on this form & we don't want to expose it as a by-product of + * other change without establishing that it would be good on this form. + * + * @return bool + */ + protected function isSuppressCustomData() { + return TRUE; + } /** * Set variables up before form is built. @@ -65,10 +76,6 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib $this->_mode = 'auto_renew'; // CRM-18468: crid is more accurate than mid for getting // subscriptionDetails, so don't get them again. - if (!$this->_crid) { - $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_mid, 'membership', 'obj'); - $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_mid, 'membership'); - } $membershipTypes = CRM_Member_PseudoConstant::membershipType(); $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_mid, 'membership_type_id'); @@ -91,16 +98,8 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib (!$this->_crid && !$this->_coid && !$this->_mid) || (!$this->_subscriptionDetails) ) { - CRM_Core_Error::fatal('Required information missing.'); - } - - if (!CRM_Core_Permission::check('edit contributions')) { - if ($this->_subscriptionDetails->contact_id != $this->getContactID()) { - CRM_Core_Error::statusBounce(ts('You do not have permission to cancel this recurring contribution.')); - } - $this->_selfService = TRUE; + CRM_Core_Error::statusBounce('Required information missing.'); } - $this->assign('self_service', $this->_selfService); // handle context redirection CRM_Contribute_BAO_ContributionRecur::setSubscriptionContext(); @@ -108,16 +107,40 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib CRM_Utils_System::setTitle($this->_mid ? ts('Cancel Auto-renewal') : ts('Cancel Recurring Contribution')); $this->assign('mode', $this->_mode); + if ($this->isSelfService()) { + unset($this->entityFields['send_cancel_request'], $this->entityFields['is_notify']); + } + if ($this->_subscriptionDetails->contact_id) { list($this->_donorDisplayName, $this->_donorEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_subscriptionDetails->contact_id); } } + /** + * Set entity fields for this cancellation. + */ + public function setEntityFields() { + $this->entityFields = [ + 'cancel_reason' => ['name' => 'cancel_reason'], + ]; + $this->entityFields['send_cancel_request'] = [ + 'title' => ts('Send cancellation request?'), + 'name' => 'send_cancel_request', + 'not-auto-addable' => TRUE, + ]; + $this->entityFields['is_notify'] = [ + 'title' => ts('Notify Contributor?'), + 'name' => 'is_notify', + 'not-auto-addable' => TRUE, + ]; + } + /** * Build the form object. */ public function buildQuickForm() { + $this->buildQuickEntityForm(); // Determine if we can cancel recurring contribution via API with this processor $cancelSupported = $this->_paymentProcessorObj->supports('CancelRecurring'); if ($cancelSupported) { @@ -145,7 +168,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib } $type = 'next'; - if ($this->_selfService) { + if ($this->isSelfService()) { $type = 'submit'; } @@ -184,7 +207,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib $cancelSubscription = TRUE; $params = $this->controller->exportValues($this->_name); - if ($this->_selfService) { + if ($this->isSelfService()) { // for self service force sending-request & notify if ($this->_paymentProcessorObj->supports('cancelRecurring')) { $params['send_cancel_request'] = 1; @@ -209,6 +232,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib 'id' => $this->_subscriptionDetails->recur_id, 'membership_id' => $this->_mid, 'processor_message' => $message, + 'cancel_reason' => $params['cancel_reason'], ]); $tplParams = [];