diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index a6a4c20b..750dfb45 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -21,6 +21,7 @@ jobs: run: | python -m pip install --upgrade pip pip install tox + sudo apt-get update sudo apt install libcurl4-openssl-dev - name: Test with tox run: tox diff --git a/Adyen/client.py b/Adyen/client.py index ac4e3e5a..ef44f93d 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -122,7 +122,7 @@ def _determine_base_url_and_version(self, platform, service): live_pal_url = settings.PAL_LIVE_ENDPOINT_URL_TEMPLATE live_checkout_url = settings.ENDPOINT_CHECKOUT_LIVE_SUFFIX - if platform is 'live' and self.live_endpoint_prefix: + if platform == 'live' and self.live_endpoint_prefix: live_pal_url = live_pal_url.format(live_prefix=self.live_endpoint_prefix) live_checkout_url = live_checkout_url.format(live_prefix=self.live_endpoint_prefix) @@ -181,7 +181,7 @@ def _determine_base_url_and_version(self, platform, service): base_url = versions_and_urls[service]['base_url'][platform] # Match urls that require a live prefix and do not have one - if platform is 'live' and '{live_prefix}' in base_url: + if platform == 'live' and '{live_prefix}' in base_url: errorstring = "Please set your live suffix. You can set it by running" +\ "adyen.client.live_endpoint_prefix = 'Your live suffix'" raise AdyenEndpointInvalidFormat(errorstring) @@ -376,6 +376,10 @@ def call_adyen_api( url = self._determine_api_url(platform, service, endpoint) + if 'query_parameters' in kwargs: + url = url + util.get_query(kwargs['query_parameters']) + kwargs.pop('query_parameters') + if xapikey: raw_response, raw_request, status_code, headers = \ self.http_client.request(method, url, json=request_data, diff --git a/Adyen/httpclient.py b/Adyen/httpclient.py index 47e90240..954aba5a 100644 --- a/Adyen/httpclient.py +++ b/Adyen/httpclient.py @@ -49,6 +49,7 @@ def __init__( self.timeout = timeout + def _pycurl_request( self, method, diff --git a/Adyen/util.py b/Adyen/util.py index c4acfbbd..faaed913 100644 --- a/Adyen/util.py +++ b/Adyen/util.py @@ -98,3 +98,7 @@ def is_valid_hmac_notification(dict_object, hmac_key): merchant_sign = generate_notification_sig(dict_object, hmac_key) merchant_sign_str = merchant_sign.decode("utf-8") return hmac.compare_digest(merchant_sign_str, expected_sign) + + +def get_query(query_parameters): + return '?' + '&'.join(["{}={}".format(k, v) for k, v in query_parameters.items()]) diff --git a/README.md b/README.md index e021b83d..b81bf249 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,18 @@ 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" ~~~~ +### Using query parameters +Define a dictionary with query parameters that you want to use. +~~~~ python +query_parameters = { + 'pageSize':10, + 'pageNumber':3 + } +~~~~ +pass the dictionary to the method as an additional argument. +~~~~ python +ady.management.account_company_level_api.get_companies(query_parameters=query_parameters) +~~~~ ### Example integration diff --git a/openapi-generator-cli-6.0.1.jar b/openapi-generator-cli-6.0.1.jar deleted file mode 100644 index f62e364d..00000000 Binary files a/openapi-generator-cli-6.0.1.jar and /dev/null differ diff --git a/test/ManagementTest.py b/test/ManagementTest.py index 2cf6d434..8180e25d 100644 --- a/test/ManagementTest.py +++ b/test/ManagementTest.py @@ -130,3 +130,26 @@ def test_get_list_of_android_apps(self): companyId = "YOUR_COMPANY_ACCOUNT" result = self.adyen.management.terminal_actions_company_level_api.get_companies_company_id_terminal_actions(companyId) self.assertEqual("ANDA422LZ223223K5F694GCCF732K8",result.message['androidApps'][0]['id']) + + def test_query_paramaters(self): + request = {} + companyId = "YOUR_COMPANY_ACCOUNT" + query_parameters = { + 'pageNumber': 1, + 'pageSize':10 + + } + self.adyen.client = self.test.create_client_from_file(200,request, + "test/mocks/" + "management/" + "get_list_of_merchant_accounts.json") + result = self.adyen.management.account_company_level_api.\ + get_companies_company_id_merchants(companyId, query_parameters=query_parameters) + self.adyen.client.http_client.request.assert_called_once_with( + 'GET', + 'https://management-test.adyen.com/v1/companies/YOUR_COMPANY_ACCOUNT/merchants?pageNumber=1&pageSize=10', + headers={}, + json=None, + xapikey="YourXapikey" + ) + diff --git a/test/UtilTest.py b/test/UtilTest.py index 488c6c12..4aee2a49 100644 --- a/test/UtilTest.py +++ b/test/UtilTest.py @@ -6,6 +6,7 @@ is_valid_hmac, generate_notification_sig, is_valid_hmac_notification, + get_query ) @@ -71,3 +72,11 @@ def test_notification_request_item_hmac(self): self.assertDictEqual(request['additionalData'], {'hmacSignature': hmac_calculation_str}) self.assertTrue(hmac_validate) + + def test_query_string_creation(self): + query_parameters = { + "pageSize":7, + "pageNumber":3 + } + query_string = get_query(query_parameters) + self.assertEqual(query_string,'?pageSize=7&pageNumber=3') \ No newline at end of file diff --git a/test/mocks/management/get_list_of_merchant_accounts.json b/test/mocks/management/get_list_of_merchant_accounts.json new file mode 100644 index 00000000..de984794 --- /dev/null +++ b/test/mocks/management/get_list_of_merchant_accounts.json @@ -0,0 +1,255 @@ +{ + "_links": { + "first": { + "href": "https://management-test.adyen.com/v1/companies/YOUR_COMPANY_ACCOUNT/merchants?pageNumber=1&pageSize=10" + }, + "last": { + "href": "https://management-test.adyen.com/v1/companies/YOUR_COMPANY_ACCOUNT/merchants?pageNumber=3&pageSize=10" + }, + "next": { + "href": "https://management-test.adyen.com/v1/companies/YOUR_COMPANY_ACCOUNT/merchants?pageNumber=2&pageSize=10" + }, + "self": { + "href": "https://management-test.adyen.com/v1/companies/YOUR_COMPANY_ACCOUNT/merchants?pageNumber=1&pageSize=10" + } + }, + "itemsTotal": 22, + "pagesTotal": 3, + "data": [ + { + "id": "YOUR_MERCHANT_ACCOUNT_1", + "name": "YOUR_MERCHANT_NAME_1", + "captureDelay": "immediate", + "defaultShopperInteraction": "Ecommerce", + "status": "Active", + "shopWebAddress": "YOUR_SHOP_URL_1", + "merchantCity": "Amsterdam", + "primarySettlementCurrency": "EUR", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_1" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_1/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_1/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_1/webhooks" + } + } + }, + { + "id": "YOUR_MERCHANT_ACCOUNT_2", + "name": "YOUR_MERCHANT_NAME_2", + "captureDelay": "immediate", + "defaultShopperInteraction": "POS", + "status": "Active", + "shopWebAddress": "YOUR_SHOP_URL_2", + "merchantCity": "", + "primarySettlementCurrency": "EUR", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_2" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_2/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_2/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_2/webhooks" + } + } + }, + { + "id": "YOUR_MERCHANT_ACCOUNT_3", + "status": "Active", + "merchantCity": "Amsterdam", + "primarySettlementCurrency": "EUR", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_3" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_3/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_3/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_3/webhooks" + } + } + }, + { + "id": "YOUR_MERCHANT_ACCOUNT_4", + "name": "YOUR_MERCHANT_NAME_4", + "captureDelay": "immediate", + "defaultShopperInteraction": "Ecommerce", + "status": "Active", + "shopWebAddress": "YOUR_SHOP_URL_4", + "merchantCity": "Sao Paulo", + "primarySettlementCurrency": "BRL", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_4" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_4/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_4/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_4/webhooks" + } + } + }, + { + "id": "YOUR_MERCHANT_ACCOUNT_5", + "name": "YOUR_MERCHANT_NAME_5", + "captureDelay": "3", + "defaultShopperInteraction": "Ecommerce", + "status": "Active", + "shopWebAddress": "YOUR_SHOP_URL_5", + "primarySettlementCurrency": "EUR", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_5" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_5/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_5/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_5/webhooks" + } + } + }, + { + "id": "YOUR_MERCHANT_ACCOUNT_6", + "name": "YOUR_MERCHANT_NAME_6", + "captureDelay": "immediate", + "defaultShopperInteraction": "Ecommerce", + "status": "Active", + "shopWebAddress": "YOUR_SHOP_URL_6", + "merchantCity": "Zagreb", + "primarySettlementCurrency": "BRL", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_6" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_6/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_6/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_6/webhooks" + } + } + }, + { + "id": "YOUR_MERCHANT_ACCOUNT_7", + "name": "YOUR_MERCHANT_NAME_7", + "captureDelay": "manual", + "defaultShopperInteraction": "Moto", + "status": "Active", + "shopWebAddress": "YOUR_SHOP_URL_7", + "merchantCity": "Amsterdam", + "primarySettlementCurrency": "EUR", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_7" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_7/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_7/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_7/webhooks" + } + } + }, + { + "id": "YOUR_MERCHANT_ACCOUNT_8", + "name": "YOUR_MERCHANT_NAME_8", + "captureDelay": "immediate", + "defaultShopperInteraction": "Ecommerce", + "status": "Active", + "shopWebAddress": "YOUR_SHOP_URL_8", + "merchantCity": "Amsterdam", + "primarySettlementCurrency": "EUR", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_8" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_8/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_8/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_8/webhooks" + } + } + }, + { + "id": "YOUR_MERCHANT_ACCOUNT_9", + "name": "YOUR_MERCHANT_NAME_9", + "captureDelay": "3", + "defaultShopperInteraction": "Ecommerce", + "status": "Active", + "shopWebAddress": "YOUR_SHOP_URL_9", + "merchantCity": "", + "primarySettlementCurrency": "EUR", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_9" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_9/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_9/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_9/webhooks" + } + } + }, + { + "id": "YOUR_MERCHANT_ACCOUNT_10", + "name": "YOUR_MERCHANT_NAME_10", + "captureDelay": "manual", + "defaultShopperInteraction": "Ecommerce", + "status": "Active", + "shopWebAddress": "YOUR_SHOP_URL_10", + "merchantCity": "Paris", + "primarySettlementCurrency": "EUR", + "_links": { + "self": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_10" + }, + "apiCredentials": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_10/apiCredentials" + }, + "users": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_10/users" + }, + "webhooks": { + "href": "https://management-test.adyen.com/v1/merchants/YOUR_MERCHANT_ACCOUNT_10/webhooks" + } + } + } + ] +} \ No newline at end of file