Skip to content

Commit 264e507

Browse files
committed
Fixes for Python3 version, updated README
1 parent df4524d commit 264e507

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

Adyen/client.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def call_api(self, request_data, service, action, idempotency=False,
200200
from . import username, password, merchant_account, platform
201201
#
202202
if self.http_init == False:
203-
self.http_client = HTTPClient(self.app_name,self.LIB_VERSION,self.USER_AGENT_SUFFIX, self.http_force)
203+
self.http_client = HTTPClient(self.app_name,self.USER_AGENT_SUFFIX,self.LIB_VERSION,self.http_force)
204204
self.http_init = True
205205

206206
#username at self object has highest priority. fallback to root module
@@ -302,7 +302,7 @@ def call_hpp(self, message, action, hmac_key="", **kwargs):
302302
from . import hmac, platform
303303
#
304304
if self.http_init == False:
305-
self.http_client = HTTPClient(self.app_name,self.LIB_VERSION,self.USER_AGENT_SUFFIX, self.http_force)
305+
self.http_client = HTTPClient(self.app_name,self.USER_AGENT_SUFFIX,self.LIB_VERSION,self.http_force)
306306
self.http_init = True
307307

308308
#hmac provided in function has highest priority. fallback to self then
@@ -355,7 +355,7 @@ def hpp_payment(self,request_data, action, hmac_key="", **kwargs):
355355
from . import hmac, platform
356356
#
357357
if self.http_init == False:
358-
self.http_client = HTTPClient(self.app_name,self.LIB_VERSION,self.USER_AGENT_SUFFIX, self.http_force)
358+
self.http_client = HTTPClient(self.app_name,self.USER_AGENT_SUFFIX,self.LIB_VERSION,self.http_force)
359359
self.http_init = True
360360

361361
if self.platform:
@@ -409,24 +409,18 @@ def _handle_response(self, url, raw_response, raw_request, status_code, headers,
409409
response = {}
410410
# If the result can't be parsed into json, most likely is raw html.
411411
# Some response are neither json or raw html, handle them here:
412-
try:
413-
response = json_lib.loads(raw_result)
414-
415-
self._handle_http_error(url, response, status_code,
416-
headers.get('pspReference'), raw_request, raw_response, headers)
417-
except:
418412

419-
response = json_lib.loads(raw_response)
413+
response = json_lib.loads(raw_response)
420414

421-
# Pass raised error to error handler.
422-
self._handle_http_error(url,response,status_code,headers.get('pspReference'),raw_request,raw_response,headers,request_dict)
415+
# Pass raised error to error handler.
416+
self._handle_http_error(url,response,status_code,headers.get('pspReference'),raw_request,raw_response,headers,request_dict)
423417

424-
try:
425-
if response['errorCode']:
426-
return raw_response
427-
except KeyError:
428-
errstr = 'KeyError: errorCode'
429-
pass
418+
try:
419+
if response['errorCode']:
420+
return raw_response
421+
except KeyError:
422+
errstr = 'KeyError: errorCode'
423+
pass
430424
else:
431425
try:
432426
response = json_lib.loads(raw_response)

Adyen/httpclient.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141
# ['raw_response','raw_request','status_code','headers'])
4242

4343
class HTTPClient(object):
44-
def __init__(self,app_name,USER_AGENT_SUFFIX,LIB_VERSION, force_request = None):
44+
def __init__(self,app_name,USER_AGENT_SUFFIX,LIB_VERSION,force_request = None):
4545
#Check if requests already available, default to urllib
4646
# self.app_name = app_name
4747
# self.LIB_VERSION = LIB_VERSION
4848
# self.USER_AGENT_SUFFIX = USER_AGENT_SUFFIX
4949
self.user_agent = app_name + " " + USER_AGENT_SUFFIX + LIB_VERSION
50-
5150
if not force_request:
5251
if requests:
5352
self.request = self._requests_post
@@ -120,7 +119,6 @@ def handle_header(header_line):
120119
headers['User-Agent'] = self.user_agent
121120

122121
# Convert the header dict to formatted array as pycurl needs.
123-
# header_list = ["%s:%s" % (k,v) for k,v in headers.iteritems()]
124122
if sys.version_info[0] >= 3:
125123
header_list = ["%s:%s" % (k, v) for k, v in headers.items()]
126124
else:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ payments within any Python application.
88

99
## Requirements
1010

11-
- Python 2.7
11+
- Python 2.7 or 3.6
1212
- Packages: requests or pycurl ( optional )
1313
- Adyen account. If you don't have this you can request it here: https://www.adyen.com/home/discover/test-account-signup#form
1414

test/BaseTest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ def create_client_from_file(self, status, request, filename = None):
1111
if filename:
1212
with open(filename) as data_file:
1313
data = json.load(data_file)
14-
strjson = open(filename).read()
14+
st = open(filename)
15+
strjson = st.read()
1516
else:
1617
data = ""
18+
st = ""
1719
strjson = ""
1820

1921
self.ady.client.http_client = httpclient.HTTPClient
@@ -22,4 +24,7 @@ def create_client_from_file(self, status, request, filename = None):
2224

2325
# self.ady.client.http_client.request = mock.MagicMock(return_value=[strjson, request, status, {'User-Agent': 'appname adyen-python-api-library/1.0.0'}])
2426
mockclient = self.ady.client
27+
if st:
28+
st.close()
2529
return mockclient
30+

test/PaymentTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_authorise_success_mocked(self):
3939
fraudCheckResult = result.message['fraudResult']['results'][0]['FraudCheckResult']
4040
self.assertEqual("CardChunkUsage", fraudCheckResult['name'])
4141
self.assertEqual(8, fraudCheckResult['accountScore'])
42-
self.assertEquals(2, fraudCheckResult['checkId'])
42+
self.assertEqual(2, fraudCheckResult['checkId'])
4343

4444
def test_authorise_error010_mocked(self):
4545
request = {}

0 commit comments

Comments
 (0)