From 43bb1c31e7ff2845f42cd07bade37be9036f3656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:06:06 +0200 Subject: [PATCH] Update DNS Merchant regular expression length (#168) --- README.md | 22 +++++++++++++--------- checkout_sdk/environment_subdomain.py | 2 +- tests/checkout_configuration_test.py | 15 +++++++++------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 88b11fb..3038e49 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,9 @@ def default(): checkout_api = CheckoutSdk .builder() .secret_key('secret_key') - .public_key('public_key') - .environment(Environment.sandbox()) + .public_key('public_key') # optional, only required for operations related with tokens + .environment(Environment.sandbox()) # or production() + .environment_subdomain("subdomain") # optional, Merchant-specific DNS name .build() payments_client = checkout_api.payments @@ -92,8 +93,9 @@ def oauth(): .builder() .oauth() .client_credentials(client_id='client_id', client_secret='client_secret') - .environment(Environment.sandbox()) - .scopes([OAuthScopes.GATEWAY_PAYMENT_REFUNDS, OAuthScopes.FILES]) + .environment(Environment.sandbox()) # or production() + .environment_subdomain("subdomain") # optional, Merchant-specific DNS name + .scopes([OAuthScopes.GATEWAY_PAYMENT_REFUNDS, OAuthScopes.FILES]) # optional, array of scopes .build() payments_client = checkout_api.payments @@ -114,8 +116,9 @@ def previous(): .builder() .previous() .secret_key('secret_key') - .public_key('public_key') - .environment(Environment.sandbox()) + .public_key('public_key') # optional, only required for operations related with tokens + .environment(Environment.sandbox()) # or production() + .environment_subdomain("subdomain") # optional, Merchant-specific DNS name .build() payments_client = checkout_api.payments @@ -160,9 +163,10 @@ def oauth(): .builder() .oauth() .client_credentials(client_id='client_id', client_secret='client_secret') - .environment(Environment.sandbox()) - .http_client_builder(CustomHttpClientBuilder()) - .scopes([OAuthScopes.GATEWAY_PAYMENT_REFUNDS, OAuthScopes.FILES]) + .environment(Environment.sandbox()) # or production() + .environment_subdomain("subdomain") # optional, Merchant-specific DNS name + .http_client_builder(CustomHttpClientBuilder()) # optional + .scopes([OAuthScopes.GATEWAY_PAYMENT_REFUNDS, OAuthScopes.FILES]) # optional, array of scopes .build() payments_client = checkout_api.payments diff --git a/checkout_sdk/environment_subdomain.py b/checkout_sdk/environment_subdomain.py index 9fcc126..3ccbac2 100644 --- a/checkout_sdk/environment_subdomain.py +++ b/checkout_sdk/environment_subdomain.py @@ -13,7 +13,7 @@ def add_subdomain_to_api_url_environment(environment: Environment, subdomain: st api_url = environment.base_uri new_environment = api_url - regex = r'^[0-9a-z]{8,11}$' + regex = r'^[0-9a-z]+$' if re.match(regex, subdomain): url_parts = urlparse(api_url) if url_parts.port: diff --git a/tests/checkout_configuration_test.py b/tests/checkout_configuration_test.py index 8d0961b..1705e88 100644 --- a/tests/checkout_configuration_test.py +++ b/tests/checkout_configuration_test.py @@ -34,9 +34,10 @@ def test_should_create_configuration(): @pytest.mark.parametrize( "subdomain, expected_url", [ - ("123dmain", "https://123dmain.api.sandbox.checkout.com/"), - ("123domain", "https://123domain.api.sandbox.checkout.com/"), - ("1234domain", "https://1234domain.api.sandbox.checkout.com/"), + ("a", "https://a.api.sandbox.checkout.com/"), + ("ab", "https://ab.api.sandbox.checkout.com/"), + ("abc", "https://abc.api.sandbox.checkout.com/"), + ("abc1", "https://abc1.api.sandbox.checkout.com/"), ("12345domain", "https://12345domain.api.sandbox.checkout.com/") ] ) @@ -66,9 +67,11 @@ def test_should_create_configuration_with_subdomain(subdomain, expected_url): "subdomain, expected_url", [ ("", "https://api.sandbox.checkout.com/"), - ("123", "https://api.sandbox.checkout.com/"), - ("123bad", "https://api.sandbox.checkout.com/"), - ("12345domainBad", "https://api.sandbox.checkout.com/") + (" ", "https://api.sandbox.checkout.com/"), + (" ", "https://api.sandbox.checkout.com/"), + (" - ", "https://api.sandbox.checkout.com/"), + ("a b", "https://api.sandbox.checkout.com/"), + ("ab c1.", "https://api.sandbox.checkout.com/") ] ) def test_should_create_configuration_with_bad_subdomain(subdomain, expected_url):