Skip to content

Commit c397486

Browse files
committed
Improve settings and client
1 parent f3627f7 commit c397486

File tree

4 files changed

+34
-35
lines changed

4 files changed

+34
-35
lines changed

Adyen/client.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, username=None, password=None, xapikey=None,
7272
platform="test", merchant_account=None,
7373
merchant_specific_url=None, skin_code=None,
7474
hmac=None, app_name=None,
75-
http_force=None):
75+
http_force=None, live_endpoint_prefix=None):
7676
self.username = username
7777
self.password = password
7878
self.xapikey = xapikey
@@ -91,6 +91,7 @@ def __init__(self, username=None, password=None, xapikey=None,
9191
self.USER_AGENT_SUFFIX = "adyen-python-api-library/"
9292
self.http_init = False
9393
self.http_force = http_force
94+
self.live_endpoint_prefix = live_endpoint_prefix
9495

9596
def _determine_api_url(self, platform, service, action):
9697
"""This returns the Adyen API endpoint based on the provided platform,
@@ -105,7 +106,7 @@ def _determine_api_url(self, platform, service, action):
105106
if service == "Recurring":
106107
api_version = settings.API_RECURRING_VERSION
107108
else:
108-
api_version = settings.API_VERSION
109+
api_version = settings.API_PAYOUT_VERSION
109110
return '/'.join([base_uri, service, api_version, action])
110111

111112
def _determine_hpp_url(self, platform, action):
@@ -122,8 +123,7 @@ def _determine_hpp_url(self, platform, action):
122123
result = '/'.join([base_uri, service])
123124
return result
124125

125-
def _determine_checkout_url(self, platform, service, action,
126-
live_endpoint_prefix=None):
126+
def _determine_checkout_url(self, platform, service, action):
127127
"""This returns the Adyen API endpoint based on the provided platform,
128128
service and action.
129129
@@ -132,18 +132,18 @@ def _determine_checkout_url(self, platform, service, action,
132132
service (str): API service to place request through.
133133
action (str): the API action to perform.
134134
"""
135-
base_uri = settings.BASE_CHECKOUT_URL.format(platform)
136-
api_version = settings.CHECKOUT_API_VERSION
137-
if live_endpoint_prefix is not None:
138-
base_uri = settings.ENDPOINT_PROTOCOL + live_endpoint_prefix \
139-
+ settings.CHECKOUT_URL_LIVE_SUFFIX
135+
base_uri = settings.ENDPOINT_CHECKOUT_URL.format(platform)
136+
api_version = settings.API_CHECKOUT_VERSION
137+
if self.live_endpoint_prefix is not None:
138+
base_uri = settings.ENDPOINT_PROTOCOL + self.live_endpoint_prefix \
139+
+ settings.ENDPOINT_CHECKOUT_LIVE_SUFFIX
140140

141141
if action == "paymentsDetails":
142142
action = "payments/details"
143143
if action == "paymentsResult":
144144
action = "payment/result"
145145
if action == "originKeys":
146-
api_version = settings.CHECKOUT_UTILITY_API_VERSION
146+
api_version = settings.API_CHECKOUT_UTILITY_VERSION
147147

148148
return '/'.join([base_uri, api_version, action])
149149

@@ -216,47 +216,47 @@ def call_api(self, request_data, service, action, idempotency=False,
216216

217217
# username at self object has highest priority. fallback to root module
218218
# and ensure that it is set.
219+
if self.xapikey:
220+
xapikey = self.xapikey
221+
elif 'xapikey' in kwargs:
222+
xapikey = kwargs.pop("xapikey")
223+
219224
if self.username:
220225
username = self.username
221226
elif 'username' in kwargs:
222227
username = kwargs.pop("username")
223228
elif service == "Payout":
224-
if any(substring in action for substring in ["store", "submit"]):
229+
if any(substring in action for substring in
230+
["store", "submit"]):
225231
username = self._store_payout_username(**kwargs)
226232
else:
227233
username = self._review_payout_username(**kwargs)
228234
if not username:
229235
errorstring = """Please set your webservice username.
230-
You can do this by running 'Adyen.username = 'Your username'"""
236+
You can do this by running
237+
'Adyen.username = 'Your username'"""
231238
raise AdyenInvalidRequestError(errorstring)
232-
233-
# password at self object has highest priority. fallback to root module
234-
# and ensure that it is set.
239+
# password at self object has highest priority.
240+
# fallback to root module
241+
# and ensure that it is set.
235242
if self.password:
236243
password = self.password
237244
elif 'password' in kwargs:
238245
password = kwargs.pop("password")
239246
elif service == "Payout":
240-
if any(substring in action for substring in ["store", "submit"]):
247+
if any(substring in action for substring in
248+
["store", "submit"]):
241249
password = self._store_payout_pass(**kwargs)
242250
else:
243251
password = self._review_payout_pass(**kwargs)
244252
if not password:
245253
errorstring = """Please set your webservice password.
246-
You can do this by running 'Adyen.password = 'Your password'"""
254+
You can do this by running
255+
'Adyen.password = 'Your password'"""
247256
raise AdyenInvalidRequestError(errorstring)
248257
# xapikey at self object has highest priority.
249258
# fallback to root module
250259
# and ensure that it is set.
251-
if self.xapikey:
252-
xapikey = self.xapikey
253-
elif 'xapikey' in kwargs:
254-
xapikey = kwargs.pop("xapikey")
255-
if not xapikey:
256-
errorstring = """Please set your webservice xapikey.
257-
You can do this by running
258-
'Adyen.xapikey = 'Your xapikey'"""
259-
raise AdyenInvalidRequestError(errorstring)
260260

261261
# platform at self object has highest priority. fallback to root module
262262
# and ensure that it is set to either 'live' or 'test'.

Adyen/httpclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def _requests_post(self, url,
147147
timeout=30):
148148
"""This function will POST to the url endpoint using requests.
149149
Returning an AdyenResult object on 200 HTTP response.
150-
Either json or data has to be %sovided.
150+
Either json or data has to be provided.
151151
If username and password are provided, basic auth will be used.
152152
153153

Adyen/settings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
BASE_HPP_URL = "https://{}.adyen.com/hpp"
55
ENDPOINT_LIVE_SUFFIX = "-pal-live.adyenpayments.com"
66
ENDPOINT_PROTOCOL = "https://"
7-
BASE_CHECKOUT_URL = "https://checkout-{}.adyen.com"
8-
CHECKOUT_URL_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout"
9-
CHECKOUT_API_VERSION = "v40"
10-
CHECKOUT_UTILITY_API_VERSION = "v1"
11-
API_VERSION = "v30"
7+
ENDPOINT_CHECKOUT_URL = "https://checkout-{}.adyen.com"
8+
ENDPOINT_CHECKOUT_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout"
9+
API_CHECKOUT_VERSION = "v40"
10+
API_CHECKOUT_UTILITY_VERSION = "v1"
11+
API_PAYOUT_VERSION = "v30"
1212
API_RECURRING_VERSION = "v25"

test/CheckoutTest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,9 @@ def test_checkout_api_url(self):
201201
"/v40/payments/details")
202202

203203
def test_checkout_api_url_custom(self):
204+
self.ady.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
204205
url = self.ady.client._determine_checkout_url("live", "",
205-
"payments",
206-
"1797a841fbb37ca7"
207-
"-AdyenDemo")
206+
"payments")
208207

209208
self.assertEqual(url, "https://1797a841fbb37ca7-AdyenDemo-checkout-"
210209
"live.adyenpayments.com/checkout/v40/payments")

0 commit comments

Comments
 (0)