Skip to content

Commit 91b02d8

Browse files
authored
Merge pull request #46 from thaelathy/alina
Alina
2 parents b69ff6b + d2fb206 commit 91b02d8

File tree

5 files changed

+14
-41
lines changed

5 files changed

+14
-41
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
*.DS_Store
44
*.pypirc
55
releaseguide.md
6-
6+
venv/
7+
.idea/

Adyen/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222

2323
from .httpclient import HTTPClient
2424

25-
username = None
26-
password = None
27-
platform = None
28-
merchant_account = None
29-
merchant_specific_url = None
30-
hmac = None
31-
3225

3326
class Adyen(AdyenBase):
3427
def __init__(self, **kwargs):

Adyen/client.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def __init__(self, username=None, password=None,
7979
self.store_payout_username = store_payout_username
8080
self.store_payout_password = store_payout_password
8181
self.platform = platform
82+
if not self.platform:
83+
self.platform = 'test'
8284
self.merchant_specific_url = merchant_specific_url
8385
self.hmac = hmac
8486
self.merchant_account = merchant_account
@@ -308,9 +310,8 @@ def call_hpp(self, message, action, hmac_key="", **kwargs):
308310

309311
# hmac provided in function has highest priority. fallback to self then
310312
# root module and ensure that it is set.
311-
if hmac_key:
312-
hmac = hmac_key
313-
elif self.hmac:
313+
hmac = hmac_key
314+
if self.hmac:
314315
hmac = self.hmac
315316
elif not hmac:
316317
errorstring = """Please set an hmac with your Adyen.Adyen class instance.
@@ -354,17 +355,14 @@ def call_hpp(self, message, action, hmac_key="", **kwargs):
354355

355356
def hpp_payment(self, request_data, action, hmac_key="", **kwargs):
356357

357-
from . import platform
358-
359358
if not self.http_init:
360359
self.http_client = HTTPClient(self.app_name,
361360
self.USER_AGENT_SUFFIX,
362361
self.LIB_VERSION,
363362
self.http_force)
364363
self.http_init = True
365364

366-
if self.platform:
367-
platform = self.platform
365+
platform = self.platform
368366
if platform.lower() not in ['live', 'test']:
369367
errorstring = " 'platform' must be the value of 'live' or 'test' "
370368
raise ValueError(errorstring)
@@ -477,8 +475,7 @@ def _handle_http_error(self, url, response_obj, status_code, psp_ref,
477475
"""
478476

479477
if status_code == 404:
480-
from . import merchant_specific_url
481-
if url == merchant_specific_url:
478+
if url == self.merchant_specific_url:
482479
erstr = "Received a 404 for url:'{}'. Please ensure that" \
483480
" the custom merchant specific url is correct" \
484481
.format(url)
@@ -510,7 +507,6 @@ def _handle_http_error(self, url, response_obj, status_code, psp_ref,
510507
" if the problem persists"
511508
raise AdyenAPIAuthenticationError(erstr)
512509
elif status_code == 403:
513-
from . import username
514510

515511
if response_obj.get("message") == "Invalid Merchant Account":
516512
erstr = ("You provided the merchant account:'%s' that"
@@ -528,7 +524,7 @@ def _handle_http_error(self, url, response_obj, status_code, psp_ref,
528524
" the PSP reference: %s" % (
529525
response_obj["message"], self.username, psp_ref)
530526

531-
raise AdyenAPIInvalidPermission(erstr, username, psp_ref,
527+
raise AdyenAPIInvalidPermission(erstr, self.username, psp_ref,
532528
raw_request=raw_request,
533529
raw_response=raw_response, url=url,
534530
psp=psp_ref, headers=headers)

Adyen/services.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import absolute_import, division, unicode_literals
22

33
import datetime
4+
5+
from Adyen import AdyenClient
46
from . import validation
57

68

@@ -20,11 +22,11 @@ def __getattr__(self, attr):
2022

2123

2224
class AdyenServiceBase(AdyenBase):
23-
def __init__(self, client=""):
25+
def __init__(self, client=None):
2426
if client:
2527
self.client = client
2628
else:
27-
self.client = AdyenAPIClient()
29+
self.client = AdyenClient()
2830

2931

3032
class AdyenRecurring(AdyenServiceBase):
@@ -39,7 +41,7 @@ class AdyenRecurring(AdyenServiceBase):
3941
use. If not provided, a new API client will be created.
4042
"""
4143

42-
def __init__(self, client=""):
44+
def __init__(self, client=None):
4345
super(AdyenRecurring, self).__init__(client=client)
4446
self.service = "Recurring"
4547

Adyen/util.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,6 @@
88
import binascii
99

1010

11-
def _generate_signing_string(dict_object, hmac_key):
12-
if not isinstance(dict_object, dict):
13-
raise ValueError("Must Provide dictionary object")
14-
15-
def escape_val(val):
16-
if isinstance(val, int):
17-
return val
18-
return val.replace('\\', '\\\\').replace(':', '\\:')
19-
20-
ordered_request = OrderedDict(sorted(dict_object.items(),
21-
key=lambda t: t[0]))
22-
23-
signing_string = ':'.join(
24-
map(escape_val, chain(map(str, ordered_request.keys()),
25-
map(str, ordered_request.values()))))
26-
27-
return signing_string
28-
29-
3011
def generate_hpp_sig(dict_object, hmac_key):
3112
if 'issuerId' in dict_object:
3213
if dict_object['issuerId'] == "":

0 commit comments

Comments
 (0)