CRM-16850 set membership-based recurring params before passing to payment express...
authorEileen McNaughton <eileen@fuzion.co.nz>
Sun, 19 Jul 2015 03:57:56 +0000 (15:57 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Tue, 21 Jul 2015 06:32:45 +0000 (18:32 +1200)
Conflicts:
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionBase.php

CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionBase.php

index 76ee59cd7869c1dad4c2692341a40afa1d7f2f4a..6c9a56044f45120d3e38568f6aac08b82feefd0b 100644 (file)
@@ -450,27 +450,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
         }
       }
     }
-
-    // if auto renew checkbox is set, initiate a open-ended recurring membership
-    if ((!empty($this->_params['selectMembership']) || !empty($this->_params['priceSetId'])) && !empty($this->_paymentProcessor['is_recur']) &&
-      CRM_Utils_Array::value('auto_renew', $this->_params) && empty($this->_params['is_recur']) && empty($this->_params['frequency_interval'])
-    ) {
-
-      $this->_params['is_recur'] = $this->_values['is_recur'] = 1;
-      // check if price set is not quick config
-      if (!empty($this->_params['priceSetId']) && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config')) {
-        list($this->_params['frequency_interval'], $this->_params['frequency_unit']) = CRM_Price_BAO_PriceSet::getRecurDetails($this->_params['priceSetId']);
-      }
-      else {
-        // FIXME: set interval and unit based on selected membership type
-        $this->_params['frequency_interval'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
-          $this->_params['selectMembership'], 'duration_interval'
-        );
-        $this->_params['frequency_unit'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
-          $this->_params['selectMembership'], 'duration_unit'
-        );
-      }
-    }
+    $this->setRecurringMembershipParams();
 
     if ($this->_pcpId) {
       $params = $this->processPcp($this, $this->_params);
index 5317b1df98c86981c4df1a353d8a0e883992610c..fb50237948abd4bd4238c5929b69b4f8a7a198bc 100644 (file)
@@ -1302,11 +1302,18 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       ((float ) $params['amount'] > 0.0 || $memFee > 0.0)
     ) {
       $this->setContributeMode();
-
+      // Really this setting of $this->_params & params within it should be done earlier on in the function
+      // probably the values determined here should be reused in confirm postProcess as there is no opportunity to alter anything
+      // on the confirm page. However as we are dealing with a stable release we go as close to where it is used
+      // as possible.
+      // In general the form has a lack of clarity of the logic of why things are set on the form in some cases &
+      // the logic around when $this->_params is used compared to other params arrays.
+      $this->_params = array_merge($params, $this->_params);
+      $this->setRecurringMembershipParams();
       if ($this->_paymentProcessor &&
         $this->_paymentProcessor['object']->supports('preApproval')
       ) {
-        $this->handlePreApproval($params);
+        $this->handlePreApproval($this->_params);
       }
     }
 
index e7a63d581d33b3730b8ee203d6e61745821bfd25..7b960b2b0aafd3bf8949c24fa64475a2d5054846 100644 (file)
@@ -100,7 +100,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    *
    * @var array
    */
-  public $_params;
+  public $_params = array();
 
   /**
    * The fields involved in this contribution page
@@ -1036,4 +1036,38 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
     return $separateMembershipPayment;
   }
 
+  /**
+   * Determine if recurring parameters need to be added to the form parameters.
+   *  - is_recur
+   *  - frequency_interval
+   *  - frequency_unit
+   *
+   * For membership this is based on the membership type.
+   *
+   * This needs to be done before processing the pre-approval redirect where relevant on the main page or before any payment processing.
+   *
+   * Arguably the form should start to build $this->_params in the pre-process main page & use that array consistently throughout.
+   */
+  protected function setRecurringMembershipParams() {
+    if ((!empty($this->_params['selectMembership']) || !empty($this->_params['priceSetId'])) && !empty($this->_paymentProcessor['is_recur']) &&
+      CRM_Utils_Array::value('auto_renew', $this->_params) && empty($this->_params['is_recur']) && empty($this->_params['frequency_interval'])
+    ) {
+
+      $this->_params['is_recur'] = $this->_values['is_recur'] = 1;
+      // check if price set is not quick config
+      if (!empty($this->_params['priceSetId']) && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config')) {
+        list($this->_params['frequency_interval'], $this->_params['frequency_unit']) = CRM_Price_BAO_PriceSet::getRecurDetails($this->_params['priceSetId']);
+      }
+      else {
+        // FIXME: set interval and unit based on selected membership type
+        $this->_params['frequency_interval'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
+          $this->_params['selectMembership'], 'duration_interval'
+        );
+        $this->_params['frequency_unit'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
+          $this->_params['selectMembership'], 'duration_unit'
+        );
+      }
+    }
+  }
+
 }