2

I would like to make several people a member, linked to 1 payment

  • person A: membership (+ contribution)
  • person B: membership (related to membership person A)
$contact_a = 2;
$contact_b = 3;

$contribution = civicrm_api3('Contribution', 'create', [
  'financial_type_id' => 2,
  'contact_id' => (int) $contact_a,
  'contribution_status_id' => 2,
  'total_amount' => 50,
  'is_pay_later' => 1,
]);

$main_membership = civicrm_api3('Membership', 'create', [
  'contact_id' => (int) $contact_a,
  'membership_type_id' => 1,
  'status_id' => 5,
  'skipStatusCal' => 1,
]);

$part_membership = civicrm_api3('Membership', 'create', [
  'contact_id' => (int) $contact_b,
  'owner_membership_id' => $main_membership['id'],
  'membership_type_id' => 1,
  'status_id' => 5,
  'skipStatusCal' => 1,
]);

$memb_payment = civicrm_api3('MembershipPayment', 'create', [
  'membership_id' => (int) $main_membership['id'],
  'contribution_id' => (int) $contribution['id'],
]);

This seems correct, person A gets a membership & contribution, person B gets a membership related to the membership of person A.

As soon as I process the membership payment via the API the contribution is complete and the membership for person A becomes active, BUT the membership for person B is deleted !?

$complete = civicrm_api3('Contribution', 'completetransaction', [
    'id' => 9, 
    'is_email_receipt' => 0
]);

I have simplified the operation to only the membership registrations:

$contact_a = 2;
$contact_b = 3;

$main_membership = civicrm_api3('Membership', 'create', [
  'contact_id' => (int) $contact_a,
  'membership_type_id' => 1,
  'status_id' => 5,
  'skipStatusCal' => 1,
]);

$part_membership = civicrm_api3('Membership', 'create', [
  'contact_id' => (int) $contact_b,
  'owner_membership_id' => $main_membership['id'],
  'membership_type_id' => 1,
  'status_id' => 5,
  'skipStatusCal' => 1,
]);

And if I then set the membership of person A to "New" the membership of person B is deleted !?

$new = civicrm_api3('Membership', 'create', [
  'id' => 39,
  'status_id' => "New",
]);

The problem therefore lies somewhere with the update of the membership of person A.

Does anyone have an idea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.