[FIX] payment_paypal: reply nicely to Paypal IPN with unknown reference

If a Paypal account is configured to send IPN notifications to Odoo at
the account level (as we officially advise in our doc) and is used in
another system than Odoo, transactions from that other system will
trigger notifications that gets sent to Odoo with references that are
unknown.

This tends to generate 500 errors, but Paypal will keep trying to send
the same notification over and over; this will cause a lot of errors in
logs and could also could Paypal to contact the account owner regarding
repeated failure on the IPN endpoints, which is somewhat scary for
lambda users.

This commit simply ensures that any such payment will not trigger a
faulty response (Paypal only accept 200 OK responses), but still keep a
trace of it in the logs as a warning.

Note that enabling IPN at the account level is not strictly necessary,
as transactions sent by Odoo force this behaviour regardless of the
setting with the 'notify_url' param.

closes odoo/odoo#56323

X-original-commit: e4e4b51e0d97c5dd6afe332bf7c70d8321469a52
Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
This commit is contained in:
Damien Bouvy
2020-08-21 15:11:37 +00:00
parent a0e918796f
commit 0190b6c492
@@ -60,6 +60,11 @@ class PaypalController(http.Controller):
tx = None
if reference:
tx = request.env['payment.transaction'].sudo().search([('reference', '=', reference)])
if not tx:
# we have seemingly received a notification for a payment that did not come from
# odoo, acknowledge it otherwise paypal will keep trying
_logger.warning('received notification for unknown payment reference')
return False
paypal_url = tx.acquirer_id.paypal_get_form_action_url()
pdt_request = bool(post.get('amt')) # check for specific pdt param
if pdt_request: