From 597ecd7a2015e2b712cde37b1555c83db936c065 Mon Sep 17 00:00:00 2001 From: Luca Monari Date: Wed, 1 Mar 2023 08:30:07 +0100 Subject: [PATCH 1/2] Restored previous logic with improved URLs --- mangopay/__init__.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/mangopay/__init__.py b/mangopay/__init__.py index 01fcc0b..60038e2 100644 --- a/mangopay/__init__.py +++ b/mangopay/__init__.py @@ -6,12 +6,38 @@ client_id = None apikey = None +PLENTIFIC_NAMESPACE = os.getenv("PLENTIFIC_NAMESPACE", "uk") +PLENTIFIC_IS_E2E = env_to_bool("PLENTIFIC_IS_E2E", False) + MANGOPAY_URL = os.getenv("MANGOPAY_URL", "https://api.mangopay.com") MANGOPAY_SANDBOX_URL = os.getenv("MANGOPAY_URL", "https://api.sandbox.mangopay.com") -api_url = f'{MANGOPAY_URL}/v2.01/' -api_sandbox_url = f'{MANGOPAY_SANDBOX_URL}/v2.01/' +MANGOPAY_DEFAULT_LOCAL_MOCK_SERVER_URL = f"http://localhost:1081/mock-server/{PLENTIFIC_NAMESPACE}/mangopay" +MANGOPAY_DEFAULT_E2E_MOCK_SERVER_URL = "http://mock-server:1081/mangopay" +MANGOPAY_IS_MOCK_SERVER_ENABLED = env_to_bool("MANGOPAY_IS_MOCK_SERVER_ENABLED", False) + +MANGOPAY_MOCK_SERVER_URL = os.environ.get( + "MANGOPAY_MOCK_SERVER_URL", + MANGOPAY_DEFAULT_E2E_MOCK_SERVER_URL + if PLENTIFIC_IS_E2E + else MANGOPAY_DEFAULT_LOCAL_MOCK_SERVER_URL, +) + + +def _get_api_url(): + if MANGOPAY_IS_MOCK_SERVER_ENABLED: + return MANGOPAY_MOCK_SERVER_URL + return MANGOPAY_URL + + +def _get_sandbox_url(): + if MANGOPAY_IS_MOCK_SERVER_ENABLED: + return MANGOPAY_MOCK_SERVER_URL + return MANGOPAY_SANDBOX_URL + +api_url = f'{_get_api_url()}/v2.01/' +api_sandbox_url = f'{_get_sandbox_url()}/v2.01/' temp_dir = None api_version = 2.01 sandbox = True From 51444f844adf8b764323717ffdcce42f679cc618 Mon Sep 17 00:00:00 2001 From: Luca Monari Date: Wed, 1 Mar 2023 10:24:04 +0100 Subject: [PATCH 2/2] Added comment --- mangopay/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mangopay/__init__.py b/mangopay/__init__.py index 60038e2..d00b76e 100644 --- a/mangopay/__init__.py +++ b/mangopay/__init__.py @@ -6,16 +6,17 @@ client_id = None apikey = None -PLENTIFIC_NAMESPACE = os.getenv("PLENTIFIC_NAMESPACE", "uk") -PLENTIFIC_IS_E2E = env_to_bool("PLENTIFIC_IS_E2E", False) - MANGOPAY_URL = os.getenv("MANGOPAY_URL", "https://api.mangopay.com") MANGOPAY_SANDBOX_URL = os.getenv("MANGOPAY_URL", "https://api.sandbox.mangopay.com") +# This logic will affect the URL used by this SDK only! +# On payments service we have similar settings (settings/mangopay.py) that applies +# to the MangopayAPIClient instead +PLENTIFIC_NAMESPACE = os.getenv("PLENTIFIC_NAMESPACE", "uk") +PLENTIFIC_IS_E2E = env_to_bool("PLENTIFIC_IS_E2E", False) MANGOPAY_DEFAULT_LOCAL_MOCK_SERVER_URL = f"http://localhost:1081/mock-server/{PLENTIFIC_NAMESPACE}/mangopay" MANGOPAY_DEFAULT_E2E_MOCK_SERVER_URL = "http://mock-server:1081/mangopay" MANGOPAY_IS_MOCK_SERVER_ENABLED = env_to_bool("MANGOPAY_IS_MOCK_SERVER_ENABLED", False) - MANGOPAY_MOCK_SERVER_URL = os.environ.get( "MANGOPAY_MOCK_SERVER_URL", MANGOPAY_DEFAULT_E2E_MOCK_SERVER_URL