From 156534ce4dfcba4c08f35dff412225ff073f1cff Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 1 Aug 2020 13:56:22 +1200 Subject: [PATCH] [REF] Stop instantiating transaction in PaypalIPN --- CRM/Core/Payment/BaseIPN.php | 12 ++++++++---- CRM/Core/Payment/PayPalIPN.php | 11 +++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index 973fbd9888..a0fdcf41c6 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -214,7 +214,7 @@ class CRM_Core_Payment_BaseIPN { * @return bool * @throws \CiviCRM_API3_Exception */ - public function failed(&$objects, &$transaction, $input = []) { + public function failed(&$objects, $transaction = NULL, $input = []) { $contribution = &$objects['contribution']; $memberships = []; if (!empty($objects['membership'])) { @@ -266,7 +266,9 @@ class CRM_Core_Payment_BaseIPN { } } - $transaction->commit(); + if ($transaction) { + $transaction->commit(); + } Civi::log()->debug("Setting contribution status to Failed"); return TRUE; } @@ -299,7 +301,7 @@ class CRM_Core_Payment_BaseIPN { * @return bool * @throws \CiviCRM_API3_Exception */ - public function cancelled(&$objects, &$transaction, $input = []) { + public function cancelled(&$objects, $transaction = NULL, $input = []) { $contribution = &$objects['contribution']; $memberships = []; if (!empty($objects['membership'])) { @@ -353,7 +355,9 @@ class CRM_Core_Payment_BaseIPN { $this->cancelParticipant($participant->id); } } - $transaction->commit(); + if ($transaction) { + $transaction->commit(); + } Civi::log()->debug("Setting contribution status to Cancelled"); return TRUE; } diff --git a/CRM/Core/Payment/PayPalIPN.php b/CRM/Core/Payment/PayPalIPN.php index 0e87056c87..4f3801fb8d 100644 --- a/CRM/Core/Payment/PayPalIPN.php +++ b/CRM/Core/Payment/PayPalIPN.php @@ -256,18 +256,18 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { $contribution->total_amount = $input['amount']; } - $transaction = new CRM_Core_Transaction(); - $status = $input['paymentStatus']; if ($status == 'Denied' || $status == 'Failed' || $status == 'Voided') { - return $this->failed($objects, $transaction); + $this->failed($objects); + return; } if ($status === 'Pending') { Civi::log()->debug('Returning since contribution status is Pending'); return; } elseif ($status == 'Refunded' || $status == 'Reversed') { - return $this->cancelled($objects, $transaction); + $this->cancelled($objects); + return; } elseif ($status !== 'Completed') { Civi::log()->debug('Returning since contribution status is not handled'); @@ -277,13 +277,12 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { // check if contribution is already completed, if so we ignore this ipn $completedStatusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); if ($contribution->contribution_status_id == $completedStatusId) { - $transaction->commit(); Civi::log()->debug('PayPalIPN: Returning since contribution has already been handled. (ID: ' . $contribution->id . ').'); echo 'Success: Contribution has already been handled

'; return; } - $this->completeTransaction($input, $ids, $objects, $transaction, $recur); + $this->completeTransaction($input, $ids, $objects); } /** -- 2.25.1