[REF] Stop instantiating transaction in PaypalIPN
authoreileen <emcnaughton@wikimedia.org>
Sat, 1 Aug 2020 01:56:22 +0000 (13:56 +1200)
committereileen <emcnaughton@wikimedia.org>
Sat, 1 Aug 2020 01:56:22 +0000 (13:56 +1200)
CRM/Core/Payment/BaseIPN.php
CRM/Core/Payment/PayPalIPN.php

index 973fbd988894b02582d1d483917c7ee91e3e86f8..a0fdcf41c63ff171785ecabc452b2db807f3772b 100644 (file)
@@ -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;
   }
index 0e87056c8755bde0a2d8c017730632d2eafeffc4..4f3801fb8d594de87d107346af5d1373aae7c65d 100644 (file)
@@ -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<p>';
       return;
     }
 
-    $this->completeTransaction($input, $ids, $objects, $transaction, $recur);
+    $this->completeTransaction($input, $ids, $objects);
   }
 
   /**