Skip to content
Snippets Groups Projects
Commit fd5c23d1 authored by Seamus Lee's avatar Seamus Lee
Browse files

[REF] Fix Automatic renewal membership from front end contribution forms

Properly fix regression and update unit tests to match what the form does
parent 99f0a8f6
No related branches found
No related tags found
No related merge requests found
......@@ -1151,10 +1151,13 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
return;
}
// Check if membership the selected membership is automatically opted into auto renew or give user the option.
// In the 2nd case we check that the user has in deed opted in (auto renew as at June 22 is the field name for the membership auto renew checkbox)
// Also check that the payment Processor used can support recurring contributions.
$membershipTypes = CRM_Price_BAO_PriceSet::getMembershipTypesFromPriceSet($this->_priceSetId);
if (in_array($selectedMembershipTypeID, $membershipTypes['autorenew_required'])
|| (in_array($selectedMembershipTypeID, $membershipTypes['autorenew_optional']) &&
!empty($this->_params['is_recur']))
!empty($this->_params['auto_renew']))
&& !empty($this->_paymentProcessor['is_recur'])
) {
$this->_params['auto_renew'] = TRUE;
......@@ -1166,6 +1169,12 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
$this->_params['frequency_interval'] = $this->_params['frequency_interval'] ?? $this->_values['fee'][$priceFieldId]['options'][$priceFieldValue]['membership_num_terms'];
$this->_params['frequency_unit'] = $this->_params['frequency_unit'] ?? $membershipTypeDetails['duration_unit'];
}
elseif (!$this->_separateMembershipPayment && (in_array($selectedMembershipTypeID, $membershipTypes['autorenew_required'])
|| in_array($selectedMembershipTypeID, $membershipTypes['autorenew_optional']))) {
// otherwise check if we have a separate membership payment setting as that will allow people to independently opt into recurring contributions and memberships
// If we don't have that and the membership type is auto recur or opt into recur set is_recur to 0.
$this->_params['is_recur'] = $this->_values['is_recur'] = 0;
}
}
/**
......
......@@ -93,7 +93,6 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase {
$priceFieldValueId = $this->getPriceFieldValue($membershipTypeID);
$form->testSubmit(array_merge($this->getSubmitParams(), [
'price_' . $this->priceSetId => $priceFieldValueId,
'is_recur' => 1,
]));
$this->assertEquals(1, $form->_params['is_recur']);
}
......@@ -107,7 +106,7 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase {
$priceFieldValueId = $this->getPriceFieldValue($membershipTypeID);
$form->testSubmit(array_merge($this->getSubmitParams(), [
'price_' . $this->priceSetId => $priceFieldValueId,
'is_recur' => 0,
'auto_renew' => 0,
]));
$this->assertEquals(0, $form->_params['is_recur']);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment