CRM-16189, added code to validate financial type for contribution
[civicrm-core.git] / CRM / Contribute / Form / CancelSubscription.php
index 6486bd6aa6043905c5dc6c872e1d68ef31506392..817fc58af87924b8e20431c4491c7c5b39dacd87 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
  */
 
 /**
@@ -71,12 +71,13 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Core_Form {
     }
 
     if ($this->_mid) {
-      if (CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_mid)) {
-        CRM_Core_Error::fatal(ts('The auto renewal option for this membership looks to have been cancelled already.'));
-      }
       $this->_mode = 'auto_renew';
-      $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_mid, 'membership', 'obj');
-      $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_mid, 'membership');
+      // 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');
@@ -130,7 +131,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Core_Form {
    */
   public function buildQuickForm() {
     // Determine if we can cancel recurring contribution via API with this processor
-    $cancelSupported = $this->_paymentProcessorObj->isSupported('cancelSubscription');
+    $cancelSupported = $this->_paymentProcessorObj->supports('CancelRecurring');
     if ($cancelSupported) {
       $searchRange = array();
       $searchRange[] = $this->createElement('radio', NULL, NULL, ts('Yes'), '1');
@@ -198,7 +199,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Core_Form {
 
     if ($this->_selfService) {
       // for self service force sending-request & notify
-      if ($this->_paymentProcessorObj->isSupported('cancelSubscription')) {
+      if ($this->_paymentProcessorObj->supports('cancelRecurring')) {
         $params['send_cancel_request'] = 1;
       }