From fb0ba376dfa80a47149fb517d4296a9033113b88 Mon Sep 17 00:00:00 2001 From: Antoni Stroinski <55943882+antolo-arch@users.noreply.github.com> Date: Tue, 24 Jan 2023 14:48:20 +0100 Subject: [PATCH 1/5] Generate BinLookup --- Adyen/__init__.py | 4 +-- Adyen/client.py | 2 +- Adyen/services/__init__.py | 2 +- Adyen/services/binLookup.py | 46 +++++++++++++++++++++---------- test/{mocks => }/BinLookupTest.py | 20 ++++++-------- test/DetermineEndpointTest.py | 2 +- 6 files changed, 46 insertions(+), 30 deletions(-) rename test/{mocks => }/BinLookupTest.py (85%) diff --git a/Adyen/__init__.py b/Adyen/__init__.py index a0f8c93f..8f5ac5e0 100644 --- a/Adyen/__init__.py +++ b/Adyen/__init__.py @@ -15,7 +15,7 @@ from .client import AdyenClient from .services import ( AdyenBase, - AdyenBinLookup, + AdyenBinlookupApi, AdyenRecurring, AdyenPayment, AdyenThirdPartyPayout, @@ -32,7 +32,7 @@ class Adyen(AdyenBase): def __init__(self, **kwargs): self.client = AdyenClient(**kwargs) self.payment = AdyenPayment(client=self.client) - self.binlookup = AdyenBinLookup(client=self.client) + self.binlookup = AdyenBinlookupApi(client=self.client) self.payout = AdyenThirdPartyPayout(client=self.client) self.recurring = AdyenRecurring(client=self.client) self.checkout = AdyenCheckoutApi(client=self.client) diff --git a/Adyen/client.py b/Adyen/client.py index 6cf145e7..ab8c6b88 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -143,7 +143,7 @@ def _determine_base_url_and_version(self, platform, service): 'test': settings.PAL_TEST_URL + '/Payout' } }, - 'BinLookup': { + 'binlookup': { 'version': self.api_bin_lookup_version, 'base_url': { 'live': live_pal_url + '/BinLookup', diff --git a/Adyen/services/__init__.py b/Adyen/services/__init__.py index 7b5488e5..8e2028a5 100644 --- a/Adyen/services/__init__.py +++ b/Adyen/services/__init__.py @@ -1,5 +1,5 @@ from .base import AdyenBase -from .binLookup import AdyenBinLookup +from .binLookup import AdyenBinlookupApi from .checkout import AdyenCheckoutApi from .payments import AdyenPayment from .payouts import AdyenThirdPartyPayout diff --git a/Adyen/services/binLookup.py b/Adyen/services/binLookup.py index e2169ad4..07c341b7 100644 --- a/Adyen/services/binLookup.py +++ b/Adyen/services/binLookup.py @@ -1,24 +1,42 @@ -from .base import AdyenServiceBase +""" + Adyen BinLookup API + + The BIN Lookup API provides endpoints for retrieving information, such as cost estimates, and 3D Secure supported version based on a given BIN. ## Authentication You need an [API credential](https://docs.adyen.com/development-resources/api-credentials) to authenticate to the API. If using an API key, add an `X-API-Key` header with the API key as the value, for example: ``` curl -H \"Content-Type: application/json\" \\ -H \"X-API-Key: YOUR_API_KEY\" \\ ... ``` Alternatively, you can use the username and password to connect to the API using basic authentication, for example: ``` curl -U \"ws@Company.YOUR_COMPANY_ACCOUNT\":\"YOUR_BASIC_AUTHENTICATION_PASSWORD\" \\ -H \"Content-Type: application/json\" \\ ... ``` ## Versioning The BinLookup API supports [versioning](https://docs.adyen.com/development-resources/versioning) using a version suffix in the endpoint URL. This suffix has the following format: \"vXX\", where XX is the version number. For example: ``` https://pal-test.adyen.com/pal/servlet/BinLookup/v52/get3dsAvailability ```## Going live To authneticate to the live endpoints, you need an [API credential](https://docs.adyen.com/development-resources/api-credentials) from your live Customer Area. The live endpoint URLs contain a prefix which is unique to your company account: ``` https://{PREFIX}-pal-live.adyenpayments.com/pal/servlet/BinLookup/v52/get3dsAvailability ``` Get your `{PREFIX}` from your live Customer Area under **Developers** > **API URLs** > **Prefix**. # noqa: E501 + + The version of the OpenAPI document: 52 + Contact: developer-experience@adyen.com + Generated by: https://openapi-generator.tech +""" +from .base import AdyenServiceBase -class AdyenBinLookup(AdyenServiceBase): - """This represents the Adyen API Bin Lookup service. - API call currently implemented: getCostEstimate. - Please refer to the Bin Lookup Manual for specifics around the API. - https://docs.adyen.com/api-explorer/#/BinLookup/ +class AdyenBinlookupApi(AdyenServiceBase): + """NOTE: This class is auto generated by OpenAPI Generator + Ref: https://openapi-generator.tech - Args: - client (AdyenAPIClient, optional): An API client for the service to - use. If not provided, a new API client will be created. + Do not edit the class manually. """ def __init__(self, client=None): - super(AdyenBinLookup, self).__init__(client=client) - self.service = "BinLookup" + super(AdyenBinlookupApi, self).__init__(client=client) + self.service = "binlookup" - def get_cost_estimate(self, request="", **kwargs): + def check_if3d_secure_is_available(self, request, idempotency_key=None, **kwargs): + """ + Check if 3D Secure is available + """ + endpoint = f"/get3dsAvailability" + endpoint = endpoint.replace('/', '', 1) + method = "POST" + return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs) - action = "getCostEstimate" + def get_fees_cost_estimate(self, request, idempotency_key=None, **kwargs): + """ + Get a fees cost estimate + """ + endpoint = f"/getCostEstimate" + endpoint = endpoint.replace('/', '', 1) method = "POST" - return self.client.call_adyen_api(request, self.service, method, action, **kwargs) + return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs) + diff --git a/test/mocks/BinLookupTest.py b/test/BinLookupTest.py similarity index 85% rename from test/mocks/BinLookupTest.py rename to test/BinLookupTest.py index d470fa14..157a0c3c 100644 --- a/test/mocks/BinLookupTest.py +++ b/test/BinLookupTest.py @@ -1,8 +1,9 @@ from unittest.mock import ANY import unittest -from BaseTest import BaseTest +from .BaseTest import BaseTest import Adyen +from Adyen import settings REQUEST_KWARGS = { @@ -19,6 +20,7 @@ class TestBinLookup(unittest.TestCase): client.username = "YourWSUser" client.password = "YourWSPassword" client.platform = "test" + binLookup_version = settings.API_BIN_LOOKUP_VERSION def test_get_cost_estimate_success(self): self.ady.client.http_client.request.reset_mock() @@ -46,21 +48,17 @@ def test_get_cost_estimate_success(self): filename='test/mocks/binlookup/getcostestimate-success.json' ) - result = self.ady.binlookup.get_cost_estimate(REQUEST_KWARGS) + result = self.ady.binlookup.get_fees_cost_estimate(REQUEST_KWARGS) self.assertEqual(expected, result.message) self.ady.client.http_client.request.assert_called_once_with( + 'POST', 'https://pal-test.adyen.com/pal/servlet/' - 'BinLookup/v50/getCostEstimate', + f'BinLookup/{self.binLookup_version}/getCostEstimate', headers={}, json={ 'merchantAccount': 'YourMerchantAccount', - 'amount': '1000', 'applicationInfo': { - 'adyenLibrary': { - 'name': 'adyen-python-api-library', - 'version': ANY - } - } - }, + 'amount': '1000', + }, password='YourWSPassword', username='YourWSUser' ) @@ -75,7 +73,7 @@ def test_get_cost_estimate_error_mocked(self): ) ) - result = self.ady.binlookup.get_cost_estimate(REQUEST_KWARGS) + result = self.ady.binlookup.get_fees_cost_estimate(REQUEST_KWARGS) self.assertEqual(422, result.message['status']) self.assertEqual("101", result.message['errorCode']) self.assertEqual("Invalid card number", result.message['message']) diff --git a/test/DetermineEndpointTest.py b/test/DetermineEndpointTest.py index 251f7c02..7428ca07 100644 --- a/test/DetermineEndpointTest.py +++ b/test/DetermineEndpointTest.py @@ -91,7 +91,7 @@ def test_pal_url_no_live_endpoint_prefix_test_platform(self): def test_binlookup_url_no_live_endpoint_prefix_test_platform(self): self.client.live_endpoint_prefix = None url = self.adyen.client._determine_api_url( - "test", "BinLookup", "get3dsAvailability" + "test", "binlookup", "get3dsAvailability" ) self.assertEqual( url, From 6cf92e13bfc67f007876e0420abeb31864081316 Mon Sep 17 00:00:00 2001 From: Antoni Stroinski <55943882+antolo-arch@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:06:43 +0100 Subject: [PATCH 2/5] fix unit test --- test/BinLookupTest.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/BinLookupTest.py b/test/BinLookupTest.py index 157a0c3c..cff0d46e 100644 --- a/test/BinLookupTest.py +++ b/test/BinLookupTest.py @@ -1,10 +1,11 @@ -from unittest.mock import ANY import unittest - -from .BaseTest import BaseTest import Adyen from Adyen import settings +try: + from BaseTest import BaseTest +except ImportError: + from .BaseTest import BaseTest REQUEST_KWARGS = { 'merchantAccount': 'YourMerchantAccount', From e9455018188f6005af92e47c6b6547e86118ce27 Mon Sep 17 00:00:00 2001 From: Antoni Stroinski <55943882+antolo-arch@users.noreply.github.com> Date: Fri, 27 Jan 2023 09:29:36 +0100 Subject: [PATCH 3/5] Update Adyen/services/binLookup.py Co-authored-by: Michael Paul --- Adyen/services/binLookup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adyen/services/binLookup.py b/Adyen/services/binLookup.py index 07c341b7..270f6728 100644 --- a/Adyen/services/binLookup.py +++ b/Adyen/services/binLookup.py @@ -22,7 +22,7 @@ def __init__(self, client=None): super(AdyenBinlookupApi, self).__init__(client=client) self.service = "binlookup" - def check_if3d_secure_is_available(self, request, idempotency_key=None, **kwargs): + def get_3ds_availability(self, request, idempotency_key=None, **kwargs): """ Check if 3D Secure is available """ From 5ef90a7335dbcad712d6a74cc753469ba313e867 Mon Sep 17 00:00:00 2001 From: Antoni Stroinski <55943882+antolo-arch@users.noreply.github.com> Date: Fri, 27 Jan 2023 09:29:45 +0100 Subject: [PATCH 4/5] Update Adyen/services/binLookup.py Co-authored-by: Michael Paul --- Adyen/services/binLookup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adyen/services/binLookup.py b/Adyen/services/binLookup.py index 270f6728..7818ff62 100644 --- a/Adyen/services/binLookup.py +++ b/Adyen/services/binLookup.py @@ -31,7 +31,7 @@ def get_3ds_availability(self, request, idempotency_key=None, **kwargs): method = "POST" return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs) - def get_fees_cost_estimate(self, request, idempotency_key=None, **kwargs): + def get_cost_estimate(self, request, idempotency_key=None, **kwargs): """ Get a fees cost estimate """ From b23e16133f844c5d5a0d7455dc9b31f04b4417a6 Mon Sep 17 00:00:00 2001 From: Antoni Stroinski <55943882+antolo-arch@users.noreply.github.com> Date: Fri, 27 Jan 2023 09:34:04 +0100 Subject: [PATCH 5/5] update names in unit tests --- test/BinLookupTest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/BinLookupTest.py b/test/BinLookupTest.py index cff0d46e..8d64cf89 100644 --- a/test/BinLookupTest.py +++ b/test/BinLookupTest.py @@ -49,7 +49,7 @@ def test_get_cost_estimate_success(self): filename='test/mocks/binlookup/getcostestimate-success.json' ) - result = self.ady.binlookup.get_fees_cost_estimate(REQUEST_KWARGS) + result = self.ady.binlookup.get_cost_estimate(REQUEST_KWARGS) self.assertEqual(expected, result.message) self.ady.client.http_client.request.assert_called_once_with( 'POST', @@ -74,7 +74,7 @@ def test_get_cost_estimate_error_mocked(self): ) ) - result = self.ady.binlookup.get_fees_cost_estimate(REQUEST_KWARGS) + 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'])