summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Bouvy <dbo@odoo.com>2020-04-16 08:33:21 +0000
committerDamien Bouvy <dbo@odoo.com>2020-04-22 16:54:27 +0000
commitb1c81a65729a3f6c6b1b11df6d3edd5ff6503be3 (patch)
tree0be9798ee5248b7574d1d9cfbeeded0eb20d9342
parente3021499a4fc1c9d40f2c2f39d601e667e8c3213 (diff)
[FIX] payment_authorize: display errors to customers
Set the transaction to the state 'error' when Authorize.net responds with that status, as it will display a message to the customer to detail the problem. opw-2231276 X-original-commit: 005607fce4a22394a9f67cc4eaa52f8bf89780f0
-rw-r--r--addons/payment_authorize/models/authorize_request.py6
-rw-r--r--addons/payment_authorize/models/payment.py15
2 files changed, 7 insertions, 14 deletions
diff --git a/addons/payment_authorize/models/authorize_request.py b/addons/payment_authorize/models/authorize_request.py
index 4d28aed0396..2b810f1a21d 100644
--- a/addons/payment_authorize/models/authorize_request.py
+++ b/addons/payment_authorize/models/authorize_request.py
@@ -226,11 +226,15 @@ class AuthorizeAPI():
'x_response_reason_text': response.get('err_msg')
}
- return {
+ result = {
'x_response_code': response.get('transactionResponse', {}).get('responseCode'),
'x_trans_id': response.get('transactionResponse', {}).get('transId'),
'x_type': 'auth_capture'
}
+ errors = response.get('transactionResponse', {}).get('errors')
+ if errors:
+ result['x_response_reason_text'] = '\n'.join([e.get('errorText') for e in errors])
+ return result
def authorize(self, token, amount, reference):
"""Authorize a payment for the given amount.
diff --git a/addons/payment_authorize/models/payment.py b/addons/payment_authorize/models/payment.py
index 3c89c36b5da..dcd17f0f5d6 100644
--- a/addons/payment_authorize/models/payment.py
+++ b/addons/payment_authorize/models/payment.py
@@ -161,6 +161,7 @@ class TxAuthorize(models.Model):
_authorize_valid_tx_status = 1
_authorize_pending_tx_status = 4
_authorize_cancel_tx_status = 2
+ _authorize_error_tx_status = 3
# --------------------------------------------------
# FORM RELATED METHODS
@@ -229,13 +230,6 @@ class TxAuthorize(models.Model):
self.write({'acquirer_reference': data.get('x_trans_id')})
self._set_transaction_pending()
return True
- elif status_code == self._authorize_cancel_tx_status:
- self.write({
- 'acquirer_reference': data.get('x_trans_id'),
- 'state_message': data.get('x_response_reason_text'),
- })
- self._set_transaction_cancel()
- return True
else:
error = data.get('x_response_reason_text')
_logger.info(error)
@@ -303,18 +297,13 @@ class TxAuthorize(models.Model):
self.write({'acquirer_reference': tree.get('x_trans_id')})
self._set_transaction_pending()
return True
- elif status_code == self._authorize_cancel_tx_status:
- self.write({'acquirer_reference': tree.get('x_trans_id')})
- self._set_transaction_cancel()
- return True
else:
error = tree.get('x_response_reason_text')
_logger.info(error)
self.write({
- 'state_message': error,
'acquirer_reference': tree.get('x_trans_id'),
})
- self._set_transaction_cancel()
+ self._set_transaction_error(msg=error)
return False