Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further cleanup and clarification on MembershipPayment #15407

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Ensure contribution_id is always set and clarify what functions do
  • Loading branch information
mattwire committed Oct 6, 2019
commit 976e393c49c233192e22a46d5478feef83fd7e27
27 changes: 15 additions & 12 deletions CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,22 @@ public static function create(&$params, &$ids = []) {
}
$params['skipLineItem'] = TRUE;

//record contribution for this membership
// 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);
}

// Add/update MembershipPayment record for this membership if it is a related contribution
if (!empty($params['relate_contribution_id'])) {
$membershipPaymentParams = [
'membership_id' => $membership->id,
'membership_type_id' => $membership->membership_type_id,
'contribution_id' => $params['relate_contribution_id'],
];
civicrm_api3('MembershipPayment', 'create', $membershipPaymentParams);
}

if (!empty($params['lineItems'])) {
$params['line_item'] = $params['lineItems'];
}
Expand Down Expand Up @@ -402,16 +412,6 @@ public static function create(&$params, &$ids = []) {
);
}

//insert payment record for this membership
if (!empty($params['relate_contribution_id'])) {
$membershipPaymentParams = [
'membership_id' => $membership->id,
'membership_type_id' => $membership->membership_type_id,
'contribution_id' => $params['relate_contribution_id'],
];
civicrm_api3('MembershipPayment', 'create', $membershipPaymentParams);
}

$transaction->commit();

self::createRelatedMemberships($params, $membership);
Expand Down Expand Up @@ -2438,14 +2438,17 @@ public static function getAllContactMembership($contactID, $isTest = FALSE, $onl

/**
* Record contribution record associated with membership.
* This will update an existing contribution if $params['contribution_id'] is passed in.
* This will create a MembershipPayment to link the contribution and membership
*
* @param array $params
* Array of submitted params.
* @param array $ids
* (@return CRM_Contribute_BAO_Contribution
*
* @throws \CiviCRM_API3_Exception
* @return CRM_Contribute_BAO_Contribution
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function recordMembershipContribution(&$params, $ids = []) {
if (!empty($ids)) {
Expand Down