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

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

[REF] Cleanup validation in PaypalProIPN single function

Before

Passed in object used for validation. Properties set on the passed-in-object only to be discarded

After

Simplified validation, unused variables not set

Technical Details

This fixes interaction with the contribution object to instead use the function
and switches the standardised error handling (throw an exception & let
it be caught).

The contribution object used to be passed to completeOrder but no longer
so there is no reason to set total_amount & invoice_id on it
(they will be used from input)

Comments

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
This fixes interaction with the contribution object to instead use the function
and switches the standardised error handling (throw an exception & let
it be caught).

The contribution object used to be passed to completeOrder but no longer
so there is no reason to set total_amount & invoice_id on it
(they will be used from input)
@civibot
Copy link

civibot bot commented May 20, 2021

(Standard links)

@civibot civibot bot added the master label May 20, 2021
@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 are you OK to merge this - it's actually pretty straight forward

}
}
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

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

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

}
}
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

@@ -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

@@ -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

@seamuslee001
Copy link
Contributor

All seems fine to me now

@seamuslee001 seamuslee001 merged commit 36d7246 into civicrm:master May 24, 2021
@seamuslee001 seamuslee001 deleted the ppp branch May 24, 2021 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants