Skip to content

Commit 47bd28f

Browse files
authored
Added support for custom live endpoint URLs for PAL service (#120)
* Added support for custom live endpoint URLs for PAL service. Covers issue #119 * Added test for determining binlookup service URL. Issue #119 * Updated TestDetermineUrl tests after merge with upstream
1 parent 6c0d3e2 commit 47bd28f

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

Adyen/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ def __init__(
103103
self.live_endpoint_prefix = live_endpoint_prefix
104104
self.http_timeout = http_timeout
105105

106-
@staticmethod
107-
def _determine_api_url(platform, service, action):
106+
def _determine_api_url(self, platform, service, action):
108107
"""This returns the Adyen API endpoint based on the provided platform,
109108
service and action.
110109
@@ -113,7 +112,13 @@ def _determine_api_url(platform, service, action):
113112
service (str): API service to place request through.
114113
action (str): the API action to perform.
115114
"""
116-
base_uri = settings.BASE_PAL_URL.format(platform)
115+
if platform == "live" and self.live_endpoint_prefix:
116+
base_uri = settings.PAL_LIVE_ENDPOINT_URL_TEMPLATE.format(
117+
self.live_endpoint_prefix
118+
)
119+
else:
120+
base_uri = settings.BASE_PAL_URL.format(platform)
121+
117122
if service == "Recurring":
118123
api_version = settings.API_RECURRING_VERSION
119124
elif service == "Payout":

Adyen/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Those constants are used from the library only
22
BASE_PAL_URL = "https://pal-{}.adyen.com/pal/servlet"
3+
PAL_LIVE_ENDPOINT_URL_TEMPLATE = "https://{}-pal-live" \
4+
".adyenpayments.com/pal/servlet"
35
BASE_HPP_URL = "https://{}.adyen.com/hpp"
46
ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com"
57
ENDPOINT_CHECKOUT_LIVE_SUFFIX = "https://{}-checkout-live" \

test/DetermineEndpointTest.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,55 @@ def test_payments_invalid_platform(self):
5454
self.adyen.checkout.payments(request)
5555
except AdyenEndpointInvalidFormat as error:
5656
self.assertIsNotNone(error)
57+
58+
def test_pal_url_live_endpoint_prefix_live_platform(self):
59+
self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
60+
url = self.adyen.client._determine_api_url(
61+
"live", "Payment", "payments"
62+
)
63+
self.assertEqual(
64+
url,
65+
("https://1797a841fbb37ca7-AdyenDemo-pal-"
66+
"live.adyenpayments.com/pal/servlet/Payment/v64/payments")
67+
)
68+
69+
def test_pal_url_live_endpoint_prefix_test_platform(self):
70+
self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
71+
url = self.adyen.client._determine_api_url(
72+
"test", "Payment", "payments"
73+
)
74+
self.assertEqual(
75+
url,
76+
"https://pal-test.adyen.com/pal/servlet/Payment/v64/payments"
77+
)
78+
79+
def test_pal_url_no_live_endpoint_prefix_live_platform(self):
80+
self.client.live_endpoint_prefix = None
81+
url = self.adyen.client._determine_api_url(
82+
"live", "Payment", "payments"
83+
)
84+
self.assertEqual(
85+
url,
86+
"https://pal-live.adyen.com/pal/servlet/Payment/v64/payments"
87+
)
88+
89+
def test_pal_url_no_live_endpoint_prefix_test_platform(self):
90+
self.client.live_endpoint_prefix = None
91+
url = self.adyen.client._determine_api_url(
92+
"test", "Payment", "payments"
93+
)
94+
self.assertEqual(
95+
url,
96+
"https://pal-test.adyen.com/pal/servlet/Payment/v64/payments"
97+
)
98+
99+
def test_binlookup_url_no_live_endpoint_prefix_test_platform(self):
100+
self.client.live_endpoint_prefix = None
101+
url = self.adyen.client._determine_api_url(
102+
"test", "BinLookup", "get3dsAvailability"
103+
)
104+
self.assertEqual(
105+
url,
106+
("https://pal-test.adyen.com/pal/servlet/"
107+
"BinLookup/v50/get3dsAvailability")
108+
)

0 commit comments

Comments
 (0)