[FIX] payment: do not refund transactions if they need 3DS validation
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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user