[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
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user