Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Set adyen requests timeout (#9043)
Iga Karbowiak75c8c4610c28
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.pyindex f4bf5c6d33..522e536835 100644--- a/saleor/payment/gateways/adyen/plugin.py+++ b/saleor/payment/gateways/adyen/plugin.py@@ -5,6 +5,7 @@ from urllib.parse import urlencode, urljoinimport Adyenimport opentracingimport opentracing.tags+from Adyen.httpclient import HTTPClientfrom django.contrib.auth.hashers import make_passwordfrom django.contrib.sites.models import Sitefrom django.core.exceptions import ObjectDoesNotExist, ValidationError@@ -50,6 +51,7 @@ from .webhooks import handle_additional_actions, handle_webhookGATEWAY_NAME = "Adyen"WEBHOOK_PATH = "/webhooks"ADDITIONAL_ACTION_PATH = "/additional-actions"+HTTP_TIMEOUT = 20 # in secondsclass AdyenGatewayPlugin(BasePlugin):@@ -224,6 +226,17 @@ class AdyenGatewayPlugin(BasePlugin):self.adyen = Adyen.Adyen(xapikey=api_key, live_endpoint_prefix=live_endpoint, platform=platform)+ self._init_http_client()++ def _init_http_client(self):+ adyen_client = self.adyen.client+ adyen_client.http_client = HTTPClient(+ user_agent_suffix=adyen_client.USER_AGENT_SUFFIX,+ lib_version=adyen_client.LIB_VERSION,+ force_request=adyen_client.http_force,+ timeout=HTTP_TIMEOUT,+ )+ adyen_client.http_init = Truedef _insert_webhook_endpoint_to_configuration(self, raw_configuration, channel):updated = Falsediff --git a/saleor/payment/gateways/adyen/tests/test_plugin.py b/saleor/payment/gateways/adyen/tests/test_plugin.pyindex 5d11b016c7..b3974f36ed 100644--- a/saleor/payment/gateways/adyen/tests/test_plugin.py+++ b/saleor/payment/gateways/adyen/tests/test_plugin.py@@ -4,6 +4,7 @@ from unittest import mockimport Adyenimport pytest+import requestsfrom django.core.exceptions import ValidationErrorfrom requests.exceptions import RequestException, SSLError@@ -702,3 +703,21 @@ def test_adyen_check_payment_balance_adyen_raises_error(plugin.adyen.checkout.client.call_checkout_api,action="paymentMethods/balance",)++[email protected]("saleor.payment.gateways.adyen.plugin.HTTP_TIMEOUT", 0.001)+def test_adyen_check_payment_timeout(adyen_plugin, adyen_check_balance_response):+ plugin = adyen_plugin()++ data = {+ "gatewayId": "mirumee.payments.gateway",+ "method": "givex",+ "card": {+ "cvc": "9891",+ "code": "1234567910",+ "money": {"currency": "GBP", "amount": Decimal(100.0)},+ },+ }++ with pytest.raises(requests.exceptions.ConnectTimeout):+ plugin.check_payment_balance(data)