Switch to getter function for subscriptionDetails
authorMatthew Wire <mjw@mjwconsult.co.uk>
Tue, 10 Mar 2020 21:19:20 +0000 (21:19 +0000)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Tue, 10 Mar 2020 21:24:23 +0000 (21:24 +0000)
CRM/Contribute/Form/CancelSubscription.php

index b9af4f6b9d33a33ec37828321b447ce110e74767..f3720baa2309f35e5361e75588a980701fc371ee 100644 (file)
@@ -46,14 +46,14 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
   public function preProcess() {
     parent::preProcess();
     if ($this->_crid) {
-      $this->assign('frequency_unit', $this->_subscriptionDetails->frequency_unit);
-      $this->assign('frequency_interval', $this->_subscriptionDetails->frequency_interval);
-      $this->assign('amount', $this->_subscriptionDetails->amount);
-      $this->assign('installments', $this->_subscriptionDetails->installments);
+      $this->assign('frequency_unit', $this->getSubscriptionDetails()->frequency_unit);
+      $this->assign('frequency_interval', $this->getSubscriptionDetails()->frequency_interval);
+      $this->assign('amount', $this->getSubscriptionDetails()->amount);
+      $this->assign('installments', $this->getSubscriptionDetails()->installments);
 
       // Are we cancelling a recurring contribution that is linked to an auto-renew membership?
-      if ($this->_subscriptionDetails->membership_id) {
-        $this->_mid = $this->_subscriptionDetails->membership_id;
+      if ($this->getSubscriptionDetails()->membership_id) {
+        $this->_mid = $this->getSubscriptionDetails()->membership_id;
       }
     }
 
@@ -73,15 +73,15 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
       }
       $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'obj');
 
-      $this->assign('frequency_unit', $this->_subscriptionDetails->frequency_unit);
-      $this->assign('frequency_interval', $this->_subscriptionDetails->frequency_interval);
-      $this->assign('amount', $this->_subscriptionDetails->amount);
-      $this->assign('installments', $this->_subscriptionDetails->installments);
+      $this->assign('frequency_unit', $this->getSubscriptionDetails()->frequency_unit);
+      $this->assign('frequency_interval', $this->getSubscriptionDetails()->frequency_interval);
+      $this->assign('amount', $this->getSubscriptionDetails()->amount);
+      $this->assign('installments', $this->getSubscriptionDetails()->installments);
     }
 
     if (
       (!$this->_crid && !$this->_coid && !$this->_mid) ||
-      (!$this->_subscriptionDetails)
+      (!$this->getSubscriptionDetails())
     ) {
       CRM_Core_Error::statusBounce('Required information missing.');
     }
@@ -96,9 +96,9 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
       unset($this->entityFields['send_cancel_request'], $this->entityFields['is_notify']);
     }
 
-    if ($this->_subscriptionDetails->contact_id) {
+    if ($this->getSubscriptionDetails()->contact_id) {
       list($this->_donorDisplayName, $this->_donorEmail)
-        = CRM_Contact_BAO_Contact::getContactDetails($this->_subscriptionDetails->contact_id);
+        = CRM_Contact_BAO_Contact::getContactDetails($this->getSubscriptionDetails()->contact_id);
     }
   }
 
@@ -204,12 +204,9 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
     }
 
     if (CRM_Utils_Array::value('send_cancel_request', $params) == 1) {
-      // Note the 'subscriptionId' here is the value stored in
-      // civicrm_contribution_recur.processor_id
-      $cancelParams = ['subscriptionId' => $this->_subscriptionDetails->subscription_id];
       try {
         $propertyBag = new PropertyBag();
-        $propertyBag->setRecurProcessorID($this->_subscriptionDetails->subscription_id);
+        $propertyBag->setRecurProcessorID($this->getSubscriptionDetails()->subscription_id);
         $message = $this->_paymentProcessorObj->doCancelRecurring($propertyBag)['message'];
       }
       catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
@@ -220,7 +217,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
     if ($cancelSubscription) {
       try {
         civicrm_api3('ContributionRecur', 'cancel', [
-          'id' => $this->_subscriptionDetails->recur_id,
+          'id' => $this->getSubscriptionDetails()->recur_id,
           'membership_id' => $this->_mid,
           'processor_message' => $message,
           'cancel_reason' => $params['cancel_reason'],
@@ -240,15 +237,15 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
           $msgType = 'info';
         }
         else {
-          $tplParams['recur_frequency_interval'] = $this->_subscriptionDetails->frequency_interval;
-          $tplParams['recur_frequency_unit'] = $this->_subscriptionDetails->frequency_unit;
-          $tplParams['amount'] = $this->_subscriptionDetails->amount;
+          $tplParams['recur_frequency_interval'] = $this->getSubscriptionDetails()->frequency_interval;
+          $tplParams['recur_frequency_unit'] = $this->getSubscriptionDetails()->frequency_unit;
+          $tplParams['amount'] = $this->getSubscriptionDetails()->amount;
           $tplParams['contact'] = ['display_name' => $this->_donorDisplayName];
           $status = ts('The recurring contribution of %1, every %2 %3 has been cancelled.',
             [
-              1 => $this->_subscriptionDetails->amount,
-              2 => $this->_subscriptionDetails->frequency_interval,
-              3 => $this->_subscriptionDetails->frequency_unit,
+              1 => $this->getSubscriptionDetails()->amount,
+              2 => $this->getSubscriptionDetails()->frequency_interval,
+              3 => $this->getSubscriptionDetails()->frequency_unit,
             ]
           );
           $msgTitle = 'Contribution Cancelled';
@@ -256,18 +253,18 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
         }
 
         if (CRM_Utils_Array::value('is_notify', $params) == 1) {
-          if ($this->_subscriptionDetails->contribution_page_id) {
+          if ($this->getSubscriptionDetails()->contribution_page_id) {
             CRM_Core_DAO::commonRetrieveAll(
               'CRM_Contribute_DAO_ContributionPage',
               'id',
-              $this->_subscriptionDetails->contribution_page_id,
+              $this->getSubscriptionDetails()->contribution_page_id,
               $value,
               ['title', 'receipt_from_name', 'receipt_from_email']
             );
             $receiptFrom
-              = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$this->_subscriptionDetails->contribution_page_id]) .
+              = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$this->getSubscriptionDetails()->contribution_page_id]) .
               '" <' .
-              $value[$this->_subscriptionDetails->contribution_page_id]['receipt_from_email'] .
+              $value[$this->getSubscriptionDetails()->contribution_page_id]['receipt_from_email'] .
               '>';
           }
           else {
@@ -280,7 +277,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib
             = [
               'groupName' => $this->_mode == 'auto_renew' ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
               'valueName' => $this->_mode == 'auto_renew' ? 'membership_autorenew_cancelled' : 'contribution_recurring_cancelled',
-              'contactId' => $this->_subscriptionDetails->contact_id,
+              'contactId' => $this->getSubscriptionDetails()->contact_id,
               'tplParams' => $tplParams,
               //'isTest'    => $isTest, set this from _objects
               'PDFFilename' => 'receipt.pdf',