Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Set adyen requests timeout (#9043)

Iga Karbowiak75c8c4610c28
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.py
index 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, urljoin
import Adyen
import opentracing
import opentracing.tags
+from Adyen.httpclient import HTTPClient
from django.contrib.auth.hashers import make_password
from django.contrib.sites.models import Site
from django.core.exceptions import ObjectDoesNotExist, ValidationError
@@ -50,6 +51,7 @@ from .webhooks import handle_additional_actions, handle_webhook
GATEWAY_NAME = "Adyen"
WEBHOOK_PATH = "/webhooks"
ADDITIONAL_ACTION_PATH = "/additional-actions"
+HTTP_TIMEOUT = 20 # in seconds
class 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 = True
def _insert_webhook_endpoint_to_configuration(self, raw_configuration, channel):
updated = False
diff --git a/saleor/payment/gateways/adyen/tests/test_plugin.py b/saleor/payment/gateways/adyen/tests/test_plugin.py
index 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 mock
import Adyen
import pytest
+import requests
from django.core.exceptions import ValidationError
from 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)