From f9a460d8148332467a2a46e3f00f67ce40ea1b2a Mon Sep 17 00:00:00 2001 From: Demesmaeker Date: Thu, 2 Dec 2021 14:34:46 +0000 Subject: [PATCH] [FIX] payment_adyen: discard refund notifications for unknown source txs Before this commit, a ValueError would be raised upon receiving a refund notification for a source transaction whose reference was not found in the database. As only ValidationError's are caught by the webhook controller, the acknowledgment string was never returned to Adyen and the endpoint was automatically disabled. This commits adds a check on the existence of the source transaction to allow discarding refund notifications if it is not found. task-2704522 closes odoo/odoo#82291 X-original-commit: 06d79dc3d01079db27f16dc56212cf68635e8c5d Signed-off-by: Antoine Vandevenne (anv) --- addons/payment_adyen/models/payment_transaction.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/payment_adyen/models/payment_transaction.py b/addons/payment_adyen/models/payment_transaction.py index a3f7e78e55e..91a4da15737 100644 --- a/addons/payment_adyen/models/payment_transaction.py +++ b/addons/payment_adyen/models/payment_transaction.py @@ -173,7 +173,13 @@ class PaymentTransaction(models.Model): source_tx = self.search( [('acquirer_reference', '=', source_acquirer_reference), ('provider', '=', 'adyen')] ) - tx = self._adyen_create_refund_tx_from_feedback_data(source_tx, data) + if source_tx: + # Manually create a refund transaction with a new reference. The reference of + # the refund transaction was personalized from Adyen and could be identical to + # that of an existing transaction. + tx = self._adyen_create_refund_tx_from_feedback_data(source_tx, data) + else: # The refund was initiated for an unknown source transaction + pass # Don't do anything with the refund notification if not tx: raise ValidationError(