Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Stop instantiating transaction in PaypalIPN #18020

Merged
merged 1 commit into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions CRM/Core/Payment/BaseIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function loadObjects($input, &$ids, &$objects, $required, $paymentProcess
* @return bool
* @throws \CiviCRM_API3_Exception
*/
public function failed(&$objects, &$transaction, $input = []) {
public function failed(&$objects, $transaction = NULL, $input = []) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could instantiate a transaction within this function - but I think in the case of a crash not updating the contribution to failed would likely be worse than a partial update

$contribution = &$objects['contribution'];
$memberships = [];
if (!empty($objects['membership'])) {
Expand Down Expand Up @@ -266,7 +266,9 @@ public function failed(&$objects, &$transaction, $input = []) {
}
}

$transaction->commit();
if ($transaction) {
$transaction->commit();
}
Civi::log()->debug("Setting contribution status to Failed");
return TRUE;
}
Expand Down Expand Up @@ -299,7 +301,7 @@ public function pending(&$objects, &$transaction) {
* @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'])) {
Expand Down Expand Up @@ -353,7 +355,9 @@ public function cancelled(&$objects, &$transaction, $input = []) {
$this->cancelParticipant($participant->id);
}
}
$transaction->commit();
if ($transaction) {
$transaction->commit();
}
Civi::log()->debug("Setting contribution status to Cancelled");
return TRUE;
}
Expand Down
11 changes: 5 additions & 6 deletions CRM/Core/Payment/PayPalIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,18 @@ public function single(&$input, &$ids, &$objects, $recur = FALSE, $first = FALSE
$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');
Expand All @@ -277,13 +277,12 @@ public function single(&$input, &$ids, &$objects, $recur = FALSE, $first = FALSE
// 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);
}

/**
Expand Down