From 89df4b5faa1d75bb0ed2a81670b97d4753f7c600 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 30 Nov 2021 15:22:47 +0000 Subject: [PATCH] [FIX] payment_ogone: better error reason when payment is declined Before this revision, when a payment was declined, for instance because the authorization is declined by the bank, or the credit card amount limit is exceeded, the error was marked as "Received data with invalid payment status: 2" which is not very meaningful for the users. This revision aims to set the reason why the payment was declined with the meaningful error from ogone. closes odoo/odoo#80742 X-original-commit: 758f94a173379ba7bd22813b2050e3a6f98210a9 Signed-off-by: Antoine Vandevenne (anv) Signed-off-by: Denis Ledoux (dle) --- addons/payment_ogone/i18n/payment_ogone.pot | 6 ++++++ addons/payment_ogone/models/const.py | 1 + addons/payment_ogone/models/payment_transaction.py | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/addons/payment_ogone/i18n/payment_ogone.pot b/addons/payment_ogone/i18n/payment_ogone.pot index 452165becf7..6bf2d7ee910 100644 --- a/addons/payment_ogone/i18n/payment_ogone.pot +++ b/addons/payment_ogone/i18n/payment_ogone.pot @@ -136,6 +136,12 @@ msgstr "" msgid "The communication with the API failed." msgstr "" +#. module: payment_ogone +#: code:addons/payment_ogone/models/payment_transaction.py:0 +#, python-format +msgid "The payment has been declined: %s" +msgstr "" + #. module: payment_ogone #: code:addons/payment_ogone/models/payment_transaction.py:0 #, python-format diff --git a/addons/payment_ogone/models/const.py b/addons/payment_ogone/models/const.py index b842dfe2354..cab223f5ad6 100644 --- a/addons/payment_ogone/models/const.py +++ b/addons/payment_ogone/models/const.py @@ -74,4 +74,5 @@ PAYMENT_STATUS_MAPPING = { 'pending': (41, 46, 50, 51, 52, 55, 56, 81, 82, 91, 92, 99), # 46 = 3DS 'done': (5, 8, 9), 'cancel': (1,), + 'declined': (2,), } diff --git a/addons/payment_ogone/models/payment_transaction.py b/addons/payment_ogone/models/payment_transaction.py index 604140947db..fa59f173b60 100644 --- a/addons/payment_ogone/models/payment_transaction.py +++ b/addons/payment_ogone/models/payment_transaction.py @@ -204,6 +204,17 @@ class PaymentTransaction(models.Model): self._set_done() elif payment_status in const.PAYMENT_STATUS_MAPPING['cancel']: self._set_canceled() + elif payment_status in const.PAYMENT_STATUS_MAPPING['declined']: + if data.get("NCERRORPLUS"): + reason = data.get("NCERRORPLUS") + elif data.get("NCERROR"): + reason = "Error code: %s" % data.get("NCERROR") + else: + reason = "Unknown reason" + _logger.info("the payment has been declined: %s.", reason) + self._set_error( + "Ogone: " + _("The payment has been declined: %s", reason) + ) else: # Classify unknown payment statuses as `error` tx state _logger.info( "received data with invalid payment status (%s) for transaction with reference %s",