From e94912b9a9c5f96021350e4a377ddac9d3f2ab64 Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Sat, 10 Mar 2018 21:47:34 -0800 Subject: [PATCH] [FIX] payment: do not refund transactions if they need 3DS validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was already the intended behavior, but in Python a return inside of a try...finally does not behave this way. From the Python documentation [1]: When a return, break or continue statement is executed in the try suite of a try...finally statement, the finally clause is also executed ‘on the way out.’ This can cause issues because some payment acquirers will return an error when refunding a pending transaction. This puts the transaction in the 'error' state which means it won't be refunded anymore. Additionally, putting s2s_do_transaction in a try...except like this hides any traceback that occurs which makes troubleshooting harder. [1] https://docs.python.org/3/reference/compound_stmts.html#finally --- addons/payment/models/payment_acquirer.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 6bf9bfd8fb3..343e7ebd116 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -844,16 +844,13 @@ class PaymentToken(models.Model): 'partner_country_id': self.partner_id.country_id.id, }) - try: - kwargs.update({'3d_secure': True}) - tx.s2s_do_transaction(**kwargs) - # if 3D secure is called, then we do not refund right now - if tx.html_3ds: - return tx - except: - _logger.error('Error while validating a payment method') - finally: + kwargs.update({'3d_secure': True}) + tx.s2s_do_transaction(**kwargs) + + # if 3D secure is called, then we do not refund right now + if not tx.html_3ds: tx.s2s_do_refund() + return tx @api.multi