Skip to content

Commit 2652737

Browse files
committed
[FIX] payment_paypal: fix post-refactoring issues
- fix missing access rights when handling feedback data - redirect customers to the payment confirmation page when notification data are not acknowledged by PayPal, rather than displaying an internal server error task-2494916 closes odoo#70885 X-original-commit: 948c222 Related: odoo/enterprise#18349 Signed-off-by: Antoine Vandevenne (anv) <[email protected]>
1 parent e2db444 commit 2652737

File tree

1 file changed

+15
-10
lines changed
  • addons/payment_paypal/controllers

1 file changed

+15
-10
lines changed

addons/payment_paypal/controllers/main.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ def paypal_dpn(self, **data):
2525
The route also allows the GET method in case the user clicks on "go back to merchant site".
2626
"""
2727
_logger.info("beginning DPN with post data:\n%s", pprint.pformat(data))
28-
self._validate_data_authenticity(**data)
29-
if data:
30-
request.env['payment.transaction']._handle_feedback_data('paypal', data)
28+
try:
29+
self._validate_data_authenticity(**data)
30+
except ValidationError:
31+
pass # The transaction has been moved to state 'error'. Redirect to /payment/status.
3132
else:
32-
pass # The customer has cancelled the payment, don't do anything
33+
if data:
34+
request.env['payment.transaction'].sudo()._handle_feedback_data('paypal', data)
35+
else:
36+
pass # The customer has cancelled the payment, don't do anything
3337
return werkzeug.utils.redirect('/payment/status')
3438

3539
@http.route(_notify_url, type='http', auth='public', methods=['GET', 'POST'], csrf=False)
@@ -38,7 +42,7 @@ def paypal_ipn(self, **data):
3842
_logger.info("beginning IPN with post data:\n%s", pprint.pformat(data))
3943
try:
4044
self._validate_data_authenticity(**data)
41-
request.env['payment.transaction']._handle_feedback_data('paypal', data)
45+
request.env['payment.transaction'].sudo()._handle_feedback_data('paypal', data)
4246
except ValidationError: # Acknowledge the notification to avoid getting spammed
4347
_logger.exception("unable to handle the IPN data; skipping to acknowledge the notif")
4448
return ''
@@ -86,13 +90,14 @@ def _validate_data_authenticity(self, **data):
8690
response_code = response.text
8791
if response_code == 'VERIFIED':
8892
_logger.info("authenticity of notification data verified")
89-
elif response_code == 'INVALID':
90-
raise ValidationError("PayPal: " + _("Notification data were not acknowledged."))
9193
else:
92-
raise ValidationError(
93-
"PayPal: " + _(
94+
if response_code == 'INVALID':
95+
error_message = "PayPal: " + _("Notification data were not acknowledged.")
96+
else:
97+
error_message = "PayPal: " + _(
9498
"Received unrecognized authentication check response code: received %s, "
9599
"expected VERIFIED or INVALID.",
96100
response_code
97101
)
98-
)
102+
tx_sudo._set_error(error_message)
103+
raise ValidationError(error_message)

0 commit comments

Comments
 (0)