[FIX] payment_adyen: set error when offline transaction failed
When the offline transaction failed, the error was raised that rollback all the operations and the failed transaction was not traced anywhere. With this commit the error is caught and the failed transaction can be seen in chatter. X-original-commit: 21e84624841690d36bd38b768e35cc61b3c6a17b Part-of: odoo/odoo#124040
This commit is contained in:
@@ -117,15 +117,19 @@ class PaymentProvider(models.Model):
|
||||
headers = {'X-API-Key': self.adyen_api_key}
|
||||
try:
|
||||
response = requests.request(method, url, json=payload, headers=headers, timeout=60)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.HTTPError:
|
||||
_logger.exception(
|
||||
"invalid API request at %s with data %s: %s", url, payload, response.text
|
||||
)
|
||||
msg = response.json().get('message', '')
|
||||
raise ValidationError(
|
||||
"Adyen: " + _("The communication with the API failed. Details: %s", msg)
|
||||
)
|
||||
except requests.exceptions.ConnectionError:
|
||||
_logger.exception("unable to reach endpoint at %s", url)
|
||||
raise ValidationError("Adyen: " + _("Could not establish the connection to the API."))
|
||||
except requests.exceptions.HTTPError as error:
|
||||
_logger.exception(
|
||||
"invalid API request at %s with data %s: %s", url, payload, error.response.text
|
||||
)
|
||||
raise ValidationError("Adyen: " + _("The communication with the API failed."))
|
||||
return response.json()
|
||||
|
||||
def _adyen_compute_shopper_reference(self, partner_id):
|
||||
|
||||
@@ -94,12 +94,19 @@ class PaymentTransaction(models.Model):
|
||||
data.update(captureDelayHours=0)
|
||||
|
||||
# Make the payment request to Adyen
|
||||
response_content = self.provider_id._adyen_make_request(
|
||||
url_field_name='adyen_checkout_api_url',
|
||||
endpoint='/payments',
|
||||
payload=data,
|
||||
method='POST',
|
||||
)
|
||||
try:
|
||||
response_content = self.provider_id._adyen_make_request(
|
||||
url_field_name='adyen_checkout_api_url',
|
||||
endpoint='/payments',
|
||||
payload=data,
|
||||
method='POST',
|
||||
)
|
||||
except ValidationError as e:
|
||||
if self.operation == 'offline':
|
||||
self._set_error(e) # Log the error message on linked documents' chatter.
|
||||
return # There is nothing to process.
|
||||
else:
|
||||
raise e
|
||||
|
||||
# Handle the payment request response
|
||||
_logger.info(
|
||||
|
||||
Reference in New Issue
Block a user