Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 7 additions & 10 deletions Adyen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, username=None, password=None, xapikey=None,
store_payout_username=None, store_payout_password=None,
platform="test", merchant_account=None,
merchant_specific_url=None, skin_code=None,
hmac=None, app_name="",
hmac=None,
http_force=None, live_endpoint_prefix=None):
self.username = username
self.password = password
Expand All @@ -86,7 +86,6 @@ def __init__(self, username=None, password=None, xapikey=None,
self.merchant_account = merchant_account
self.skin_code = skin_code
self.psp_list = []
self.app_name = app_name
self.LIB_VERSION = settings.LIB_VERSION
self.USER_AGENT_SUFFIX = settings.LIB_NAME + "/"
self.http_init = False
Expand All @@ -108,6 +107,8 @@ def _determine_api_url(platform, service, action):
api_version = settings.API_RECURRING_VERSION
elif service == "Payout":
api_version = settings.API_PAYOUT_VERSION
elif service == "BinLookup":
api_version = settings.API_BIN_LOOKUP_VERSION
else:
api_version = settings.API_PAYMENT_VERSION
return '/'.join([base_uri, service, api_version, action])
Expand Down Expand Up @@ -219,8 +220,7 @@ def call_api(self, request_data, service, action, idempotency=False,
succesful.
"""
if not self.http_init:
self.http_client = HTTPClient(self.app_name,
self.USER_AGENT_SUFFIX,
self.http_client = HTTPClient(self.USER_AGENT_SUFFIX,
self.LIB_VERSION,
self.http_force)
self.http_init = True
Expand Down Expand Up @@ -358,8 +358,7 @@ def call_hpp(self, message, action, hmac_key="", **kwargs):
:param hmac_key:
"""
if not self.http_init:
self.http_client = HTTPClient(self.app_name,
self.USER_AGENT_SUFFIX,
self.http_client = HTTPClient(self.USER_AGENT_SUFFIX,
self.LIB_VERSION,
self.http_force)
self.http_init = True
Expand Down Expand Up @@ -423,8 +422,7 @@ def call_checkout_api(self, request_data, action, **kwargs):
action (str): The specific action of the API service to be called
"""
if not self.http_init:
self.http_client = HTTPClient(self.app_name,
self.USER_AGENT_SUFFIX,
self.http_client = HTTPClient(self.USER_AGENT_SUFFIX,
self.LIB_VERSION,
self.http_force)
self.http_init = True
Expand Down Expand Up @@ -495,8 +493,7 @@ def call_checkout_api(self, request_data, action, **kwargs):
def hpp_payment(self, request_data, action, hmac_key="", **kwargs):

if not self.http_init:
self.http_client = HTTPClient(self.app_name,
self.USER_AGENT_SUFFIX,
self.http_client = HTTPClient(self.USER_AGENT_SUFFIX,
self.LIB_VERSION,
self.http_force)
self.http_init = True
Expand Down
7 changes: 2 additions & 5 deletions Adyen/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@


class HTTPClient(object):
def __init__(self, app_name, user_agent_suffix,
lib_version, force_request=None):
def __init__(self, user_agent_suffix, lib_version, force_request=None):
# Check if requests already available, default to urllib
self.user_agent = app_name + " " + user_agent_suffix + lib_version
# In case the app_name is empty
self.user_agent = self.user_agent.strip()
self.user_agent = user_agent_suffix + lib_version
if not force_request:
if requests:
self.request = self._requests_post
Expand Down
2 changes: 1 addition & 1 deletion Adyen/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class AdyenBase(object):
def __setattr__(self, attr, value):
client_attr = ["username", "password", "platform", "app_name"]
client_attr = ["username", "password", "platform"]
if attr in client_attr:
if value:
self.client[attr] = value
Expand Down
3 changes: 2 additions & 1 deletion Adyen/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com"
ENDPOINT_CHECKOUT_LIVE_SUFFIX = "https://{}-checkout-live" \
".adyenpayments.com/checkout"
API_BIN_LOOKUP_VERSION = "v50"
API_CHECKOUT_VERSION = "v49"
API_CHECKOUT_UTILITY_VERSION = "v1"
API_RECURRING_VERSION = "v25"
API_PAYMENT_VERSION = "v49"
API_PAYOUT_VERSION = "v30"
LIB_VERSION = "2.3.0"
LIB_VERSION = "3.0.0"
LIB_NAME = "adyen-python-api-library"
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ ady.payment.client.hmac = "HMAC key for skin code"
ady.payment.client.platform = "test" # Environment to use the library in.
ady.payment.client.merchant_account = "merchant account name from CA"
ady.payment.client.password = "webservice user password"
ady.payment.client.app_name = "your app name"
```

## Documentation
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='Adyen',
packages=['Adyen'],
version='2.3.0',
version='3.0.0',
maintainer='Adyen',
maintainer_email='support@adyen.com',
description='Adyen Python Api',
Expand Down
1 change: 0 additions & 1 deletion test/CheckoutTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class TestCheckout(unittest.TestCase):
test = BaseTest(adyen)
client.xapikey = "YourXapikey"
client.platform = "test"
client.app_name = "appname"

def test_payment_methods_success_mocked(self):
request = {'merchantAccount': "YourMerchantAccount"}
Expand Down
1 change: 0 additions & 1 deletion test/CheckoutUtilityTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class TestCheckoutUtility(unittest.TestCase):
test = BaseTest(ady)
client.xapikey = "YourXapikey"
client.platform = "test"
client.app_name = "appname"

def test_origin_keys_success_mocked(self):
request = {
Expand Down
2 changes: 1 addition & 1 deletion test/DetermineEndpointTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class TestDetermineUrl(unittest.TestCase):
client = adyen.client
test = BaseTest(adyen)
client.xapikey = "YourXapikey"
client.app_name = "appname"

def test_checkout_api_url_custom(self):
self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
Expand Down Expand Up @@ -50,6 +49,7 @@ def test_payments_invalid_platform(self):

self.client.platform = "live"
self.client.live_endpoint_prefix = None

try:
self.adyen.checkout.payments(request)
except AdyenEndpointInvalidFormat as error:
Expand Down
1 change: 0 additions & 1 deletion test/DirectoryLookupTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class TestDirectoryLookup(unittest.TestCase):
client.platform = "test"
client.hmac = "DFB1EB5485895CFA84146406857104A" \
"BB4CBCABDC8AAF103A624C8F6A3EAAB00"
client.app_name = "appname"

def test_get_post_parameters(self):
request = {
Expand Down
1 change: 0 additions & 1 deletion test/ModificationTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class TestModifications(unittest.TestCase):
client.username = "YourWSUser"
client.password = "YourWSPassword"
client.platform = "test"
client.app_name = "appname"

def test_capture_success(self):
request = {}
Expand Down
2 changes: 0 additions & 2 deletions test/PaymentTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class TestPayments(unittest.TestCase):
client.username = "YourWSUser"
client.password = "YourWSPassword"
client.platform = "test"
client.app_name = "appname"
client.xapikey = ""

def test_authorise_success_mocked(self):
Expand Down Expand Up @@ -208,7 +207,6 @@ class TestPaymentsWithXapiKey(unittest.TestCase):
client = adyen.client
test = BaseTest(adyen)
client.platform = "test"
client.app_name = "appname"
client.username = "YourWSUser"
client.password = "YourWSPassword"
client.xapikey = ""
Expand Down
1 change: 0 additions & 1 deletion test/RecurringTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class TestRecurring(unittest.TestCase):
client.username = "YourWSUser"
client.password = "YourWSPassword"
client.platform = "test"
client.app_name = "appname"

def test_list_recurring_details(self):
request = {}
Expand Down
1 change: 0 additions & 1 deletion test/ThirdPartyPayoutTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class TestThirdPartyPayout(unittest.TestCase):
client.username = "YourWSUser"
client.password = "YourWSPassword"
client.platform = "test"
client.app_name = "appname"
client.review_payout_username = "YourReviewPayoutUser"
client.review_payout_password = "YourReviewPayoutPassword"
client.store_payout_username = "YourStorePayoutUser"
Expand Down
46 changes: 30 additions & 16 deletions test/mocks/BinLookupTest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import Adyen
from unittest.mock import ANY
import unittest

from BaseTest import BaseTest
import Adyen


REQUEST_KWARGS = {
'merchantAccount': 'YourMerchantAccount',
'amount': '1000'
}


class TestBinLookup(unittest.TestCase):
Expand All @@ -11,14 +19,9 @@ class TestBinLookup(unittest.TestCase):
client.username = "YourWSUser"
client.password = "YourWSPassword"
client.platform = "test"
client.app_name = "appname"

def test_get_cost_estimate_success(self):
request = {
'merchantAccount': 'YourMerchantAccount',
'amount': '1000'
}

self.ady.client.http_client.request.reset_mock()
expected = {
'cardBin': {
'bin': '458012',
Expand All @@ -39,29 +42,40 @@ def test_get_cost_estimate_success(self):

self.ady.client = self.test.create_client_from_file(
status=200,
request=request,
request=REQUEST_KWARGS,
filename='test/mocks/binlookup/getcostestimate-success.json'
)

result = self.ady.binlookup.get_cost_estimate(request)
result = self.ady.binlookup.get_cost_estimate(REQUEST_KWARGS)
self.assertEqual(expected, result.message)
self.ady.client.http_client.request.assert_called_once_with(
'https://pal-test.adyen.com/pal/servlet/'
'BinLookup/v50/getCostEstimate',
headers={},
json={
'merchantAccount': 'YourMerchantAccount',
'amount': '1000', 'applicationInfo': {
'adyenLibrary': {
'name': 'adyen-python-api-library',
'version': ANY
}
}
},
password='YourWSPassword',
username='YourWSUser'
)

def test_get_cost_estimate_error_mocked(self):
request = {
'merchantAccount': 'YourMerchantAccount',
'amount': '1000'
}

self.ady.client = self.test.create_client_from_file(
status=200,
request=request,
request=REQUEST_KWARGS,
filename=(
"test/mocks/binlookup/"
"getcostestimate-error-invalid-data-422.json"
)
)

result = self.ady.binlookup.get_cost_estimate(request)
result = self.ady.binlookup.get_cost_estimate(REQUEST_KWARGS)
self.assertEqual(422, result.message['status'])
self.assertEqual("101", result.message['errorCode'])
self.assertEqual("Invalid card number", result.message['message'])
Expand Down