[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/odoo#70885

X-original-commit: 948c22243c88dd905f1a7838f6fba75f44f06b2a
Related: odoo/enterprise#18349
Signed-off-by: Antoine Vandevenne (anv) <AntoineVDV@users.noreply.github.com>
This commit is contained in:
Antoine Vandevenne (anv)
2021-05-17 14:22:14 +00:00
parent e2db444a1f
commit 26527370a2
+15 -10
View File
@@ -25,11 +25,15 @@ class PaypalController(http.Controller):
The route also allows the GET method in case the user clicks on "go back to merchant site".
"""
_logger.info("beginning DPN with post data:\n%s", pprint.pformat(data))
self._validate_data_authenticity(**data)
if data:
request.env['payment.transaction']._handle_feedback_data('paypal', data)
try:
self._validate_data_authenticity(**data)
except ValidationError:
pass # The transaction has been moved to state 'error'. Redirect to /payment/status.
else:
pass # The customer has cancelled the payment, don't do anything
if data:
request.env['payment.transaction'].sudo()._handle_feedback_data('paypal', data)
else:
pass # The customer has cancelled the payment, don't do anything
return werkzeug.utils.redirect('/payment/status')
@http.route(_notify_url, type='http', auth='public', methods=['GET', 'POST'], csrf=False)
@@ -38,7 +42,7 @@ class PaypalController(http.Controller):
_logger.info("beginning IPN with post data:\n%s", pprint.pformat(data))
try:
self._validate_data_authenticity(**data)
request.env['payment.transaction']._handle_feedback_data('paypal', data)
request.env['payment.transaction'].sudo()._handle_feedback_data('paypal', data)
except ValidationError: # Acknowledge the notification to avoid getting spammed
_logger.exception("unable to handle the IPN data; skipping to acknowledge the notif")
return ''
@@ -86,13 +90,14 @@ class PaypalController(http.Controller):
response_code = response.text
if response_code == 'VERIFIED':
_logger.info("authenticity of notification data verified")
elif response_code == 'INVALID':
raise ValidationError("PayPal: " + _("Notification data were not acknowledged."))
else:
raise ValidationError(
"PayPal: " + _(
if response_code == 'INVALID':
error_message = "PayPal: " + _("Notification data were not acknowledged.")
else:
error_message = "PayPal: " + _(
"Received unrecognized authentication check response code: received %s, "
"expected VERIFIED or INVALID.",
response_code
)
)
tx_sudo._set_error(error_message)
raise ValidationError(error_message)