Skip to content

Commit ce3dff7

Browse files
Merge pull request #76 from Adyen/develop
Release 2.1.0
2 parents 9bf9188 + b69c38e commit ce3dff7

File tree

7 files changed

+254
-24
lines changed

7 files changed

+254
-24
lines changed

Adyen/client.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self, username=None, password=None, xapikey=None,
7171
store_payout_username=None, store_payout_password=None,
7272
platform="test", merchant_account=None,
7373
merchant_specific_url=None, skin_code=None,
74-
hmac=None, app_name=None,
74+
hmac=None, app_name="",
7575
http_force=None, live_endpoint_prefix=None):
7676
self.username = username
7777
self.password = password
@@ -222,40 +222,46 @@ def call_api(self, request_data, service, action, idempotency=False,
222222

223223
# username at self object has highest priority. fallback to root module
224224
# and ensure that it is set.
225+
xapikey = None
225226
if self.xapikey:
226227
xapikey = self.xapikey
227228
elif 'xapikey' in kwargs:
228229
xapikey = kwargs.pop("xapikey")
229230

231+
username = None
230232
if self.username:
231233
username = self.username
232234
elif 'username' in kwargs:
233235
username = kwargs.pop("username")
234-
elif service == "Payout":
236+
if service == "Payout":
235237
if any(substring in action for substring in
236238
["store", "submit"]):
237239
username = self._store_payout_username(**kwargs)
238240
else:
239241
username = self._review_payout_username(**kwargs)
240-
if not username:
242+
243+
if not username and not xapikey:
241244
errorstring = """Please set your webservice username.
242245
You can do this by running
243246
'Adyen.username = 'Your username'"""
244247
raise AdyenInvalidRequestError(errorstring)
245248
# password at self object has highest priority.
246249
# fallback to root module
247250
# and ensure that it is set.
248-
if self.password:
251+
252+
password = None
253+
if self.password and not xapikey:
249254
password = self.password
250255
elif 'password' in kwargs:
251256
password = kwargs.pop("password")
252-
elif service == "Payout":
257+
if service == "Payout":
253258
if any(substring in action for substring in
254259
["store", "submit"]):
255260
password = self._store_payout_pass(**kwargs)
256261
else:
257262
password = self._review_payout_pass(**kwargs)
258-
if not password:
263+
264+
if not password and not xapikey:
259265
errorstring = """Please set your webservice password.
260266
You can do this by running
261267
'Adyen.password = 'Your password'"""

Adyen/httpclient.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def _pycurl_post(self,
6060
data=None,
6161
username="",
6262
password="",
63+
xapikey="",
6364
headers={},
6465
timeout=30):
6566
"""This function will POST to the url endpoint using pycurl. returning
@@ -77,6 +78,8 @@ def _pycurl_post(self,
7778
as part of password.
7879
password (str, optional): Password for basic auth. Must be included
7980
as part of username.
81+
xapikey (str, optional): Adyen API key. Will be used for auth
82+
if username and password are absent.
8083
headers (dict, optional): Key/Value pairs of headers to include
8184
timeout (int, optional): Default 30. Timeout for the request.
8285
@@ -102,6 +105,11 @@ def _pycurl_post(self,
102105
# request can be identified as coming from the Adyen Python library.
103106
headers['User-Agent'] = self.user_agent
104107

108+
if username and password:
109+
curl.setopt(curl.USERPWD, '%s:%s' % (username, password))
110+
elif xapikey:
111+
headers["X-API-KEY"] = xapikey
112+
105113
# Convert the header dict to formatted array as pycurl needs.
106114
if sys.version_info[0] >= 3:
107115
header_list = ["%s:%s" % (k, v) for k, v in headers.items()]
@@ -120,9 +128,6 @@ def _pycurl_post(self,
120128
raw_request = json_lib.dumps(json) if json else urlencode(data)
121129
curl.setopt(curl.POSTFIELDS, raw_request)
122130

123-
if username and password:
124-
curl.setopt(curl.USERPWD, '%s:%s' % (username, password))
125-
126131
curl.setopt(curl.TIMEOUT, timeout)
127132
curl.perform()
128133

@@ -143,7 +148,7 @@ def _requests_post(self, url,
143148
username="",
144149
password="",
145150
xapikey="",
146-
headers=None,
151+
headers={},
147152
timeout=30):
148153
"""This function will POST to the url endpoint using requests.
149154
Returning an AdyenResult object on 200 HTTP response.
@@ -160,6 +165,8 @@ def _requests_post(self, url,
160165
as part of password.
161166
password (str, optional): Password for basic auth. Must be included
162167
as part of username.
168+
xapikey (str, optional): Adyen API key. Will be used for auth
169+
if username and password are absent.
163170
headers (dict, optional): Key/Value pairs of headers to include
164171
timeout (int, optional): Default 30. Timeout for the request.
165172
@@ -169,8 +176,6 @@ def _requests_post(self, url,
169176
int: HTTP status code, eg 200,404,401
170177
dict: Key/Value pairs of the headers received.
171178
"""
172-
if headers is None:
173-
headers = {}
174179

175180
# Adding basic auth if username and password provided.
176181
auth = None
@@ -194,11 +199,12 @@ def _requests_post(self, url,
194199
return request.text, message, request.status_code, request.headers
195200

196201
def _urllib_post(self, url,
197-
json="",
198-
data="",
202+
json=None,
203+
data=None,
199204
username="",
200205
password="",
201-
headers=None,
206+
xapikey="",
207+
headers={},
202208
timeout=30):
203209

204210
"""This function will POST to the url endpoint using urllib2. returning
@@ -216,6 +222,8 @@ def _urllib_post(self, url,
216222
uncluded as part of password.
217223
password (str, optional): Password for basic auth. Must be
218224
included as part of username.
225+
xapikey (str, optional): Adyen API key. Will be used for auth
226+
if username and password are absent.
219227
headers (dict, optional): Key/Value pairs of headers to include
220228
timeout (int, optional): Default 30. Timeout for the request.
221229
@@ -225,8 +233,6 @@ def _urllib_post(self, url,
225233
int: HTTP status code, eg 200,404,401
226234
dict: Key/Value pairs of the headers received.
227235
"""
228-
if headers is None:
229-
headers = {}
230236

231237
# Store regular dict to return later:
232238
raw_store = json
@@ -258,6 +264,8 @@ def _urllib_post(self, url,
258264
replace('\n', '')
259265
url_request.add_header("Authorization",
260266
"Basic %s" % basic_authstring)
267+
elif xapikey:
268+
headers["X-API-KEY"] = xapikey
261269

262270
# Adding the headers to the request.
263271
for key, value in headers.items():
@@ -302,6 +310,8 @@ def request(self, url,
302310
uncluded as part of password.
303311
password (str, optional): Password for basic auth. Must be
304312
included as part of username.
313+
xapikey (str, optional): Adyen API key. Will be used for auth
314+
if username and password are absent.
305315
headers (dict, optional): Key/Value pairs of headers to include
306316
Returns:
307317
str: Raw request placed

Adyen/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com"
55
ENDPOINT_CHECKOUT_LIVE_SUFFIX = "https://{}-checkout-live" \
66
".adyenpayments.com/checkout"
7-
API_CHECKOUT_VERSION = "v41"
7+
API_CHECKOUT_VERSION = "v49"
88
API_CHECKOUT_UTILITY_VERSION = "v1"
99
API_RECURRING_VERSION = "v25"
10-
API_PAYMENT_VERSION = "v40"
10+
API_PAYMENT_VERSION = "v49"
1111
API_PAYOUT_VERSION = "v30"
12-
LIB_VERSION = "2.0.0"
12+
LIB_VERSION = "2.1.0"
1313
LIB_NAME = "adyen-python-api-library"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name='Adyen',
55
packages=['Adyen'],
6-
version='2.0.0',
6+
version='2.1.0',
77
maintainer='Adyen',
88
maintainer_email='[email protected]',
99
description='Adyen Python Api',

test/BaseTest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import mock
1+
2+
try:
3+
import mock
4+
except Exception:
5+
from unittest import mock
26
import json
37
from Adyen import httpclient
48

test/DetermineEndpointTest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ def test_checkout_api_url_custom(self):
1717
url = self.adyen.client._determine_checkout_url("live", "payments")
1818
self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
1919
self.assertEqual(url, "https://1797a841fbb37ca7-AdyenDemo-checkout-"
20-
"live.adyenpayments.com/checkout/v41/payments")
20+
"live.adyenpayments.com/checkout/v49/payments")
2121

2222
def test_checkout_api_url(self):
2323
self.client.live_endpoint_prefix = None
2424
url = self.adyen.client._determine_checkout_url("test",
2525
"paymentsDetails")
2626
self.assertEqual(url, "https://checkout-test.adyen.com"
27-
"/v41/payments/details")
27+
"/v49/payments/details")
2828

2929
def test_payments_invalid_platform(self):
3030

0 commit comments

Comments
 (0)