diff --git a/addons/payment_adyen/models/payment_provider.py b/addons/payment_adyen/models/payment_provider.py index e8a2d21ea75..9b7e3c84d52 100644 --- a/addons/payment_adyen/models/payment_provider.py +++ b/addons/payment_adyen/models/payment_provider.py @@ -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): diff --git a/addons/payment_adyen/models/payment_transaction.py b/addons/payment_adyen/models/payment_transaction.py index 42c447fca5f..1a32f53526d 100644 --- a/addons/payment_adyen/models/payment_transaction.py +++ b/addons/payment_adyen/models/payment_transaction.py @@ -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(