From 5b51381ecfd6a56ffdcee9630a5873d2068df14a Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 25 Jul 2017 13:33:20 +1200 Subject: [PATCH] Fix paypal ipn not using correct payment instrument id --- CRM/Core/Payment/PayPalProIPN.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/CRM/Core/Payment/PayPalProIPN.php b/CRM/Core/Payment/PayPalProIPN.php index e557541c36..adac726bfa 100644 --- a/CRM/Core/Payment/PayPalProIPN.php +++ b/CRM/Core/Payment/PayPalProIPN.php @@ -170,14 +170,6 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN { return FALSE; } - if ($input['txnType'] == 'recurring_payment' && - $input['paymentStatus'] != 'Completed' - ) { - CRM_Core_Error::debug_log_message("Ignore all IPN payments that are not completed"); - echo "Failure: Invalid parameters

"; - return FALSE; - } - $recur = &$objects['contributionRecur']; // make sure the invoice ids match @@ -245,7 +237,19 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN { $recur->start_date = $now; } else { - $recur->modified_date = $now; + $input['invoice_id'] = md5(uniqid(rand(), TRUE)); + $input['original_contribution_id'] = $ids['contribution']; + $input['contribution_recur_id'] = $ids['contributionRecur']; + + if ($input['paymentStatus'] != 'Completed') { + throw new CRM_Core_Exception("Ignore all IPN payments that are not completed"); + } + // In future moving to create pending & then complete, but this OK for now. + // Also consider accepting 'Failed' like other processors. + $input['contribution_status_id'] = 1; + + civicrm_api3('Contribution', 'repeattransaction', $input); + return; } //contribution installment is completed @@ -310,6 +314,7 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN { $contribution->amount_level = $objects['contribution']->amount_level; $contribution->campaign_id = $objects['contribution']->campaign_id; $objects['contribution'] = &$contribution; + $contribution->invoice_id = md5(uniqid(rand(), TRUE)); } // CRM-13737 - am not aware of any reason why payment_date would not be set - this if is a belt & braces $objects['contribution']->receive_date = !empty($input['payment_date']) ? date('YmdHis', strtotime($input['payment_date'])) : $now; @@ -356,9 +361,6 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN { $transaction = new CRM_Core_Transaction(); - $participant = &$objects['participant']; - $membership = &$objects['membership']; - $status = $input['paymentStatus']; if ($status == 'Denied' || $status == 'Failed' || $status == 'Voided') { return $this->failed($objects, $transaction); -- 2.25.1