From fbf7782c25a6c87c2964297179c02bca8f1a5d45 Mon Sep 17 00:00:00 2001 From: Kwadjo Nyante <61976215+harpazo64@users.noreply.github.com> Date: Tue, 31 Aug 2021 12:46:32 +0200 Subject: [PATCH 01/10] Create codeql-analysis2.yml security code-scanning --- .github/workflows/codeql-analysis2.yml | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/codeql-analysis2.yml diff --git a/.github/workflows/codeql-analysis2.yml b/.github/workflows/codeql-analysis2.yml new file mode 100644 index 00000000..afb3639c --- /dev/null +++ b/.github/workflows/codeql-analysis2.yml @@ -0,0 +1,71 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ develop ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ develop ] + schedule: + - cron: '0 0 * * *' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + queries: security-extedned # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + # - name: Autobuild + # uses: github/codeql-action/autobuild@v1 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 From e5e318440ec52412a27541781839f45f6dbc3f49 Mon Sep 17 00:00:00 2001 From: Kwadjo Nyante <61976215+harpazo64@users.noreply.github.com> Date: Tue, 31 Aug 2021 12:47:52 +0200 Subject: [PATCH 02/10] Update codeql-analysis2.yml update --- .github/workflows/codeql-analysis2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis2.yml b/.github/workflows/codeql-analysis2.yml index afb3639c..30a6d939 100644 --- a/.github/workflows/codeql-analysis2.yml +++ b/.github/workflows/codeql-analysis2.yml @@ -49,7 +49,7 @@ jobs: # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. - queries: security-extedned # queries: ./path/to/local/query, your-org/your-repo/queries@main + queries: security-extended # queries: ./path/to/local/query, your-org/your-repo/queries@main # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) From 590ddcfb74f93eccbb788b5ee586889f439b116f Mon Sep 17 00:00:00 2001 From: Eric Laff Date: Tue, 8 Jun 2021 22:13:29 +0200 Subject: [PATCH 03/10] Adding cancels action --- Adyen/client.py | 10 ++++--- Adyen/services.py | 4 +++ test/CheckoutTest.py | 27 +++++++++++++++++++ .../checkout/paymentscancels-success.json | 7 +++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 test/mocks/checkout/paymentscancels-success.json diff --git a/Adyen/client.py b/Adyen/client.py index bcdb266b..4fa0f19e 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -145,13 +145,14 @@ def _determine_hpp_url(platform, action): result = '/'.join([base_uri, service]) return result - def _determine_checkout_url(self, platform, action): + def _determine_checkout_url(self, platform, action, path_param=None): """This returns the Adyen API endpoint based on the provided platform, service and action. Args: platform (str): Adyen platform, ie 'live' or 'test'. action (str): the API action to perform. + path_param Optional[(str)]: a generic id that can be used to modify a payment e.g. paymentPspReference. """ api_version = settings.API_CHECKOUT_VERSION if platform == "test": @@ -171,6 +172,8 @@ def _determine_checkout_url(self, platform, action): action = "payments/details" if action == "paymentsResult": action = "payments/result" + if action == "paymentsCancels": + action = f"payments/{path_param}/cancels" if action == "originKeys": api_version = settings.API_CHECKOUT_UTILITY_VERSION if action == "paymentMethodsBalance": @@ -437,7 +440,7 @@ class instance. status_code, headers, message) return adyen_result - def call_checkout_api(self, request_data, action, idempotency_key=None, + def call_checkout_api(self, request_data, action, idempotency_key=None, path_param=None, **kwargs): """This will call the checkout adyen api. xapi key merchant_account, and platform are pulled from root module level and or self object. @@ -452,6 +455,7 @@ def call_checkout_api(self, request_data, action, idempotency_key=None, https://docs.adyen.com/developers/checkout/api-integration service (str): This is the API service to be called. action (str): The specific action of the API service to be called + path_param (str): This is used to pass the id or referenceID to the API sercie """ if not self.http_init: self.http_client = HTTPClient(self.USER_AGENT_SUFFIX, @@ -520,7 +524,7 @@ def call_checkout_api(self, request_data, action, idempotency_key=None, headers = {} if idempotency_key: headers[self.IDEMPOTENCY_HEADER_NAME] = idempotency_key - url = self._determine_checkout_url(platform, action) + url = self._determine_checkout_url(platform, action, path_param) raw_response, raw_request, status_code, headers = \ self.http_client.request(url, json=request_data, diff --git a/Adyen/services.py b/Adyen/services.py index 3c44273a..e5ba74a6 100644 --- a/Adyen/services.py +++ b/Adyen/services.py @@ -322,6 +322,10 @@ def payment_result(self, request=None, **kwargs): action = "paymentsResult" return self.client.call_checkout_api(request, action, **kwargs) + def payment_cancels(self, request=None, path_param=None,**kwargs): + action = "paymentsCancels" + return self.client.call_checkout_api(request, action, path_param=path_param, **kwargs) + def origin_keys(self, request=None, **kwargs): action = "originKeys" return self.client.call_checkout_api(request, action, **kwargs) diff --git a/test/CheckoutTest.py b/test/CheckoutTest.py index 14bec1ab..ca9a6828 100644 --- a/test/CheckoutTest.py +++ b/test/CheckoutTest.py @@ -236,6 +236,33 @@ def test_payments_result_error_mocked(self): self.assertEqual("Invalid payload provided", result.message['message']) self.assertEqual("validation", result.message['errorType']) + def test_payments_cancels_success_mocked(self): + requests = {"reference": "Your wro order number", "merchantAccount":"YOUR_MERCHANT_ACCOUNT"} + reference_id = "8836183819713023" + self.adyen.client = self.test.create_client_from_file(200, requests, + "test/mocks/" + "checkout/" + "paymentscancels" + "-success.json") + result = self.adyen.checkout.payment_cancels(request=requests, path_param=reference_id) + self.assertEqual(reference_id, result.message["paymentPspReference"]) + self.assertEqual("received", result.message['status']) + + def test_payments_cancels_fail_mocked(self): + requests = {"reference": "Your wro order number"} + reference_id = "8836183819713023" + self.adyen.client = self.test.create_client_from_file(200, requests, + "test/mocks/" + "checkout/" + "paymentsresult-error-invalid-" + "data-payload-422.json") + result = self.adyen.checkout.payment_cancels(request=requests, path_param=reference_id) + self.assertEqual(422, result.message['status']) + self.assertEqual("14_018", result.message['errorCode']) + self.assertEqual("Invalid payload provided", result.message['message']) + self.assertEqual("validation", result.message['errorType']) + + def test_orders_success(self): request = {'merchantAccount': "YourMerchantAccount"} self.adyen.client = self.test.create_client_from_file(200, request, diff --git a/test/mocks/checkout/paymentscancels-success.json b/test/mocks/checkout/paymentscancels-success.json new file mode 100644 index 00000000..f9883a90 --- /dev/null +++ b/test/mocks/checkout/paymentscancels-success.json @@ -0,0 +1,7 @@ +{ + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "paymentPspReference": "8836183819713023", + "pspReference" : "8412534564722331", + "reference": "Cancel123", + "status" : "received" +} \ No newline at end of file From 5be67f9f8ca428893fe99f298b0f00a825cbc92a Mon Sep 17 00:00:00 2001 From: Eric Laff Date: Wed, 9 Jun 2021 14:48:17 +0200 Subject: [PATCH 04/10] Adding modifications to checkout api --- Adyen/client.py | 8 +- Adyen/services.py | 45 ++++- test/CheckoutTest.py | 178 +++++++++++++++++- .../checkout/paymentcapture-success.json | 11 ++ ...aymentscancel-withoutreference-succes.json | 7 + .../checkout/paymentsreversals-success.json | 7 + 6 files changed, 247 insertions(+), 9 deletions(-) create mode 100644 test/mocks/checkout/paymentcapture-success.json create mode 100644 test/mocks/checkout/paymentscancel-withoutreference-succes.json create mode 100644 test/mocks/checkout/paymentsreversals-success.json diff --git a/Adyen/client.py b/Adyen/client.py index 4fa0f19e..28a74ce9 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -172,8 +172,14 @@ def _determine_checkout_url(self, platform, action, path_param=None): action = "payments/details" if action == "paymentsResult": action = "payments/result" - if action == "paymentsCancels": + if action == "paymentsCancelsWithoutReference": + action = "payments/cancels" + if action == "paymentsCancelsWithReference": action = f"payments/{path_param}/cancels" + if action == "paymentsReversals": + action = f"payments/{path_param}/reversals" + if action == "payments/Refunds": + action = f"payments/{path_param}/refunds" if action == "originKeys": api_version = settings.API_CHECKOUT_UTILITY_VERSION if action == "paymentMethodsBalance": diff --git a/Adyen/services.py b/Adyen/services.py index e5ba74a6..16fe9428 100644 --- a/Adyen/services.py +++ b/Adyen/services.py @@ -280,6 +280,13 @@ class AdyenCheckoutApi(AdyenServiceBase): payments/details originKeys + Modifications: + capture + refunds + cancels + reversals + + Please refer to the checkout documentation for specifics around the API. https://docs.adyen.com/developers/checkout @@ -322,9 +329,41 @@ def payment_result(self, request=None, **kwargs): action = "paymentsResult" return self.client.call_checkout_api(request, action, **kwargs) - def payment_cancels(self, request=None, path_param=None,**kwargs): - action = "paymentsCancels" - return self.client.call_checkout_api(request, action, path_param=path_param, **kwargs) + def payment_captures(self, path_param, request=None, idempotency_key=None, **kwargs): + if path_param is None or "": + raise ValueError( + 'must contain a pspReference in the path_param, path_param cannot be empty' + ) + action = "paymentsCapture" + return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) + + def payments_cancels_without_reference(self, request=None, idempotency_key=None, **kwargs): + action = "paymentsCancelsWithoutReference" + return self.client.call_checkout_api(request, action, idempotency_key, **kwargs) + + def payments_cancels_with_reference(self, path_param, request=None, idempotency_key=None, **kwargs): + if path_param == "": + raise ValueError( + 'must contain a pspReference in the path_param, path_param cannot be empty' + ) + action = "paymentsCancelsWithReference" + return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) + + def payments_reversals(self, path_param, request=None, idempotency_key=None, **kwargs): + if path_param is None or "": + raise ValueError( + 'must contain a pspReference in the path_param, path_param cannot be empty' + ) + action = "paymentsReversals" + return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) + + def payments_refunds(self, path_param, request=None, idempotency_key=None, **kwargs): + if path_param is None or "": + raise ValueError( + 'must contain a pspReference in the path_param, path_param cannot be empty' + ) + action = "paymentsRefunds" + return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) def origin_keys(self, request=None, **kwargs): action = "originKeys" diff --git a/test/CheckoutTest.py b/test/CheckoutTest.py index ca9a6828..bffc5526 100644 --- a/test/CheckoutTest.py +++ b/test/CheckoutTest.py @@ -236,32 +236,200 @@ def test_payments_result_error_mocked(self): self.assertEqual("Invalid payload provided", result.message['message']) self.assertEqual("validation", result.message['errorType']) + def test_payments_cancels_without_reference(self): + requests = { + "paymentReference": "Payment123", + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "reference": "YourCancelReference", + } + self.adyen.client = self.test.create_client_from_file(200, requests, + "test/mocks/" + "checkout/" + "paymentscancel-" + "withoutreference-succes.json") + results = self.adyen.checkout.payments_cancels_without_reference(request=requests) + self.assertIsNotNone(results.message['paymentReference']) + self.assertEqual("8412534564722331", results.message['pspReference']) + self.assertEqual("received", results.message['status']) + + def test_payments_cancels_without_reference_error_mocked(self): + requests = { + "paymentReference": "Payment123", + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "reference": "YourCancelReference", + } + self.adyen.client = self.test.create_client_from_file(200, requests, + "test/mocks/" + "checkout/" + "paymentsresult" + "-error-invalid-" + "data-payload-" + "422.json") + + result = self.adyen.checkout.payments_cancels_without_reference(requests) + self.assertEqual(422, result.message['status']) + self.assertEqual("14_018", result.message['errorCode']) + self.assertEqual("Invalid payload provided", result.message['message']) + self.assertEqual("validation", result.message['errorType']) + def test_payments_cancels_success_mocked(self): - requests = {"reference": "Your wro order number", "merchantAccount":"YOUR_MERCHANT_ACCOUNT"} + requests = {"reference": "Your wro order number", "merchantAccount": "YOUR_MERCHANT_ACCOUNT"} reference_id = "8836183819713023" self.adyen.client = self.test.create_client_from_file(200, requests, "test/mocks/" "checkout/" "paymentscancels" "-success.json") - result = self.adyen.checkout.payment_cancels(request=requests, path_param=reference_id) + result = self.adyen.checkout.payments_cancels_with_reference(request=requests, path_param=reference_id) self.assertEqual(reference_id, result.message["paymentPspReference"]) self.assertEqual("received", result.message['status']) - def test_payments_cancels_fail_mocked(self): + def test_payments_cancels_error_mocked(self): requests = {"reference": "Your wro order number"} - reference_id = "8836183819713023" + psp_reference = "8836183819713023" self.adyen.client = self.test.create_client_from_file(200, requests, "test/mocks/" "checkout/" "paymentsresult-error-invalid-" "data-payload-422.json") - result = self.adyen.checkout.payment_cancels(request=requests, path_param=reference_id) + result = self.adyen.checkout.payments_cancels_with_reference(request=requests, path_param=psp_reference) self.assertEqual(422, result.message['status']) self.assertEqual("14_018", result.message['errorCode']) self.assertEqual("Invalid payload provided", result.message['message']) self.assertEqual("validation", result.message['errorType']) + def test_payments_refunds_success_mocked(self): + requests = { + "paymentReference": "Payment123", + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "reference": "YourCancelReference", + } + psp_reference = "Payment123" + self.adyen.client = self.test.create_client_from_file(200, requests, + "test/mocks/" + "checkout/" + "paymentscancel-" + "withoutreference-succes.json") + + result = self.adyen.checkout.payments_cancels_without_reference(request=requests, path_param=psp_reference) + self.assertEqual(psp_reference, result.message["paymentReference"]) + self.assertIsNotNone(result.message["pspReference"]) + self.assertEqual("received", result.message['status']) + + def test_payments_refunds_error_mocked(self): + requests = { + "paymentReference": "Payment123", + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "reference": "YourCancelReference", + } + reference_id = "Payment123" + self.adyen.client = self.test.create_client_from_file(200, requests, + "test/mocks/" + "checkout/" + "paymentsresult-error-invalid-" + "data-payload-422.json") + + result = self.adyen.checkout.payments_cancels_without_reference(request=requests, path_param=reference_id) + self.assertEqual(422, result.message['status']) + self.assertEqual("14_018", result.message['errorCode']) + self.assertEqual("Invalid payload provided", result.message['message']) + self.assertEqual("validation", result.message['errorType']) + + def test_payments_refunds_raises_vaulue_error(self): + requests = { + "paymentReference": "Payment123", + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "reference": "YourCancelReference", + } + self.adyen.client = self.test.create_client_from_file(200, requests, + "test/mocks/" + "checkout/" + "paymentscancel-" + "withoutreference-succes.json") + with self.assertRaises(ValueError) as exc: + self.adyen.checkout.payments_cancels_with_reference(request=requests, path_param="") + self.assertEqual(exc.exception.__class__, ValueError) + self.assertEqual(exc.exception.__str__(), 'must contain a pspReference in the path_param, path_param cannot ' + 'be empty') + + def test_reversals_success_mocked(self): + requests = { + "reference": "YourReversalReference", + "merchantAccount": "YOUR_MERCHANT_ACCOUNT" + } + psp_reference = "8836183819713023" + self.adyen.client = self.test.create_client_from_file(200, requests, + "test/mocks/" + "checkout/" + "paymentsreversals-" + "success.json") + + result = self.adyen.checkout.payments_reversals(request=requests, path_param=psp_reference) + self.assertEqual(psp_reference, result.message["paymentPspReference"]) + self.assertIsNotNone(result.message["pspReference"]) + self.assertEqual("received", result.message['status']) + + def test_payments_reversals_failure_mocked(self): + requests = { + "reference": "YourReversalReference", + "merchantAccount": "YOUR_MERCHANT_ACCOUNT" + } + psp_reference = "8836183819713023" + self.adyen.client = self.test.create_client_from_file(200, requests, + "test/mocks/" + "checkout/" + "paymentsresult-error-invalid-" + "data-payload-422.json") + + result = self.adyen.checkout.payments_reversals(request=requests, path_param=psp_reference) + self.assertEqual(422, result.message['status']) + self.assertEqual("14_018", result.message['errorCode']) + self.assertEqual("Invalid payload provided", result.message['message']) + self.assertEqual("validation", result.message['errorType']) + + def test_payments_capture_success_mocked(self): + request = { + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "amount": { + "value": 2500, + "currency": "EUR" + }, + "reference": "YOUR_UNIQUE_REFERENCE" + } + psp_reference = "8536214160615591" + self.adyen.client = self.test.create_client_from_file(200, request, + "test/mocks/" + "checkout/" + "paymentcapture-" + "success.json") + + result = self.adyen.checkout.payment_captures(request=request, path_param=psp_reference) + self.assertEqual(psp_reference, result.message["paymentPspReference"]) + self.assertIsNotNone(result.message["pspReference"]) + self.assertEqual("received", result.message['status']) + self.assertEqual(2500, result.message['amount']['value']) + + def test_payments_capture_error_mocked(self): + request = { + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "amount": { + "value": 2500, + "currency": "EUR" + }, + "reference": "YOUR_UNIQUE_REFERENCE" + } + psp_reference = "8536214160615591" + self.adyen.client = self.test.create_client_from_file(200, request, + "test/mocks/" + "checkout/" + "paymentsresult-error-invalid-" + "data-payload-422.json") + + result = self.adyen.checkout.payment_captures(request=request, path_param=psp_reference) + self.assertEqual(422, result.message['status']) + self.assertEqual("14_018", result.message['errorCode']) + self.assertEqual("Invalid payload provided", result.message['message']) + self.assertEqual("validation", result.message['errorType']) def test_orders_success(self): request = {'merchantAccount': "YourMerchantAccount"} diff --git a/test/mocks/checkout/paymentcapture-success.json b/test/mocks/checkout/paymentcapture-success.json new file mode 100644 index 00000000..00b019d2 --- /dev/null +++ b/test/mocks/checkout/paymentcapture-success.json @@ -0,0 +1,11 @@ +{ + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "paymentPspReference": "8536214160615591", + "pspReference": "8836226171638872", + "reference": "YOUR_UNIQUE_REFERENCE", + "status": "received", + "amount": { + "currency": "EUR", + "value": 2500 + } +} \ No newline at end of file diff --git a/test/mocks/checkout/paymentscancel-withoutreference-succes.json b/test/mocks/checkout/paymentscancel-withoutreference-succes.json new file mode 100644 index 00000000..744700ce --- /dev/null +++ b/test/mocks/checkout/paymentscancel-withoutreference-succes.json @@ -0,0 +1,7 @@ +{ + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "paymentReference": "Payment123", + "pspReference" : "8412534564722331", + "reference": "YourCancelReference", + "status" : "received" +} \ No newline at end of file diff --git a/test/mocks/checkout/paymentsreversals-success.json b/test/mocks/checkout/paymentsreversals-success.json new file mode 100644 index 00000000..2503aed0 --- /dev/null +++ b/test/mocks/checkout/paymentsreversals-success.json @@ -0,0 +1,7 @@ +{ + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", + "paymentPspReference": "8836183819713023", + "pspReference" : "8863534564726784", + "reference": "YourReversalReference", + "status" : "received" +} \ No newline at end of file From a2a69cbcda02a4cb68fd3680057cdeb00d7afdfc Mon Sep 17 00:00:00 2001 From: Eric Laff Date: Tue, 8 Jun 2021 22:13:29 +0200 Subject: [PATCH 05/10] Adding cancels action --- test/CheckoutTest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/CheckoutTest.py b/test/CheckoutTest.py index bffc5526..abc4487e 100644 --- a/test/CheckoutTest.py +++ b/test/CheckoutTest.py @@ -274,6 +274,7 @@ def test_payments_cancels_without_reference_error_mocked(self): def test_payments_cancels_success_mocked(self): requests = {"reference": "Your wro order number", "merchantAccount": "YOUR_MERCHANT_ACCOUNT"} + reference_id = "8836183819713023" self.adyen.client = self.test.create_client_from_file(200, requests, "test/mocks/" @@ -375,6 +376,7 @@ def test_payments_reversals_failure_mocked(self): "merchantAccount": "YOUR_MERCHANT_ACCOUNT" } psp_reference = "8836183819713023" + self.adyen.client = self.test.create_client_from_file(200, requests, "test/mocks/" "checkout/" From 9229e1523db45f43e1974ab879e4253631bbffb7 Mon Sep 17 00:00:00 2001 From: Eric Laff Date: Wed, 9 Mar 2022 11:40:16 +0100 Subject: [PATCH 06/10] paymentsCapture action to client, parameter order fixed, refund tests calling the correct action, cancels action fixed --- Adyen/client.py | 4 ++-- Adyen/services.py | 18 +++++++++--------- test/CheckoutTest.py | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Adyen/client.py b/Adyen/client.py index 28a74ce9..597693b3 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -172,8 +172,8 @@ def _determine_checkout_url(self, platform, action, path_param=None): action = "payments/details" if action == "paymentsResult": action = "payments/result" - if action == "paymentsCancelsWithoutReference": - action = "payments/cancels" + if action == "cancels": + action = "/cancels" if action == "paymentsCancelsWithReference": action = f"payments/{path_param}/cancels" if action == "paymentsReversals": diff --git a/Adyen/services.py b/Adyen/services.py index 16fe9428..b7653fef 100644 --- a/Adyen/services.py +++ b/Adyen/services.py @@ -329,19 +329,19 @@ def payment_result(self, request=None, **kwargs): action = "paymentsResult" return self.client.call_checkout_api(request, action, **kwargs) - def payment_captures(self, path_param, request=None, idempotency_key=None, **kwargs): - if path_param is None or "": + def payment_captures(self, request, idempotency_key=None, path_param=None, **kwargs): + if path_param == "": raise ValueError( 'must contain a pspReference in the path_param, path_param cannot be empty' ) action = "paymentsCapture" return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) - def payments_cancels_without_reference(self, request=None, idempotency_key=None, **kwargs): - action = "paymentsCancelsWithoutReference" + def payments_cancels_without_reference(self, request, idempotency_key=None, **kwargs): + action = "cancels" return self.client.call_checkout_api(request, action, idempotency_key, **kwargs) - def payments_cancels_with_reference(self, path_param, request=None, idempotency_key=None, **kwargs): + def payments_cancels_with_reference(self, request, idempotency_key=None, path_param=None, **kwargs): if path_param == "": raise ValueError( 'must contain a pspReference in the path_param, path_param cannot be empty' @@ -349,16 +349,16 @@ def payments_cancels_with_reference(self, path_param, request=None, idempotency_ action = "paymentsCancelsWithReference" return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) - def payments_reversals(self, path_param, request=None, idempotency_key=None, **kwargs): - if path_param is None or "": + def payments_reversals(self, request, idempotency_key=None, path_param=None, **kwargs): + if path_param == "": raise ValueError( 'must contain a pspReference in the path_param, path_param cannot be empty' ) action = "paymentsReversals" return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) - def payments_refunds(self, path_param, request=None, idempotency_key=None, **kwargs): - if path_param is None or "": + def payments_refunds(self, request, idempotency_key=None, path_param=None, **kwargs): + if path_param == "": raise ValueError( 'must contain a pspReference in the path_param, path_param cannot be empty' ) diff --git a/test/CheckoutTest.py b/test/CheckoutTest.py index abc4487e..7e18d6df 100644 --- a/test/CheckoutTest.py +++ b/test/CheckoutTest.py @@ -312,7 +312,7 @@ def test_payments_refunds_success_mocked(self): "paymentscancel-" "withoutreference-succes.json") - result = self.adyen.checkout.payments_cancels_without_reference(request=requests, path_param=psp_reference) + result = self.adyen.checkout.payments_refunds(request=requests, path_param=psp_reference) self.assertEqual(psp_reference, result.message["paymentReference"]) self.assertIsNotNone(result.message["pspReference"]) self.assertEqual("received", result.message['status']) @@ -330,13 +330,13 @@ def test_payments_refunds_error_mocked(self): "paymentsresult-error-invalid-" "data-payload-422.json") - result = self.adyen.checkout.payments_cancels_without_reference(request=requests, path_param=reference_id) + result = self.adyen.checkout.payments_refunds(request=requests, path_param=reference_id) self.assertEqual(422, result.message['status']) self.assertEqual("14_018", result.message['errorCode']) self.assertEqual("Invalid payload provided", result.message['message']) self.assertEqual("validation", result.message['errorType']) - def test_payments_refunds_raises_vaulue_error(self): + def test_payments_refunds_raises_value_error(self): requests = { "paymentReference": "Payment123", "merchantAccount": "YOUR_MERCHANT_ACCOUNT", @@ -348,7 +348,7 @@ def test_payments_refunds_raises_vaulue_error(self): "paymentscancel-" "withoutreference-succes.json") with self.assertRaises(ValueError) as exc: - self.adyen.checkout.payments_cancels_with_reference(request=requests, path_param="") + self.adyen.checkout.payments_refunds(request=requests, path_param="") self.assertEqual(exc.exception.__class__, ValueError) self.assertEqual(exc.exception.__str__(), 'must contain a pspReference in the path_param, path_param cannot ' 'be empty') From 570cda14bb6d0a8e10cda371890b0c1d00a6a138 Mon Sep 17 00:00:00 2001 From: Eric Laff Date: Thu, 10 Mar 2022 09:22:57 +0100 Subject: [PATCH 07/10] Removing 2nd codeql file --- .github/workflows/codeql-analysis2.yml | 71 -------------------------- 1 file changed, 71 deletions(-) delete mode 100644 .github/workflows/codeql-analysis2.yml diff --git a/.github/workflows/codeql-analysis2.yml b/.github/workflows/codeql-analysis2.yml deleted file mode 100644 index 30a6d939..00000000 --- a/.github/workflows/codeql-analysis2.yml +++ /dev/null @@ -1,71 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ develop ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ develop ] - schedule: - - cron: '0 0 * * *' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'python' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - queries: security-extended # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - # - name: Autobuild - # uses: github/codeql-action/autobuild@v1 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 From 757699517a81c8bd6eb8a08e70fda4a70d4a4d2a Mon Sep 17 00:00:00 2001 From: Eric Laff Date: Thu, 10 Mar 2022 09:28:13 +0100 Subject: [PATCH 08/10] modification action can capture --- Adyen/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Adyen/client.py b/Adyen/client.py index 597693b3..e3315905 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -176,6 +176,8 @@ def _determine_checkout_url(self, platform, action, path_param=None): action = "/cancels" if action == "paymentsCancelsWithReference": action = f"payments/{path_param}/cancels" + if action == "paymentsCapture": + action = f"/payments/{path_param}/captures" if action == "paymentsReversals": action = f"payments/{path_param}/reversals" if action == "payments/Refunds": From 186cb19c737adf40f9975164b5fd7ef0a7fb4c7a Mon Sep 17 00:00:00 2001 From: Eric Laff Date: Thu, 10 Mar 2022 09:38:17 +0100 Subject: [PATCH 09/10] Fixing capture modification method name --- Adyen/services.py | 2 +- test/CheckoutTest.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Adyen/services.py b/Adyen/services.py index b7653fef..c65c17ba 100644 --- a/Adyen/services.py +++ b/Adyen/services.py @@ -329,7 +329,7 @@ def payment_result(self, request=None, **kwargs): action = "paymentsResult" return self.client.call_checkout_api(request, action, **kwargs) - def payment_captures(self, request, idempotency_key=None, path_param=None, **kwargs): + def payments_captures(self, request, idempotency_key=None, path_param=None, **kwargs): if path_param == "": raise ValueError( 'must contain a pspReference in the path_param, path_param cannot be empty' diff --git a/test/CheckoutTest.py b/test/CheckoutTest.py index 7e18d6df..4bff0b3d 100644 --- a/test/CheckoutTest.py +++ b/test/CheckoutTest.py @@ -405,7 +405,7 @@ def test_payments_capture_success_mocked(self): "paymentcapture-" "success.json") - result = self.adyen.checkout.payment_captures(request=request, path_param=psp_reference) + result = self.adyen.checkout.payments_captures(request=request, path_param=psp_reference) self.assertEqual(psp_reference, result.message["paymentPspReference"]) self.assertIsNotNone(result.message["pspReference"]) self.assertEqual("received", result.message['status']) @@ -427,7 +427,7 @@ def test_payments_capture_error_mocked(self): "paymentsresult-error-invalid-" "data-payload-422.json") - result = self.adyen.checkout.payment_captures(request=request, path_param=psp_reference) + result = self.adyen.checkout.payments_captures(request=request, path_param=psp_reference) self.assertEqual(422, result.message['status']) self.assertEqual("14_018", result.message['errorCode']) self.assertEqual("Invalid payload provided", result.message['message']) From 9006c95e94f2ae72bb0aa81c854f43d60f4f25e0 Mon Sep 17 00:00:00 2001 From: Eric Laff Date: Thu, 10 Mar 2022 16:44:00 +0100 Subject: [PATCH 10/10] fix call_checkout_api param order for modification --- Adyen/services.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Adyen/services.py b/Adyen/services.py index c65c17ba..bba80ea5 100644 --- a/Adyen/services.py +++ b/Adyen/services.py @@ -335,7 +335,7 @@ def payments_captures(self, request, idempotency_key=None, path_param=None, **kw 'must contain a pspReference in the path_param, path_param cannot be empty' ) action = "paymentsCapture" - return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) + return self.client.call_checkout_api(request, action, idempotency_key, path_param, **kwargs) def payments_cancels_without_reference(self, request, idempotency_key=None, **kwargs): action = "cancels" @@ -347,7 +347,7 @@ def payments_cancels_with_reference(self, request, idempotency_key=None, path_pa 'must contain a pspReference in the path_param, path_param cannot be empty' ) action = "paymentsCancelsWithReference" - return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) + return self.client.call_checkout_api(request, action, idempotency_key, path_param, **kwargs) def payments_reversals(self, request, idempotency_key=None, path_param=None, **kwargs): if path_param == "": @@ -355,7 +355,7 @@ def payments_reversals(self, request, idempotency_key=None, path_param=None, **k 'must contain a pspReference in the path_param, path_param cannot be empty' ) action = "paymentsReversals" - return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) + return self.client.call_checkout_api(request, action, idempotency_key, path_param, **kwargs) def payments_refunds(self, request, idempotency_key=None, path_param=None, **kwargs): if path_param == "": @@ -363,7 +363,7 @@ def payments_refunds(self, request, idempotency_key=None, path_param=None, **kwa 'must contain a pspReference in the path_param, path_param cannot be empty' ) action = "paymentsRefunds" - return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs) + return self.client.call_checkout_api(request, action, idempotency_key, path_param, **kwargs) def origin_keys(self, request=None, **kwargs): action = "originKeys"