Skip to content

Commit 18f4bf7

Browse files
authored
BIN Lookup API: Specify version. (#108)
Following a recent PR to add support for the BINLookup API, it seems I've forgot to specify the API version. this caused call failures as the BINLookup API only supports v40/v50 versions while the default version is v49.
1 parent 167314d commit 18f4bf7

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

Adyen/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def _determine_api_url(platform, service, action):
108108
api_version = settings.API_RECURRING_VERSION
109109
elif service == "Payout":
110110
api_version = settings.API_PAYOUT_VERSION
111+
elif service == "BinLookup":
112+
api_version = settings.API_BIN_LOOKUP_VERSION
111113
else:
112114
api_version = settings.API_PAYMENT_VERSION
113115
return '/'.join([base_uri, service, api_version, action])

Adyen/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com"
55
ENDPOINT_CHECKOUT_LIVE_SUFFIX = "https://{}-checkout-live" \
66
".adyenpayments.com/checkout"
7+
API_BIN_LOOKUP_VERSION = "v50"
78
API_CHECKOUT_VERSION = "v49"
89
API_CHECKOUT_UTILITY_VERSION = "v1"
910
API_RECURRING_VERSION = "v25"

test/mocks/BinLookupTest.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
import Adyen
1+
from unittest.mock import ANY
22
import unittest
3+
34
from BaseTest import BaseTest
5+
import Adyen
6+
7+
8+
REQUEST_KWARGS = {
9+
'merchantAccount': 'YourMerchantAccount',
10+
'amount': '1000'
11+
}
412

513

614
class TestBinLookup(unittest.TestCase):
@@ -14,11 +22,7 @@ class TestBinLookup(unittest.TestCase):
1422
client.app_name = "appname"
1523

1624
def test_get_cost_estimate_success(self):
17-
request = {
18-
'merchantAccount': 'YourMerchantAccount',
19-
'amount': '1000'
20-
}
21-
25+
self.ady.client.http_client.request.reset_mock()
2226
expected = {
2327
'cardBin': {
2428
'bin': '458012',
@@ -39,29 +43,40 @@ def test_get_cost_estimate_success(self):
3943

4044
self.ady.client = self.test.create_client_from_file(
4145
status=200,
42-
request=request,
46+
request=REQUEST_KWARGS,
4347
filename='test/mocks/binlookup/getcostestimate-success.json'
4448
)
4549

46-
result = self.ady.binlookup.get_cost_estimate(request)
50+
result = self.ady.binlookup.get_cost_estimate(REQUEST_KWARGS)
4751
self.assertEqual(expected, result.message)
52+
self.ady.client.http_client.request.assert_called_once_with(
53+
'https://pal-test.adyen.com/pal/servlet/'
54+
'BinLookup/v50/getCostEstimate',
55+
headers={},
56+
json={
57+
'merchantAccount': 'YourMerchantAccount',
58+
'amount': '1000', 'applicationInfo': {
59+
'adyenLibrary': {
60+
'name': 'adyen-python-api-library',
61+
'version': ANY
62+
}
63+
}
64+
},
65+
password='YourWSPassword',
66+
username='YourWSUser'
67+
)
4868

4969
def test_get_cost_estimate_error_mocked(self):
50-
request = {
51-
'merchantAccount': 'YourMerchantAccount',
52-
'amount': '1000'
53-
}
54-
5570
self.ady.client = self.test.create_client_from_file(
5671
status=200,
57-
request=request,
72+
request=REQUEST_KWARGS,
5873
filename=(
5974
"test/mocks/binlookup/"
6075
"getcostestimate-error-invalid-data-422.json"
6176
)
6277
)
6378

64-
result = self.ady.binlookup.get_cost_estimate(request)
79+
result = self.ady.binlookup.get_cost_estimate(REQUEST_KWARGS)
6580
self.assertEqual(422, result.message['status'])
6681
self.assertEqual("101", result.message['errorCode'])
6782
self.assertEqual("Invalid card number", result.message['message'])

0 commit comments

Comments
 (0)