Merge pull request #14897 from mattwire/membership_payment2
[civicrm-core.git] / CRM / Member / BAO / Membership.php
index bbd24740df693ddc6f4bb57e6afe13896b9b9b5c..3ec42d2989c4141e5d9046d2cf5ed1d8e96b0000 100644 (file)
@@ -2508,8 +2508,11 @@ WHERE      civicrm_membership.is_test = 0
     // store contribution id
     $params['contribution_id'] = $contribution->id;
 
-    //insert payment record for this membership
-    if (empty($ids['contribution']) || !empty($params['is_recur'])) {
+    // Create membership payment if it does not already exist
+    $membershipPayment = civicrm_api3('MembershipPayment', 'get', [
+      'contribution_id' => $contribution->id,
+    ]);
+    if (empty($membershipPayment['count'])) {
       civicrm_api3('MembershipPayment', 'create', [
         'membership_id' => $membershipId,
         'contribution_id' => $contribution->id,