Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3919941
Removed direct logging from library and logger.
Jun 27, 2017
b42eefd
Imported future, and updated import statements where not fitting yet
Jun 29, 2017
fe76347
PW-214: Added first testing cases, using mocked request
Aleffio Jul 5, 2017
10d0be2
PW-214: Added first testing cases, using mocked request
Aleffio Jul 5, 2017
1d600f5
Added http_force mechanism to force the use of one of the three libra…
Aleffio Jul 6, 2017
9722e12
Fixed the urllib section where the error code was not retrieved properly
Aleffio Jul 6, 2017
6cb980e
Fixed 403 error message not showing properly
Aleffio Jul 6, 2017
eda041b
PW-214: Added ModificationTest
Aleffio Jul 6, 2017
13b4d86
PW-214: Added DirectoryLookupTest and RecurringTest, minor cleaning o…
Aleffio Jul 6, 2017
f061c04
Added http_force mechanism to hpp call
Aleffio Jul 6, 2017
9a0b2cc
Removed "shipBeforeDate" from DirectoryLookUp validation since it is …
Aleffio Jul 6, 2017
6b41323
updated .travis.yml for initial tests
Aleffio Jul 7, 2017
dfe4715
updated .travis.yml for initial tests
Aleffio Jul 7, 2017
1165839
updated .travis.yml for initial tests
Aleffio Jul 7, 2017
a953a06
updated .travis.yml for initial tests
Aleffio Jul 7, 2017
1d40018
updated .travis.yml for initial tests
Aleffio Jul 7, 2017
fdce9a6
updated .travis.yml for different branch
Aleffio Jul 10, 2017
b940836
Merge pull request #23 from Adyen/Tests-LibChanges
rikterbeek Jul 10, 2017
0d65fb2
updated README with travis.ci images
Aleffio Jul 10, 2017
98b2e49
Merge pull request #24 from Adyen/Tests-LibChanges
rikterbeek Jul 10, 2017
81bad6c
Make Adyen.httpclient module Python 3 compatible (#25)
woochica Jul 13, 2017
294370b
Make Adyen.util module Python 3 compatible (#26)
woochica Jul 13, 2017
df4524d
Fixes for Python3 version, updated .travis with Python3
Aleffio Jul 13, 2017
264e507
Fixes for Python3 version, updated README
Aleffio Jul 14, 2017
d62d979
Merge pull request #29 from Adyen/Tests-LibChanges
rikterbeek Jul 14, 2017
95f1291
Added Documentation link to README
Aleffio Jul 17, 2017
f25f75c
Added Documentation link to README
Aleffio Jul 17, 2017
fdeae6f
updated .gitignore
Aleffio Jul 17, 2017
f8eee09
Added setup files for pip
Aleffio Jul 17, 2017
6e824f9
Merge pull request #30 from Adyen/Tests-LibChanges
rikterbeek Jul 17, 2017
b76084f
Updated client.py with the 1.1.0 version
Aleffio Jul 17, 2017
eb66e08
Merge pull request #31 from Adyen/Tests-LibChanges
rikterbeek Jul 17, 2017
abfbc9f
Update README
Aleffio Jul 17, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
*.log
*.DS_Store
*.pypirc
MANIFEST.in
releaseguide.md
setup.cfg
setup.py

16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
sudo: true
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
cache:
pip: false
- "3.6"
cache: pip
install:
- pip install requests
- pip install pycurl
- pip install mock
- pip install coveralls
script:
- python runtests.py
- coverage run -m unittest discover -s test -p '*Test.py'
after_success:
coveralls
8 changes: 5 additions & 3 deletions Adyen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/python

from __future__ import absolute_import, division, print_function, unicode_literals

from . import util
from .util import generate_hpp_sig
from .exceptions import (
Expand All @@ -16,9 +19,9 @@
AdyenPayment,
AdyenHPP)

from .httpclient import HTTPClient

import datetime
from adyen_log import logname,getlogger
logger = getlogger()

username = ""
password = ""
Expand All @@ -34,7 +37,6 @@ def __init__(self, **kwargs):
self.hpp = AdyenHPP(client=self.client)
self.recurring = AdyenRecurring(client=self.client)


_base_adyen_obj = Adyen()
recurring = _base_adyen_obj.recurring
hpp = _base_adyen_obj.hpp
Expand Down
28 changes: 0 additions & 28 deletions Adyen/adyen_log.py

This file was deleted.

89 changes: 31 additions & 58 deletions Adyen/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/python

from __future__ import absolute_import, division, print_function, unicode_literals

import json as json_lib
import re

Expand All @@ -15,10 +18,6 @@

import datetime
from datetime import timedelta
import logging
from adyen_log import logname,getlogger
logger = logging.getLogger(logname())


HMAC_TEST_url = "https://ca-test.adyen.com/ca/ca/skin/checkhmac.shtml"

Expand Down Expand Up @@ -77,7 +76,7 @@ class AdyenClient(object):
def __init__(self, username=None, password=None, review_payout_username=None,
review_payout_password=None, store_payout_username=None,
store_payout_password=None, platform=None,
merchant_account=None, merchant_specific_url=None, skin_code=None, hmac=None,app_name=None,create_log=None):
merchant_account=None, merchant_specific_url=None, skin_code=None, hmac=None, app_name=None, http_force = None):
self.username = username
self.password = password
self.review_payout_username = review_payout_username
Expand All @@ -91,10 +90,10 @@ def __init__(self, username=None, password=None, review_payout_username=None,
self.skin_code = skin_code
self.psp_list = []
self.app_name = app_name
self.create_log = create_log
self.LIB_VERSION = "1.0.0";
self.LIB_VERSION = "1.1.0";
self.USER_AGENT_SUFFIX = "adyen-python-api-library/";
self.http_init = False
self.http_force = http_force

def _determine_api_url(self, platform, service, action):
"""This returns the Adyen API endpoint based on the provided platform,
Expand Down Expand Up @@ -123,7 +122,7 @@ def _determine_hpp_url(self, platform, action):
return result

def _review_payout_username(self,**kwargs):
from Adyen import review_payout_username
from . import review_payout_username
if 'username' in kwargs:
review_payout_username = kwargs['username']
elif self.review_payout_username:
Expand All @@ -132,13 +131,12 @@ def _review_payout_username(self,**kwargs):
errorstring = """AdyenInvalidRequestError: Please set your review payout
webservice username. You can do this by running
'Adyen.review_payout_username = 'Your payout username' """
# logger.error(errorstring)
raise AdyenInvalidRequestError(errorstring)

return review_payout_username

def _review_payout_pass(self,**kwargs):
from Adyen import review_payout_password
from . import review_payout_password
if 'password' in kwargs:
review_payout_password = kwargs["password"]
elif self.review_payout_password:
Expand All @@ -147,13 +145,12 @@ def _review_payout_pass(self,**kwargs):
errorstring = """AdyenInvalidRequestError: Please set your review payout
webservice password. You can do this by running
'Adyen.review_payout_password = 'Your payout password'"""
# logger.error(errorstring)
raise AdyenInvalidRequestError(errorstring)

return review_payout_password

def _store_payout_username(self,**kwargs):
from Adyen import store_payout_username
from . import store_payout_username
if 'username' in kwargs:
store_payout_username = kwargs['username']
elif self.store_payout_username:
Expand All @@ -162,13 +159,12 @@ def _store_payout_username(self,**kwargs):
errorstring = """AdyenInvalidRequestError: Please set your store payout
webservice username. You can do this by running
'Adyen.store_payout_username = 'Your payout username'"""
# logger.error(errorstring)
raise AdyenInvalidRequestError(errorstring)

return store_payout_username

def _store_payout_pass(self,**kwargs):
from Adyen import store_payout_password
from . import store_payout_password
if 'password' in kwargs:
store_payout_password = kwargs["password"]
elif self.store_payout_password:
Expand All @@ -177,7 +173,6 @@ def _store_payout_pass(self,**kwargs):
errorstring = """AdyenInvalidRequestError: Please set your store payout
webservice password. You can do this by running
'Adyen.store_payout_password = 'Your payout password'"""
# logger.error(errorstring)
raise AdyenInvalidRequestError(errorstring)

return store_payout_password
Expand All @@ -202,10 +197,10 @@ def call_api(self, request_data, service, action, idempotency=False,
AdyenResult: The AdyenResult is returned when a request was
succesful.
"""
from Adyen import username, password, merchant_account, platform

from . import username, password, merchant_account, platform
#
if self.http_init == False:
self.http_client = HTTPClient(self.app_name,self.LIB_VERSION,self.USER_AGENT_SUFFIX)
self.http_client = HTTPClient(self.app_name,self.USER_AGENT_SUFFIX,self.LIB_VERSION,self.http_force)
self.http_init = True

#username at self object has highest priority. fallback to root module
Expand All @@ -222,7 +217,6 @@ def call_api(self, request_data, service, action, idempotency=False,
if not username:
errorstring = """AdyenInvalidRequestError: Please set your webservice username."
You can do this by running 'Adyen.username = 'Your username'"""
# logger.error(errorstring)
raise AdyenInvalidRequestError(errorstring)
#Ensure that username has been removed so as not to be passed to adyen.
if 'username' in kwargs:
Expand All @@ -242,7 +236,6 @@ def call_api(self, request_data, service, action, idempotency=False,
if not password:
errorstring = """AdyenInvalidRequestError: Please set your webservice password.
You can do this by running 'Adyen.password = 'Your password'"""
# logger.error(errorstring)
raise AdyenInvalidRequestError(errorstring)
#Ensure that password has been removed so as not to be passed to adyen.
if 'password' in kwargs:
Expand Down Expand Up @@ -306,10 +299,10 @@ def call_hpp(self, message, action, hmac_key="", **kwargs):
AdyenResult: The AdyenResult is returned when a request was
succesful.
"""
from Adyen import hmac, platform

from . import hmac, platform
#
if self.http_init == False:
self.http_client = HTTPClient(self.app_name,self.LIB_VERSION,self.USER_AGENT_SUFFIX)
self.http_client = HTTPClient(self.app_name,self.USER_AGENT_SUFFIX,self.LIB_VERSION,self.http_force)
self.http_init = True

#hmac provided in function has highest priority. fallback to self then
Expand All @@ -324,7 +317,6 @@ def call_hpp(self, message, action, hmac_key="", **kwargs):
parameter in the function call ie.
'Adyen.hpp.directory_lookup(hmac=\"!WR#F@...\"'. Please reach
out to support@Adyen.com if the issue persists."""
# logger.error(errorstring)
raise AdyenInvalidRequestError(errorstring)

#platform provided in self has highest priority, fallback to root module
Expand All @@ -333,11 +325,9 @@ def call_hpp(self, message, action, hmac_key="", **kwargs):
platform = self.platform
if platform.lower() not in ['live','test']:
errorstring = " 'platform' must be the value of 'live' or 'test' "
# logger.error(errorstring)
raise ValueError(errorstring)
elif not isinstance(platform, str):
errorstring = "'platform' must be type string"
# logger.error(errorstring)
raise TypeError(errorstring)

if 'skinCode' not in message:
Expand All @@ -362,21 +352,19 @@ def call_hpp(self, message, action, hmac_key="", **kwargs):

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

from Adyen import hmac, platform

from . import hmac, platform
#
if self.http_init == False:
self.http_client = HTTPClient(self.app_name,self.LIB_VERSION,self.USER_AGENT_SUFFIX)
self.http_client = HTTPClient(self.app_name,self.USER_AGENT_SUFFIX,self.LIB_VERSION,self.http_force)
self.http_init = True

if self.platform:
platform = self.platform
if platform.lower() not in ['live','test']:
errorstring = " 'platform' must be the value of 'live' or 'test' "
# logger.error(errorstring)
raise ValueError(errorstring)
elif not isinstance(platform, str):
errorstring = "'platform' must be type string"
# logger.error(errorstring)
raise TypeError(errorstring)

if 'skinCode' not in request_data:
Expand Down Expand Up @@ -421,25 +409,18 @@ def _handle_response(self, url, raw_response, raw_request, status_code, headers,
response = {}
# If the result can't be parsed into json, most likely is raw html.
# Some response are neither json or raw html, handle them here:
try:
response = json_lib.loads(raw_result)

self._handle_http_error(url, response, status_code,
headers.get('pspReference'), raw_request, raw_response, headers)
except:

response = json_lib.loads(raw_response)
response = json_lib.loads(raw_response)

# Pass raised error to error handler.
self._handle_http_error(url,response,status_code,headers.get('pspReference'),raw_request,raw_response,headers,request_dict)
# Pass raised error to error handler.
self._handle_http_error(url,response,status_code,headers.get('pspReference'),raw_request,raw_response,headers,request_dict)

try:
if response['errorCode']:
return raw_response
except KeyError:
errstr = 'KeyError: errorCode'
# logger.error('Key Error: errorCode')
pass
try:
if response['errorCode']:
return raw_response
except KeyError:
errstr = 'KeyError: errorCode'
pass
else:
try:
response = json_lib.loads(raw_response)
Expand All @@ -465,8 +446,6 @@ def _handle_response(self, url, raw_response, raw_request, status_code, headers,
raw_response=raw_response,
url=url

# logger.error(errorstring)

raise AdyenInvalidRequestError(errorstring)

def _handle_http_error(self, url, response_obj, status_code, psp_ref,
Expand All @@ -489,14 +468,12 @@ def _handle_http_error(self, url, response_obj, status_code, psp_ref,
"""

if status_code == 404:
from Adyen import merchant_specific_url
from . import merchant_specific_url
if url == merchant_specific_url:
erstr = "Received a 404 for url:'{}'. Please ensure that the custom merchant specific url is correct".format(url)
# logger.error(erstr)
raise AdyenAPICommunicationError(erstr)
else:
erstr = "Unexpected error while communicating with Adyen. Please reach out to support@adyen.com if the problem persists"
# logger.error(erstr)
raise AdyenAPICommunicationError(erstr,
raw_request=raw_request,
raw_response=raw_response,
Expand All @@ -506,26 +483,22 @@ def _handle_http_error(self, url, response_obj, status_code, psp_ref,
elif status_code in [400, 422]:
erstr = "Received validation error with errorCode: %s, message: %s, HTTP Code: %s. Please verify the values provided. Please reach out to support@adyen.com if the problem persists, providing the PSP reference: %s" % (response_obj["errorCode"],response_obj["message"], status_code, psp_ref)

# logger.error(erstr)

raise ValueError(erstr)
elif status_code == 401:
erstr = "Unable to authenticate with Adyen's Servers. Please verify the credentials set with the Adyen base class. Please reach out to your Adyen Admin if the problem persists"
# logger.error(erstr)
raise ValueError(erstr)
elif status_code == 403:
from Adyen import username
from . import username

ma = raw_request['merchantAccount']

if response_obj.get("message")=="Invalid Merchant Account":
erstr = ("You provided the merchant account:'%s' that doesn't exist or you don't have access to it.\n"
"Please verify the merchant account provided. \n"
"Reach out to support@adyen.com if the issue persists") % raw_request['merchantAccount']
# logger.error(erstr)
raise AdyenAPIInvalidPermission(erstr)

erstr = "Unable to perform the requested action. message: %s. If you think your webservice user: %s might not have the necessary permissions to perform this request. Please reach out to support@adyen.com, providing the PSP reference: %s" % response_obj["message"],self.username,psp_ref
erstr = "Unable to perform the requested action. message: %s. If you think your webservice user: %s might not have the necessary permissions to perform this request. Please reach out to support@adyen.com, providing the PSP reference: %s" % (response_obj["message"],self.username,psp_ref)

raise AdyenAPIInvalidPermission(erstr,username,psp_ref,raw_request=raw_request,raw_response=raw_response,url=url,psp=psp_ref,headers=headers)
elif status_code == 422:
Expand Down
4 changes: 1 addition & 3 deletions Adyen/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import logging
from adyen_log import logname,getlogger
logger = logging.getLogger(logname())
from __future__ import absolute_import, division, print_function, unicode_literals

class AdyenError(Exception):

Expand Down
Loading