From a889a8fe9d7c1ee0bd755f7efc6ea11f562d7526 Mon Sep 17 00:00:00 2001 From: alexandros Date: Mon, 11 Oct 2021 15:25:26 +0200 Subject: [PATCH 1/4] Add vagrantfile, sessions api, update to v68 --- .gitignore | 3 +- Adyen/client.py | 5 ++- Adyen/services.py | 3 ++ Adyen/settings.py | 3 +- Vagrantfile | 20 ++++++++++++ test/CheckoutTest.py | 31 +++++++++++++++++-- test/DetermineEndpointTest.py | 17 +++++++--- .../sessions-error-invalid-data-422.json | 6 ++++ test/mocks/checkout/sessions-success.json | 11 +++++++ 9 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 Vagrantfile create mode 100644 test/mocks/checkout/sessions-error-invalid-data-422.json create mode 100644 test/mocks/checkout/sessions-success.json diff --git a/.gitignore b/.gitignore index 85e6154a..3de14bd7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ releaseguide.md venv/ .idea/ -.coverage \ No newline at end of file +.coverage +.vagrant/ \ No newline at end of file diff --git a/Adyen/client.py b/Adyen/client.py index e43fa560..a964ceff 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -189,6 +189,8 @@ def _determine_checkout_url(self, platform, action): action = "paymentMethods/balance" if action == "ordersCancel": action = "orders/cancel" + if action == "sessions": + action = "sessions" return '/'.join([base_uri, api_version, action]) @@ -509,7 +511,8 @@ def call_checkout_api(self, request_data, action, idempotency_key=None, "payments", "paymentSession", "paymentLinks", - "paymentMethodsBalance" + "paymentMethodsBalance", + "sessions" ] if action in with_app_info: diff --git a/Adyen/services.py b/Adyen/services.py index b569f560..e288106d 100644 --- a/Adyen/services.py +++ b/Adyen/services.py @@ -325,6 +325,9 @@ def origin_keys(self, request=None, **kwargs): action = "originKeys" return self.client.call_checkout_api(request, action, **kwargs) + def sessions(self, request=None, **kwargs): + action = "sessions" + return self.client.call_checkout_api(request, action, **kwargs) # Orders endpoints # /paymentMethods/balance diff --git a/Adyen/settings.py b/Adyen/settings.py index 793da7e5..30c16171 100644 --- a/Adyen/settings.py +++ b/Adyen/settings.py @@ -7,7 +7,8 @@ ENDPOINT_CHECKOUT_LIVE_SUFFIX = "https://{}-checkout-live" \ ".adyenpayments.com/checkout" API_BIN_LOOKUP_VERSION = "v50" -API_CHECKOUT_VERSION = "v67" +API_CHECKOUT_VERSION = "v68" +API_CHECKOUT_VERSION = "v68" API_CHECKOUT_UTILITY_VERSION = "v1" API_RECURRING_VERSION = "v49" API_PAYMENT_VERSION = "v64" diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..7a1a7576 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,20 @@ +$script = <<-SCRIPT +sudo yum install -y https://repo.ius.io/ius-release-el7.rpm +echo "Run update" +sudo yum update +echo "Install python 3.6" +sudo yum install -y python36u python36u-libs python36u-devel python36u-pip +sudo yum install python2-pycodestyle +SCRIPT + +Vagrant.configure("2") do |config| + config.vm.box = "centos/7" + config.vm.synced_folder '.', '/home/vagrant/adyen-python-api-library', disabled: false + config.vm.synced_folder '.', '/vagrant', disabled: true + config.vm.network :forwarded_port, guest:3001, host: 3001 + config.vm.provider :virtualbox do |vb| + vb.name = "adyen-python-api-library" + vb.customize ["modifyvm", :id, "--memory", "1024", "--cpus", "2"] + end + config.vm.provision "shell", inline: $script +end \ No newline at end of file diff --git a/test/CheckoutTest.py b/test/CheckoutTest.py index 14bec1ab..3bbff993 100644 --- a/test/CheckoutTest.py +++ b/test/CheckoutTest.py @@ -91,7 +91,7 @@ def test_payments_error_mocked(self): result = self.adyen.checkout.payments(request) self.adyen.client.http_client.request.assert_called_once_with( - 'https://checkout-test.adyen.com/v67/payments', + 'https://checkout-test.adyen.com/v68/payments', headers={}, json={ 'returnUrl': 'https://your-company.com/...', @@ -134,7 +134,7 @@ def test_payments_details_success_mocked(self): result = self.adyen.checkout.payments_details(request) self.adyen.client.http_client.request.assert_called_once_with( - u'https://checkout-test.adyen.com/v67/payments/details', + u'https://checkout-test.adyen.com/v68/payments/details', headers={}, json={ 'paymentData': 'Hee57361f99....', @@ -274,3 +274,30 @@ def test_paymentmethods_balance_success(self): self.assertEqual("Success", result.message['resultCode']) self.assertEqual(100, result.message['balance']['value']) self.assertEqual("EUR", result.message['balance']['currency']) + + def test_sessions_success(self): + request = {'merchantAccount': "YourMerchantAccount"} + self.adyen.client = self.test.create_client_from_file(200, request, + "test/mocks/" + "checkout/" + "sessions" + "-success.json") + result = self.adyen.checkout.sessions(request) + self.assertEqual("session-test-id", result.message['id']) + self.assertEqual("TestReference", result.message['reference']) + self.assertEqual("http://test-url.com", result.message['returnUrl']) + + def test_sessions_error(self): + request = {'merchantAccount': "YourMerchantAccount"} + self.adyen.client = self.test.create_client_from_file(200, request, + "test/mocks/" + "checkout/" + "sessions" + "-error" + "-invalid" + "-data-422" + ".json") + result = self.adyen.checkout.sessions(request) + self.assertEqual(422, result.message['status']) + self.assertEqual("130", result.message['errorCode']) + self.assertEqual("validation", result.message['errorType']) \ No newline at end of file diff --git a/test/DetermineEndpointTest.py b/test/DetermineEndpointTest.py index 6943fba4..bd30641f 100644 --- a/test/DetermineEndpointTest.py +++ b/test/DetermineEndpointTest.py @@ -21,14 +21,14 @@ def test_checkout_api_url_custom(self): url = self.adyen.client._determine_checkout_url("live", "payments") self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo" self.assertEqual(url, "https://1797a841fbb37ca7-AdyenDemo-checkout-" - "live.adyenpayments.com/checkout/v67/payments") + "live.adyenpayments.com/checkout/v68/payments") def test_checkout_api_url(self): self.client.live_endpoint_prefix = None url = self.adyen.client._determine_checkout_url("test", "paymentsDetails") self.assertEqual(url, "https://checkout-test.adyen.com" - "/v67/payments/details") + "/v68/payments/details") def test_payments_invalid_platform(self): @@ -112,19 +112,26 @@ def test_checkout_api_url_orders(self): url = self.adyen.client._determine_checkout_url("test", "orders") self.assertEqual(url, "https://checkout-test.adyen.com" - "/v67/orders") + "/v68/orders") def test_checkout_api_url_order_cancel(self): self.client.live_endpoint_prefix = None url = self.adyen.client._determine_checkout_url("test", "ordersCancel") self.assertEqual(url, "https://checkout-test.adyen.com" - "/v67/orders/cancel") + "/v68/orders/cancel") def test_checkout_api_url_order_payment_methods_balance(self): self.client.live_endpoint_prefix = None url = self.adyen.client._determine_checkout_url("test", "paymentMethods" "Balance") - self.assertEqual(url, "https://checkout-test.adyen.com""/v67/" + self.assertEqual(url, "https://checkout-test.adyen.com""/v68/" "paymentMethods/balance") + + def test_checkout_api_url_sessions(self): + self.client.live_endpoint_prefix = None + url = self.adyen.client._determine_checkout_url("test", + "sessions") + self.assertEqual(url, "https://checkout-test.adyen.com""/v68/" + "sessions") diff --git a/test/mocks/checkout/sessions-error-invalid-data-422.json b/test/mocks/checkout/sessions-error-invalid-data-422.json new file mode 100644 index 00000000..540ea247 --- /dev/null +++ b/test/mocks/checkout/sessions-error-invalid-data-422.json @@ -0,0 +1,6 @@ +{ + "status": 422, + "errorCode": "130", + "message": "Reference Missing", + "errorType": "validation" +} \ No newline at end of file diff --git a/test/mocks/checkout/sessions-success.json b/test/mocks/checkout/sessions-success.json new file mode 100644 index 00000000..a20fbbc1 --- /dev/null +++ b/test/mocks/checkout/sessions-success.json @@ -0,0 +1,11 @@ +{ + "id": "session-test-id", + "amount": { + "currency": "EUR", + "value": 1000 + }, + "reference": "TestReference", + "returnUrl": "http://test-url.com", + "expiresAt": "2021-09-30T06:45:06Z", + "merchantAccount": "YourMerchantAccount" +} \ No newline at end of file From f8eb622a28d837f23db7adfcc865230b31ca1369 Mon Sep 17 00:00:00 2001 From: alexandros Date: Mon, 11 Oct 2021 15:28:53 +0200 Subject: [PATCH 2/4] Remove extra settings --- Adyen/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Adyen/settings.py b/Adyen/settings.py index 30c16171..97bd96ef 100644 --- a/Adyen/settings.py +++ b/Adyen/settings.py @@ -8,7 +8,6 @@ ".adyenpayments.com/checkout" API_BIN_LOOKUP_VERSION = "v50" API_CHECKOUT_VERSION = "v68" -API_CHECKOUT_VERSION = "v68" API_CHECKOUT_UTILITY_VERSION = "v1" API_RECURRING_VERSION = "v49" API_PAYMENT_VERSION = "v64" From 524092c403eecb9ddec0351d41aa228874e6562b Mon Sep 17 00:00:00 2001 From: alexandros Date: Mon, 11 Oct 2021 15:40:12 +0200 Subject: [PATCH 3/4] Remove unused if --- Adyen/client.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Adyen/client.py b/Adyen/client.py index a964ceff..9383a34e 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -189,8 +189,6 @@ def _determine_checkout_url(self, platform, action): action = "paymentMethods/balance" if action == "ordersCancel": action = "orders/cancel" - if action == "sessions": - action = "sessions" return '/'.join([base_uri, api_version, action]) From f19642b9dc64ce89fe1fa34a3a59cea8be4672fe Mon Sep 17 00:00:00 2001 From: alexandros Date: Tue, 12 Oct 2021 10:19:44 +0200 Subject: [PATCH 4/4] Sessions returns httpcode 201 so it is not an error --- Adyen/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adyen/client.py b/Adyen/client.py index 9383a34e..5c597993 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -601,7 +601,7 @@ def _handle_response(self, url, raw_response, raw_request, Returns: AdyenResult: Result object if successful. """ - if status_code != 200: + if (status_code != 200 and status_code != 201): 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: