After updating to CiviCRM 5.35 we cannot create payment plan memberships.
Before
You cannot create a payment plan memberships on CiviCRM 5.35.
After
You can create a payment plan memberships on CiviCRM 5.35.
Technical Details
A small change in CiviCRM internal caused this bug.
In CiviCRM 5.28, BAO/Membership.php#L334 will create the contribution and will add the membership_id to params array.
// Record contribution for this membership and create a MembershipPayment
if (!empty($params['contribution_status_id']) && empty($params['relate_contribution_id'])) {
$memInfo = array_merge($params, ['membership_id' => $membership->id]);
$params['contribution'] = self::recordMembershipContribution($memInfo);
}
In CiviCRM 5.35, Form/Membership.php#L1451 will create the contribution but will not add the membership_id to params array.
if (!empty($formValues['record_contribution'])) {
CRM_Member_BAO_Membership::recordMembershipContribution($params);
}
Because of that, this PR :
Removed the condition related that checks for the membership_id, the reason is that we are checking for the membership id to ensure that the contribution (payment) is one that is related to a membership, but since we already have a check to confirm that the contribution is a payment plan payment _membershipextras_isPaymentPlanWithAtLeastOneInstallment , and payment plans are created from the membership form, then we don't really need to check for the membership id too to confirm that.
Fixed the failing tests after removing the membership_id because the tests testExtendPendingPlanWithFixedMembershipAndOneInstalment and testVerifyMembershipStartDate in Hook/Pre/MembershipEditTest.php will alter the globals - _REQUEST - and the condition isContributionCreation && $isPaymentPlanPayment && $isFirstPaymentPlanContribution - after removing membership_id - will be true for normal contributions in the tests that following them. Solved by using CRM_Utils_GlobalStack to clean the globals after the tests.
Overview
After updating to CiviCRM 5.35 we cannot create payment plan memberships.
Before
You cannot create a payment plan memberships on CiviCRM 5.35.
After
You can create a payment plan memberships on CiviCRM 5.35.
Technical Details
A small change in CiviCRM internal caused this bug.
In CiviCRM 5.28, BAO/Membership.php#L334 will create the contribution and will add the
membership_id
toparams
array.In CiviCRM 5.35, Form/Membership.php#L1451 will create the contribution but will not add the
membership_id
toparams
array.Because of that, this PR :
membership_id
, the reason is that we are checking for the membership id to ensure that the contribution (payment) is one that is related to a membership, but since we already have a check to confirm that the contribution is a payment plan payment_membershipextras_isPaymentPlanWithAtLeastOneInstallment
, and payment plans are created from the membership form, then we don't really need to check for the membership id too to confirm that.membership_id
because the teststestExtendPendingPlanWithFixedMembershipAndOneInstalment
andtestVerifyMembershipStartDate
inHook/Pre/MembershipEditTest.php
will alter the globals -_REQUEST
- and the conditionisContributionCreation && $isPaymentPlanPayment && $isFirstPaymentPlanContribution
- after removingmembership_id
- will be true for normal contributions in the tests that following them. Solved by usingCRM_Utils_GlobalStack
to clean the globals after the tests.