diff --git a/Adyen/client.py b/Adyen/client.py index 353e3326..e5a0d54c 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -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 @@ -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 @@ -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]) @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/Adyen/httpclient.py b/Adyen/httpclient.py index 9aa36003..38e5a419 100644 --- a/Adyen/httpclient.py +++ b/Adyen/httpclient.py @@ -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 diff --git a/Adyen/services.py b/Adyen/services.py index e174c1be..90099f74 100644 --- a/Adyen/services.py +++ b/Adyen/services.py @@ -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 diff --git a/Adyen/settings.py b/Adyen/settings.py index 26c4d9c6..83ddcfff 100644 --- a/Adyen/settings.py +++ b/Adyen/settings.py @@ -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" diff --git a/README.md b/README.md index f7a5edc3..61973c89 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/setup.py b/setup.py index 6d849ab0..03268046 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/test/CheckoutTest.py b/test/CheckoutTest.py index 2aca7171..5061e8e9 100644 --- a/test/CheckoutTest.py +++ b/test/CheckoutTest.py @@ -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"} diff --git a/test/CheckoutUtilityTest.py b/test/CheckoutUtilityTest.py index fce50a09..8682ca33 100644 --- a/test/CheckoutUtilityTest.py +++ b/test/CheckoutUtilityTest.py @@ -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 = { diff --git a/test/DetermineEndpointTest.py b/test/DetermineEndpointTest.py index 4233c335..48345f0a 100644 --- a/test/DetermineEndpointTest.py +++ b/test/DetermineEndpointTest.py @@ -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" @@ -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: diff --git a/test/DirectoryLookupTest.py b/test/DirectoryLookupTest.py index d5f8cb52..dc75e962 100644 --- a/test/DirectoryLookupTest.py +++ b/test/DirectoryLookupTest.py @@ -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 = { diff --git a/test/ModificationTest.py b/test/ModificationTest.py index 21ed10d2..153a97c5 100644 --- a/test/ModificationTest.py +++ b/test/ModificationTest.py @@ -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 = {} diff --git a/test/PaymentTest.py b/test/PaymentTest.py index 82c06545..62fd1440 100644 --- a/test/PaymentTest.py +++ b/test/PaymentTest.py @@ -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): @@ -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 = "" diff --git a/test/RecurringTest.py b/test/RecurringTest.py index bebf91b6..e2aaf909 100644 --- a/test/RecurringTest.py +++ b/test/RecurringTest.py @@ -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 = {} diff --git a/test/ThirdPartyPayoutTest.py b/test/ThirdPartyPayoutTest.py index ed0a278b..1ab411f8 100644 --- a/test/ThirdPartyPayoutTest.py +++ b/test/ThirdPartyPayoutTest.py @@ -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" diff --git a/test/mocks/BinLookupTest.py b/test/mocks/BinLookupTest.py index 9ace1fa1..d470fa14 100644 --- a/test/mocks/BinLookupTest.py +++ b/test/mocks/BinLookupTest.py @@ -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): @@ -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', @@ -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'])