Skip to content

Commit a13dc7e

Browse files
committed
fix determine checkout url
1 parent 0aa55af commit a13dc7e

File tree

5 files changed

+26
-33
lines changed

5 files changed

+26
-33
lines changed

Adyen/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,21 @@ def _determine_hpp_url(self, platform, action):
123123
result = '/'.join([base_uri, service])
124124
return result
125125

126-
def _determine_checkout_url(self, platform, service, action):
126+
def _determine_checkout_url(self, platform, action):
127127
"""This returns the Adyen API endpoint based on the provided platform,
128128
service and action.
129129
130130
Args:
131131
platform (str): Adyen platform, ie 'live' or 'test'.
132-
service (str): API service to place request through.
133132
action (str): the API action to perform.
134133
"""
135134
api_version = settings.API_CHECKOUT_VERSION
136-
base_uri = settings.ENDPOINT_CHECKOUT_URL.format(platform)
137-
if self.live_endpoint_prefix is not None and platform == "live":
135+
if platform == "test":
136+
base_uri = settings.ENDPOINT_CHECKOUT_TEST
137+
elif self.live_endpoint_prefix is not None and platform == "live":
138138
base_uri = settings.ENDPOINT_CHECKOUT_LIVE_SUFFIX.format(
139139
self.live_endpoint_prefix)
140-
if self.live_endpoint_prefix is not None and platform == "test":
140+
elif self.live_endpoint_prefix is None and platform == "live":
141141
errorstring = """Please set your live suffix. You can set it
142142
by running 'settings.
143143
ENDPOINT_CHECKOUT_LIVE_SUFFIX = 'Your live suffix'"""
@@ -373,7 +373,7 @@ class instance.
373373
status_code, headers, message)
374374
return adyen_result
375375

376-
def call_checkout_api(self, request_data, service, action, **kwargs):
376+
def call_checkout_api(self, request_data, action, **kwargs):
377377
"""This will call the checkout adyen api. xapi key merchant_account,
378378
and platform are pulled from root module level and or self object.
379379
AdyenResult will be returned on 200 response. Otherwise, an exception
@@ -426,7 +426,7 @@ def call_checkout_api(self, request_data, service, action, **kwargs):
426426
# merchant account and merchant reference to determine uniqueness.
427427
headers = {}
428428

429-
url = self._determine_checkout_url(platform, service, action)
429+
url = self._determine_checkout_url(platform, action)
430430

431431
raw_response, raw_request, status_code, headers = \
432432
self.http_client.request(url, json=request_data,

Adyen/services.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -312,35 +312,29 @@ def payment_methods(self, request="", **kwargs):
312312
'merchantAccount must contain the merchant account'
313313
' when retrieving payment methods.')
314314

315-
return self.client.call_checkout_api(request, self.service,
316-
action, **kwargs)
315+
return self.client.call_checkout_api(request, action, **kwargs)
317316

318317
def payments(self, request="", **kwargs):
319318
action = "payments"
320319
if validation.check_in(request, action):
321-
return self.client.call_checkout_api(request, self.service,
322-
action, **kwargs)
320+
return self.client.call_checkout_api(request, action, **kwargs)
323321

324322
def payments_details(self, request="", **kwargs):
325323
action = "paymentsDetails"
326324
if validation.check_in(request, action):
327-
return self.client.call_checkout_api(request, self.service,
328-
action, **kwargs)
325+
return self.client.call_checkout_api(request, action, **kwargs)
329326

330327
def payment_session(self, request="", **kwargs):
331328
action = "paymentSession"
332329
if validation.check_in(request, action):
333-
return self.client.call_checkout_api(request, self.service,
334-
action, **kwargs)
330+
return self.client.call_checkout_api(request, action, **kwargs)
335331

336332
def payment_result(self, request="", **kwargs):
337333
action = "paymentsResult"
338334
if validation.check_in(request, action):
339-
return self.client.call_checkout_api(request, self.service, action,
340-
**kwargs)
335+
return self.client.call_checkout_api(request, action, **kwargs)
341336

342337
def origin_keys(self, request="", **kwargs):
343338
action = "originKeys"
344339
if validation.check_in(request, action):
345-
return self.client.call_checkout_api(request, self.service,
346-
action, **kwargs)
340+
return self.client.call_checkout_api(request, action, **kwargs)

Adyen/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
BASE_PAL_URL = "https://pal-{}.adyen.com/pal/servlet"
44
BASE_HPP_URL = "https://{}.adyen.com/hpp"
55
ENDPOINT_LIVE_SUFFIX = "-pal-live.adyenpayments.com"
6-
ENDPOINT_CHECKOUT_URL = "https://checkout-{}.adyen.com"
6+
ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com"
77
ENDPOINT_CHECKOUT_LIVE_SUFFIX = "https://{}-checkout-live" \
88
".adyenpayments.com/checkout"
99
API_CHECKOUT_VERSION = "v40"

test/CheckoutUtilityTest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def test_origin_keys_success_mocked(self):
4747
['https://www.your-domain2.com'])
4848

4949
def test_checkout_utility_api_url_custom(self):
50-
url = self.ady.client._determine_checkout_url("test", "",
51-
"originKeys")
50+
url = self.ady.client._determine_checkout_url("test", "originKeys")
5251

5352
self.assertEqual(url, "https://checkout-test.adyen.com/v1/originKeys")

test/DetermineEndpointTest.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ class TestDetermineUrl(unittest.TestCase):
1515

1616
def test_checkout_api_url_custom(self):
1717
self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
18-
url = self.adyen.client._determine_checkout_url("live", "",
19-
"payments")
18+
url = self.adyen.client._determine_checkout_url("live", "payments")
2019
self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
2120
self.assertEqual(url, "https://1797a841fbb37ca7-AdyenDemo-checkout-"
2221
"live.adyenpayments.com/checkout/v40/payments")
2322

23+
def test_checkout_api_url(self):
24+
25+
self.client.live_endpoint_prefix = None
26+
url = self.adyen.client._determine_checkout_url("test",
27+
"paymentsDetails")
28+
self.assertEqual(url, "https://checkout-test.adyen.com"
29+
"/v40/payments/details")
30+
2431
def test_payments_invalid_platform(self):
2532

2633
request = {'amount': {"value": "100000", "currency": "EUR"},
@@ -35,17 +42,10 @@ def test_payments_invalid_platform(self):
3542
}, 'merchantAccount': "YourMerchantAccount",
3643
'returnUrl': "https://your-company.com/..."}
3744

38-
self.client.platform = "test"
45+
self.client.platform = "live"
46+
self.client.live_endpoint_prefix = None
3947
try:
4048
result = self.adyen.checkout.payments(request)
4149
except AdyenEndpointInvalidFormat as error:
4250
print("the error" + str(error.__class__.__name__))
4351
self.assertIsNotNone("dfasdf")
44-
45-
def test_checkout_api_url(self):
46-
47-
self.client.live_endpoint_prefix = None
48-
url = self.adyen.client._determine_checkout_url("test", "",
49-
"paymentsDetails")
50-
self.assertEqual(url, "https://checkout-test.adyen.com"
51-
"/v40/payments/details")

0 commit comments

Comments
 (0)