From 90102a325bfd3a8436a74ac426a2f06f979fa04d Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 19 Jul 2015 15:57:56 +1200 Subject: [PATCH] CRM-16850 set membership-based recurring params before passing to payment express so it is approved as a recurring, where required Conflicts: CRM/Contribute/Form/Contribution/Main.php CRM/Contribute/Form/ContributionBase.php --- CRM/Contribute/Form/Contribution/Confirm.php | 22 +----------- CRM/Contribute/Form/Contribution/Main.php | 11 ++++-- CRM/Contribute/Form/ContributionBase.php | 36 +++++++++++++++++++- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 76ee59cd78..6c9a56044f 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -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); diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 5317b1df98..fb50237948 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -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); } } diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index e7a63d581d..7b960b2b0a 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -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' + ); + } + } + } + } -- 2.25.1