From 0190b6c4929bd8dee0210f5deb9d17b259b57c64 Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Tue, 26 May 2020 13:52:07 +0000 Subject: [PATCH] [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) --- addons/payment_paypal/controllers/main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/payment_paypal/controllers/main.py b/addons/payment_paypal/controllers/main.py index 8f1b8fb6500..29a199ec1eb 100644 --- a/addons/payment_paypal/controllers/main.py +++ b/addons/payment_paypal/controllers/main.py @@ -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: