Skip to content

Commit e424f4b

Browse files
[PW-8066]Add application info header (#216)
* Prepare the library to send in the application info header Add the application info header, remove the ugly workaround to send in the app info for checkout only, fix unit tests, adding the headers * change headers names * repair tests * Update test/CheckoutTest.py Co-authored-by: jillingk <93914435+jillingk@users.noreply.github.com> --------- Co-authored-by: jillingk <93914435+jillingk@users.noreply.github.com>
1 parent 1454090 commit e424f4b

11 files changed

+57
-53
lines changed

Adyen/client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def __str__(self):
4646

4747
class AdyenClient(object):
4848
IDEMPOTENCY_HEADER_NAME = 'Idempotency-Key'
49+
APPLICATION_INFO_HEADER_NAME = 'adyen-library-name'
50+
APPLICATION_VERSION_HEADER_NAME = 'adyen-library-version'
4951
"""A requesting client that interacts with Adyen. This class holds the
5052
adyen logic of Adyen HTTP API communication. This is the object that can
5153
maintain its own username, password, merchant_account, hmac and skin_code.
@@ -402,9 +404,14 @@ def call_adyen_api(
402404
"version": settings.LIB_VERSION
403405
}
404406
}
407+
408+
headers = {
409+
self.APPLICATION_INFO_HEADER_NAME: settings.LIB_NAME,
410+
self.APPLICATION_VERSION_HEADER_NAME: settings.LIB_VERSION
411+
}
412+
405413
# Adyen requires this header to be set and uses the combination of
406414
# merchant account and merchant reference to determine uniqueness.
407-
headers = {}
408415
if idempotency_key:
409416
headers[self.IDEMPOTENCY_HEADER_NAME] = idempotency_key
410417

test/BinLookupTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_get_cost_estimate_success(self):
5555
'POST',
5656
'https://pal-test.adyen.com/pal/servlet/'
5757
f'BinLookup/{self.binLookup_version}/getCostEstimate',
58-
headers={},
58+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
5959
json={
6060
'merchantAccount': 'YourMerchantAccount',
6161
'amount': '1000',

test/CheckoutTest.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,9 @@ def test_payments_error_mocked(self):
9696
self.adyen.client.http_client.request.assert_called_once_with(
9797
'POST',
9898
'https://checkout-test.adyen.com/{}/payments'.format(self.checkout_version),
99-
headers={},
99+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
100100
json={
101101
'returnUrl': 'https://your-company.com/...',
102-
u'applicationInfo': {
103-
u'adyenLibrary': {
104-
u'version': f"{self.lib_version}",
105-
u'name': 'adyen-python-api-library'
106-
}
107-
},
108102
'reference': '54431',
109103
'merchantAccount': 'YourMerchantAccount',
110104
'amount': {'currency': 'EUR', 'value': '100000'},
@@ -115,7 +109,8 @@ def test_payments_error_mocked(self):
115109
'expiryMonth': '08',
116110
'type': 'scheme',
117111
'cvc': '737'
118-
}
112+
},
113+
'applicationInfo': {'adyenLibrary': {'name': 'adyen-python-api-library', 'version': settings.LIB_VERSION}}
119114
},
120115
xapikey='YourXapikey'
121116
)
@@ -140,7 +135,7 @@ def test_payments_details_success_mocked(self):
140135
self.adyen.client.http_client.request.assert_called_once_with(
141136
'POST',
142137
u'https://checkout-test.adyen.com/{}/payments/details'.format(self.checkout_version),
143-
headers={},
138+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
144139
json={
145140
'paymentData': 'Hee57361f99....',
146141
'details': {'MD': 'sdfsdfsdf...', 'PaRes': 'sdkfhskdjfsdf...'}
@@ -398,7 +393,7 @@ def test_payments_capture_success_mocked(self):
398393
f'https://checkout-test.adyen.com/{self.checkout_version}/payments/{psp_reference}/captures',
399394
json=request,
400395
xapikey='YourXapikey',
401-
headers={}
396+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
402397
)
403398
self.assertEqual(psp_reference, result.message["paymentPspReference"])
404399
self.assertIsNotNone(result.message["pspReference"])
@@ -440,7 +435,8 @@ def test_orders_success(self):
440435
f'https://checkout-test.adyen.com/{self.checkout_version}/orders',
441436
json=request,
442437
xapikey='YourXapikey',
443-
headers={}
438+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
439+
444440
)
445441
self.assertEqual("8515930288670953", result.message['pspReference'])
446442
self.assertEqual("Success", result.message['resultCode'])
@@ -461,7 +457,7 @@ def test_orders_cancel_success(self):
461457
f'https://checkout-test.adyen.com/{self.checkout_version}/orders/cancel',
462458
json=request,
463459
xapikey='YourXapikey',
464-
headers={}
460+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
465461
)
466462
self.assertEqual("8515931182066678", result.message['pspReference'])
467463
self.assertEqual("Received", result.message['resultCode'])
@@ -480,7 +476,7 @@ def test_paymentmethods_balance_success(self):
480476
f'https://checkout-test.adyen.com/{self.checkout_version}/paymentMethods/balance',
481477
json=request,
482478
xapikey='YourXapikey',
483-
headers={}
479+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
484480
)
485481
self.assertEqual("851611111111713K", result.message['pspReference'])
486482
self.assertEqual("Success", result.message['resultCode'])
@@ -514,9 +510,10 @@ def test_sessions_error(self):
514510
self.adyen.client.http_client.request.assert_called_once_with(
515511
'POST',
516512
f'https://checkout-test.adyen.com/{self.checkout_version}/sessions',
517-
json={'merchantAccount': 'YourMerchantAccount', 'applicationInfo': {'adyenLibrary': {'name': 'adyen-python-api-library', 'version': '7.1.1'}}},
513+
json={'merchantAccount': 'YourMerchantAccount',
514+
'applicationInfo': {'adyenLibrary': {'name': 'adyen-python-api-library', 'version': settings.LIB_VERSION}}},
518515
xapikey='YourXapikey',
519-
headers={}
516+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
520517
)
521518
self.assertEqual(422, result.message['status'])
522519
self.assertEqual("130", result.message['errorCode'])
@@ -561,7 +558,7 @@ def test_payment_link(self):
561558
self.adyen.client.http_client.request.assert_called_once_with(
562559
'POST',
563560
f'https://checkout-test.adyen.com/{self.checkout_version}/paymentLinks',
564-
headers={},
561+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
565562
xapikey='YourXapikey',
566563
json=request
567564
)
@@ -578,7 +575,7 @@ def test_get_payment_link(self):
578575
self.adyen.client.http_client.request.assert_called_once_with(
579576
'GET',
580577
f'https://checkout-test.adyen.com/{self.checkout_version}/paymentLinks/{id}',
581-
headers={},
578+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
582579
xapikey="YourXapikey",
583580
json=None
584581
)
@@ -597,7 +594,7 @@ def test_update_payment_link(self):
597594
self.adyen.client.http_client.request.assert_called_once_with(
598595
'PATCH',
599596
f'https://checkout-test.adyen.com/{self.checkout_version}/paymentLinks/{id}',
600-
headers={},
597+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
601598
xapikey="YourXapikey",
602599
json=request
603600
)

test/DataProtectionTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_data_erasure(self):
3131
'POST',
3232
f'https://ca-test.adyen.com/ca/services/DataProtectionService/{self.data_protection_version}'
3333
'/requestSubjectErasure',
34-
headers={},
34+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
3535
xapikey="YourXapikey",
3636
json=request
3737
)

test/LegalEntityManagementTest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_creating_legal_entity(self):
4545
self.adyen.client.http_client.request.assert_called_once_with(
4646
'POST',
4747
f'https://kyc-test.adyen.com/lem/{self.lem_version}/legalEntities',
48-
headers={},
48+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
4949
json=request,
5050
xapikey="YourXapikey"
5151
)
@@ -59,7 +59,7 @@ def test_get_transfer_instrument(self):
5959
self.adyen.client.http_client.request.assert_called_once_with(
6060
'GET',
6161
f'https://kyc-test.adyen.com/lem/{self.lem_version}/transferInstruments/{instrumentId}',
62-
headers={},
62+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
6363
json=None,
6464
xapikey="YourXapikey"
6565
)
@@ -81,7 +81,7 @@ def test_update_business_line(self):
8181
self.adyen.client.http_client.request.assert_called_once_with(
8282
'PATCH',
8383
f'https://kyc-test.adyen.com/lem/{self.lem_version}/businessLines/{businessLineId}',
84-
headers={},
84+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
8585
json=request,
8686
xapikey="YourXapikey"
8787
)
@@ -99,7 +99,7 @@ def test_accept_terms_of_service(self):
9999
self.adyen.client.http_client.request.assert_called_once_with(
100100
'PATCH',
101101
f'https://kyc-test.adyen.com/lem/{self.lem_version}/legalEntities/{legalEntityId}/termsOfService/{documentId}',
102-
headers={},
102+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
103103
json=request,
104104
xapikey="YourXapikey"
105105
)

test/ManagementTest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_get_company_account(self):
3131
self.adyen.client.http_client.request.assert_called_once_with(
3232
'GET',
3333
f'https://management-test.adyen.com/{self.management_version}/companies/{id}',
34-
headers={},
34+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
3535
json=None,
3636
xapikey="YourXapikey"
3737
)
@@ -54,7 +54,7 @@ def test_my_api_credential_api(self):
5454
self.adyen.client.http_client.request.assert_called_once_with(
5555
'DELETE',
5656
f'https://management-test.adyen.com/{self.management_version}/me/allowedOrigins/{originId}',
57-
headers={},
57+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
5858
json=None,
5959
xapikey="YourXapikey"
6060
)
@@ -81,7 +81,7 @@ def test_update_a_store(self):
8181
self.adyen.client.http_client.request.assert_called_once_with(
8282
'PATCH',
8383
f'https://management-test.adyen.com/{self.management_version}/merchants/{merchantId}/stores/{storeId}',
84-
headers={},
84+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
8585
json=request,
8686
xapikey="YourXapikey"
8787
)
@@ -117,7 +117,7 @@ def test_create_a_user(self):
117117
'POST',
118118
f'https://management-test.adyen.com/{self.management_version}/companies/{companyId}/users',
119119
json=request,
120-
headers={},
120+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
121121
xapikey="YourXapikey"
122122
)
123123

@@ -150,7 +150,7 @@ def test_query_paramaters(self):
150150
self.adyen.client.http_client.request.assert_called_once_with(
151151
'GET',
152152
f'https://management-test.adyen.com/{self.management_version}/companies/{companyId}/merchants?pageNumber=1&pageSize=10',
153-
headers={},
153+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
154154
json=None,
155155
xapikey="YourXapikey"
156156
)

test/RecurringTest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_list_recurring_details(self):
3434
self.adyen.client.http_client.request.assert_called_once_with(
3535
'POST',
3636
f'https://pal-test.adyen.com/pal/servlet/Recurring/{self.recurring_version}/listRecurringDetails',
37-
headers={},
37+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
3838
json=request,
3939
username='YourWSUser',
4040
password='YourWSPassword'
@@ -61,7 +61,7 @@ def test_disable(self):
6161
self.adyen.client.http_client.request.assert_called_once_with(
6262
'POST',
6363
f'https://pal-test.adyen.com/pal/servlet/Recurring/{self.recurring_version}/disable',
64-
headers={},
64+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
6565
json=request,
6666
username='YourWSUser',
6767
password='YourWSPassword',

test/StoredValueTest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def issue(self):
3535
self.adyen.client.http_client.request.assert_called_once_with(
3636
'POST',
3737
f'https://pal-test.adyen.com/pal/servlet/StoredValue/{self.stored_value_version}/issue',
38-
headers={},
38+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
3939
json=request,
4040
xapikey="YourXapikey"
4141
)
@@ -63,7 +63,7 @@ def test_activate_giftcard(self):
6363
self.adyen.client.http_client.request.assert_called_once_with(
6464
'POST',
6565
f'https://pal-test.adyen.com/pal/servlet/StoredValue/{self.stored_value_version}/changeStatus',
66-
headers={},
66+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
6767
json=request,
6868
xapikey="YourXapikey"
6969
)
@@ -90,7 +90,7 @@ def test_load_funds(self):
9090
self.adyen.client.http_client.request.assert_called_once_with(
9191
'POST',
9292
f'https://pal-test.adyen.com/pal/servlet/StoredValue/{self.stored_value_version}/load',
93-
headers={},
93+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
9494
json=request,
9595
xapikey="YourXapikey"
9696
)
@@ -112,7 +112,7 @@ def test_check_balance(self):
112112
self.adyen.client.http_client.request.assert_called_once_with(
113113
'POST',
114114
f'https://pal-test.adyen.com/pal/servlet/StoredValue/{self.stored_value_version}/checkBalance',
115-
headers={},
115+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
116116
json=request,
117117
xapikey="YourXapikey"
118118
)
@@ -138,7 +138,7 @@ def test_merge_balance(self):
138138
self.adyen.client.http_client.request.assert_called_once_with(
139139
'POST',
140140
f'https://pal-test.adyen.com/pal/servlet/StoredValue/{self.stored_value_version}/mergeBalance',
141-
headers={},
141+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
142142
json=request,
143143
xapikey="YourXapikey"
144144
)
@@ -155,7 +155,7 @@ def test_void_transaction(self):
155155
self.adyen.client.http_client.request.assert_called_once_with(
156156
'POST',
157157
f'https://pal-test.adyen.com/pal/servlet/StoredValue/{self.stored_value_version}/voidTransaction',
158-
headers={},
158+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
159159
json=request,
160160
xapikey="YourXapikey"
161161
)

test/TerminalTest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_assign_terminals(self):
3535
self.client.http_client.request.assert_called_once_with(
3636
"POST",
3737
f"https://postfmapi-test.adyen.com/postfmapi/terminal/{self.terminal_version}/assignTerminals",
38-
headers={},
38+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
3939
json={
4040
"companyAccount": "YOUR_COMPANY_ACCOUNT",
4141
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
@@ -79,7 +79,7 @@ def test_find_terminal(self):
7979
self.client.http_client.request.assert_called_once_with(
8080
"POST",
8181
f"https://postfmapi-test.adyen.com/postfmapi/terminal/{self.terminal_version}/findTerminal",
82-
headers={},
82+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
8383
json={
8484
"terminal": "P400Plus-275479597",
8585
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
@@ -127,7 +127,7 @@ def test_get_stores_under_account(self):
127127
self.client.http_client.request.assert_called_once_with(
128128
"POST",
129129
f"https://postfmapi-test.adyen.com/postfmapi/terminal/{self.terminal_version}/getStoresUnderAccount",
130-
headers={},
130+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
131131
json={
132132
"companyAccount": "YOUR_COMPANY_ACCOUNT",
133133
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
@@ -152,7 +152,7 @@ def test_get_terminal_details(self):
152152
self.client.http_client.request.assert_called_once_with(
153153
"POST",
154154
f"https://postfmapi-test.adyen.com/postfmapi/terminal/{self.terminal_version}/getTerminalDetails",
155-
headers={},
155+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
156156
json={
157157
"terminal": "P400Plus-275479597",
158158
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
@@ -204,7 +204,7 @@ def test_get_terminals_under_account(self):
204204
self.client.http_client.request.assert_called_once_with(
205205
"POST",
206206
f"https://postfmapi-test.adyen.com/postfmapi/terminal/{self.terminal_version}/getTerminalsUnderAccount",
207-
headers={},
207+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
208208
json={
209209
"companyAccount": "YOUR_COMPANY_ACCOUNT",
210210
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
@@ -241,7 +241,7 @@ def test_get_terminals_under_account_store(self):
241241
self.client.http_client.request.assert_called_once_with(
242242
"POST",
243243
f"https://postfmapi-test.adyen.com/postfmapi/terminal/{self.terminal_version}/getTerminalsUnderAccount",
244-
headers={},
244+
headers={'adyen-library-name': 'adyen-python-api-library', 'adyen-library-version': settings.LIB_VERSION},
245245
json={
246246
"companyAccount": "YOUR_COMPANY_ACCOUNT",
247247
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",

0 commit comments

Comments
 (0)