From d871836b7bb6dea280ba27160d2f1a891bb083ac Mon Sep 17 00:00:00 2001 From: alainburindi Date: Tue, 23 Nov 2021 15:24:41 +0200 Subject: [PATCH] shallow copy the payload --- Adyen/client.py | 20 +++++++++++++------- Adyen/util.py | 4 ++++ test/CheckoutTest.py | 2 +- test/UtilTest.py | 12 +++++++++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Adyen/client.py b/Adyen/client.py index 4c3d1d04..59406dde 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -109,12 +109,18 @@ def __init__( self.http_force = http_force self.live_endpoint_prefix = live_endpoint_prefix self.http_timeout = http_timeout - self.api_bin_lookup_version = api_bin_lookup_version or settings.API_BIN_LOOKUP_VERSION - self.api_checkout_utility_version = api_checkout_utility_version or settings.API_CHECKOUT_UTILITY_VERSION - self.api_checkout_version = api_checkout_version or settings.API_CHECKOUT_VERSION - self.api_payment_version = api_payment_version or settings.API_PAYMENT_VERSION - self.api_payout_version = api_payout_version or settings.API_PAYOUT_VERSION - self.api_recurring_version = api_recurring_version or settings.API_RECURRING_VERSION + self.api_bin_lookup_version = api_bin_lookup_version or \ + settings.API_BIN_LOOKUP_VERSION + self.api_checkout_utility_version = api_checkout_utility_version or \ + settings.API_CHECKOUT_UTILITY_VERSION + self.api_checkout_version = api_checkout_version or \ + settings.API_CHECKOUT_VERSION + self.api_payment_version = api_payment_version or \ + settings.API_PAYMENT_VERSION + self.api_payout_version = api_payout_version or \ + settings.API_PAYOUT_VERSION + self.api_recurring_version = api_recurring_version or \ + settings.API_RECURRING_VERSION def _determine_api_url(self, platform, service, action): """This returns the Adyen API endpoint based on the provided platform, @@ -594,7 +600,7 @@ def _handle_response(self, url, raw_response, raw_request, Returns: AdyenResult: Result object if successful. """ - if (status_code != 200 and status_code != 201): + 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: diff --git a/Adyen/util.py b/Adyen/util.py index b9cb9520..4efe6243 100644 --- a/Adyen/util.py +++ b/Adyen/util.py @@ -35,6 +35,8 @@ def escape_val(val): def is_valid_hmac(dict_object, hmac_key): + dict_object = dict_object.copy() + if 'additionalData' in dict_object: if dict_object['additionalData']['hmacSignature'] == "": raise ValueError("Must Provide hmacSignature in additionalData") @@ -85,6 +87,8 @@ def escape_val(val): def is_valid_hmac_notification(dict_object, hmac_key): + dict_object = dict_object.copy() + if 'additionalData' in dict_object: if dict_object['additionalData']['hmacSignature'] == "": raise ValueError("Must Provide hmacSignature in additionalData") diff --git a/test/CheckoutTest.py b/test/CheckoutTest.py index 534aada8..844a9c13 100644 --- a/test/CheckoutTest.py +++ b/test/CheckoutTest.py @@ -300,4 +300,4 @@ def test_sessions_error(self): 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 + self.assertEqual("validation", result.message['errorType']) diff --git a/test/UtilTest.py b/test/UtilTest.py index 9cd9b334..488c6c12 100644 --- a/test/UtilTest.py +++ b/test/UtilTest.py @@ -34,6 +34,9 @@ def test_hpp_request_item_hmac(self): self.assertEqual(hmac_calculation_str, expected_hmac) request['additionalData'] = {'hmacSignature': hmac_calculation_str} hmac_validate = is_valid_hmac(request, key) + self.assertIn('additionalData', request) + self.assertDictEqual(request['additionalData'], + {'hmacSignature': hmac_calculation_str}) self.assertTrue(hmac_validate) def test_notification_request_item_hmac(self): @@ -49,9 +52,9 @@ def test_notification_request_item_hmac(self): "success": "true", "eventDate": "2019-05-06T17:15:34.121+02:00", "operations": [ - "CANCEL", - "CAPTURE", - "REFUND" + "CANCEL", + "CAPTURE", + "REFUND" ], "paymentMethod": "visa", } @@ -64,4 +67,7 @@ def test_notification_request_item_hmac(self): self.assertEqual(hmac_calculation_str, expected_hmac) request['additionalData'] = {'hmacSignature': hmac_calculation_str} hmac_validate = is_valid_hmac_notification(request, key) + self.assertIn('additionalData', request) + self.assertDictEqual(request['additionalData'], + {'hmacSignature': hmac_calculation_str}) self.assertTrue(hmac_validate)