PayPal fails to create contribution following duplicate merge when membership record has been deleted
Whilst JMA was reviewing the data on a client system we found that a number of PayPal IPN recurring contributions had not been recorded. A decent number of them were not recorded because it seems we hit this line https://github.com/civicrm/civicrm-core/blob/068c4e1acb11a4f9c6d5d6f01e0003a12156d363/CRM/Contribute/BAO/Contribution.php#L4412 . The situation seems to have been that perhaps a duplicate membership had been created somewhere along the road but had been subsequently deleted.
I would suggest that the fact that a contribution may have a membership id associated with it but we can no longer find the associated membership should not be a reason that the IPN shouldn't be processed.
Example log messages
Feb 09 2021 08:19:28 [debug] PayPalIPN: Received (ContactID: xxxx; trxn_id: zzzzzzzz). Feb 09 2021 08:19:28 [debug] PayPalIPN: Received payment for membership tttt. Original contribution was hhh. The template for this contribution is nnnit is linked to 0payments for this membership. It has 1 line items linked to this membership. it is expected the original contribution will be linked by both entities to the membership. Feb 09 2021 08:19:28 [debug] PayPalIPN: Membership should be linked to contribution recur record hhhh 1links found Feb 09 2021 08:19:28 [error] $Fatal Error Details = array:3 [ "message" => "Could not find membership record: ttt"