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;
$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;
+ }
}
/**
$priceFieldValueId = $this->getPriceFieldValue($membershipTypeID);
$form->testSubmit(array_merge($this->getSubmitParams(), [
'price_' . $this->priceSetId => $priceFieldValueId,
- 'is_recur' => 1,
]));
$this->assertEquals(1, $form->_params['is_recur']);
}
$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']);
}