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] Cleanup validation in PaypalProIPN single function #20360

Merged
merged 1 commit into from
May 24, 2021
Merged
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
22 changes: 6 additions & 16 deletions CRM/Core/Payment/PayPalProIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,16 @@ public function single($input, $contribution, $recur = FALSE, $first = FALSE) {

// make sure the invoice is valid and matches what we have in the contribution record
if ((!$recur) || ($recur && $first)) {
if ($contribution->invoice_id != $input['invoice']) {
Civi::log()->debug('PayPalProIPN: Invoice values dont match between database and IPN request.');
echo "Failure: Invoice values dont match between database and IPN request<p>contribution is" . $contribution->invoice_id . " and input is " . $input['invoice'];
return;
if ($this->getContributionObject()->invoice_id !== $input['invoice']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This simplification is fine to me

throw new CRM_Core_Exception('PayPalProIPN: Invoice values dont match between database and IPN request.');
}
}
else {
$contribution->invoice_id = md5(uniqid(rand(), TRUE));
Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton do we not need to do this for subsequent recurring contributions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seamuslee001 no - I did try to explain in the message template - that contribution doesn't actually 'go anywhere' from here - or at least nowhere that accesses this property

Copy link
Contributor

Choose a reason for hiding this comment

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

right i see now ok

}

if (!$recur) {
if ($contribution->total_amount != $input['amount']) {
Civi::log()->debug('PayPalProIPN: Amount values dont match between database and IPN request.');
echo "Failure: Amount values dont match between database and IPN request<p>";
return;
if ($this->getContributionObject()->total_amount != $input['amount']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This simplification is fine to me

throw new CRM_Core_Exception('PayPalProIPN: Amount values dont match between database and IPN request.');
}
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

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

This works for me as well

$contribution->total_amount = $input['amount'];
}

$status = $input['paymentStatus'];
if ($status === 'Denied' || $status === 'Failed' || $status === 'Voided') {
Expand All @@ -402,7 +392,7 @@ public function single($input, $contribution, $recur = FALSE, $first = FALSE) {
Contribution::update(FALSE)->setValues([
'cancel_date' => 'now',
'contribution_status_id:name' => 'Cancelled',
])->addWhere('id', '=', $contribution->id)->execute();
])->addWhere('id', '=', $this->getContributionID())->execute();
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep fine

Civi::log()->debug("Setting contribution status to Cancelled");
return;
}
Expand All @@ -419,7 +409,7 @@ public function single($input, $contribution, $recur = FALSE, $first = FALSE) {
return;
}

CRM_Contribute_BAO_Contribution::completeOrder($input, $this->getContributionRecurID(), $contribution->id ?? NULL);
CRM_Contribute_BAO_Contribution::completeOrder($input, $this->getContributionRecurID(), $this->getContributionID());
Copy link
Contributor

Choose a reason for hiding this comment

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

Fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See how repeat other never gets the contribution - so that invoice_id is set but discarded

}

/**
Expand Down