Skip to content

Commit 8fc8817

Browse files
committed
Add functionality to update headers from kwargs and adjust README accordingly
1 parent aebea6a commit 8fc8817

File tree

4 files changed

+51
-29
lines changed

4 files changed

+51
-29
lines changed

Adyen/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ def call_adyen_api(
345345
if idempotency_key:
346346
headers[self.IDEMPOTENCY_HEADER_NAME] = idempotency_key
347347

348+
# Additional headers provided via the `header_parameters` keyword argument
349+
# Pass as a keyword argument in the method call.
350+
if 'header_parameters' in kwargs:
351+
headers.update(kwargs['header_parameters'])
352+
kwargs.pop('header_parameters')
353+
348354
url = self._determine_api_url(platform, endpoint)
349355

350356
if 'query_parameters' in kwargs:

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ pass the dictionary to the method as an additional argument.
150150
adyen.management.account_company_level_api.get_companies(query_parameters=query_parameters)
151151
~~~~
152152

153+
### Using Header Parameters
154+
155+
Define a dictionary named containing the headers you want to include in your request.
156+
157+
~~~~ pyhton
158+
header_parameters = {
159+
"Var1": "Var2",
160+
"Var2": "Var1"
161+
}
162+
~~~~
163+
164+
Pass the dictionary as an additional argument to the method where you make the API call.
165+
166+
~~~~ pyhton
167+
adyen.checkout.payments_api.payments(header_parameters=headers)
168+
~~~~
169+
153170
### Handling exceptions
154171

155172
Adyen service exceptions extend the AdyenError class. After you catch this exception, you can access the

test/ClientTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class TestClient(unittest.TestCase):
1313

1414
client = adyen.client
1515
test = BaseTest(adyen)
16-
client.xapikey = "YourXapikey"
16+
client.xapikey = "YOUR_API_KEY"
1717
client.platform = "test"
1818
lib_version = settings.LIB_VERSION

test/UtilTest.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
is_valid_hmac_notification,
88
get_query
99
)
10+
1011
try:
1112
from BaseTest import BaseTest
1213
except ImportError:
@@ -65,14 +66,13 @@ def test_webhooks_with_slashes(self):
6566
mixed_notification = load(file)
6667
self.assertTrue(is_valid_hmac_notification(mixed_notification, hmac_key))
6768

68-
6969
def test_query_string_creation(self):
7070
query_parameters = {
71-
"pageSize":7,
72-
"pageNumber":3
71+
"pageSize": 7,
72+
"pageNumber": 3
7373
}
7474
query_string = get_query(query_parameters)
75-
self.assertEqual(query_string,'?pageSize=7&pageNumber=3')
75+
self.assertEqual(query_string, '?pageSize=7&pageNumber=3')
7676

7777
def test_passing_xapikey_in_method(self):
7878
request = {'merchantAccount': "YourMerchantAccount"}
@@ -96,10 +96,10 @@ def test_custom_version(self):
9696
self.test = BaseTest(self.adyen)
9797
self.client.platform = "test"
9898
self.adyen.client = self.test.create_client_from_file(200, request,
99-
"test/mocks/"
100-
"checkout/"
101-
"paymentmethods"
102-
"-success.json")
99+
"test/mocks/"
100+
"checkout/"
101+
"paymentmethods"
102+
"-success.json")
103103
result = self.adyen.checkout.payments_api.payment_methods(request, xapikey="YourXapikey")
104104
self.adyen.client.http_client.request.assert_called_once_with(
105105
'POST',
@@ -111,25 +111,24 @@ def test_custom_version(self):
111111

112112
def test_is_valid_hmac_notification_removes_additional_data(self):
113113
notification = {
114-
"live":"false",
115-
"notificationItems":[
116-
{
117-
"NotificationRequestItem":{
118-
"additionalData":{
119-
"hmacSignature":"11aa",
120-
"fraudResultType":"GREEN",
121-
"fraudManualReview": "false",
122-
"totalFraudScore":"75"
123-
},
124-
"amount":{
125-
"currency":"USD",
126-
"value":10000
127-
},
128-
"success":"true"
129-
130-
}
131-
}
132-
]}
114+
"live": "false",
115+
"notificationItems": [
116+
{
117+
"NotificationRequestItem": {
118+
"additionalData": {
119+
"hmacSignature": "11aa",
120+
"fraudResultType": "GREEN",
121+
"fraudManualReview": "false",
122+
"totalFraudScore": "75"
123+
},
124+
"amount": {
125+
"currency": "USD",
126+
"value": 10000
127+
},
128+
"success": "true"
129+
130+
}
131+
}
132+
]}
133133
is_valid_hmac_notification(notification, "11aa")
134134
self.assertIsNotNone(notification['notificationItems'][0]['NotificationRequestItem']['additionalData'])
135-

0 commit comments

Comments
 (0)