Skip to content

Commit a6f4bc6

Browse files
authored
Allow versions override at client init (#145)
We have a usecase where we need two Adyen clients using two different versions in the same code base. Overriding version using settings.xxx_VERSION does not allow us to use multiple API versions depending on our usecases. Adding the possibility to override the API versions in the Client constructor solves this issue
1 parent 0335aef commit a6f4bc6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Adyen/client.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ def __init__(
8383
http_force=None,
8484
live_endpoint_prefix=None,
8585
http_timeout=30,
86+
api_bin_lookup_version=None,
87+
api_checkout_utility_version=None,
88+
api_checkout_version=None,
89+
api_payment_version=None,
90+
api_payout_version=None,
91+
api_recurring_version=None,
8692
):
8793
self.username = username
8894
self.password = password
@@ -103,6 +109,12 @@ def __init__(
103109
self.http_force = http_force
104110
self.live_endpoint_prefix = live_endpoint_prefix
105111
self.http_timeout = http_timeout
112+
self.api_bin_lookup_version = api_bin_lookup_version or settings.API_BIN_LOOKUP_VERSION
113+
self.api_checkout_utility_version = api_checkout_utility_version or settings.API_CHECKOUT_UTILITY_VERSION
114+
self.api_checkout_version = api_checkout_version or settings.API_CHECKOUT_VERSION
115+
self.api_payment_version = api_payment_version or settings.API_PAYMENT_VERSION
116+
self.api_payout_version = api_payout_version or settings.API_PAYOUT_VERSION
117+
self.api_recurring_version = api_recurring_version or settings.API_RECURRING_VERSION
106118

107119
def _determine_api_url(self, platform, service, action):
108120
"""This returns the Adyen API endpoint based on the provided platform,
@@ -121,13 +133,13 @@ def _determine_api_url(self, platform, service, action):
121133
base_uri = settings.BASE_PAL_URL.format(platform)
122134

123135
if service == "Recurring":
124-
api_version = settings.API_RECURRING_VERSION
136+
api_version = self.api_recurring_version
125137
elif service == "Payout":
126-
api_version = settings.API_PAYOUT_VERSION
138+
api_version = self.api_payout_version
127139
elif service == "BinLookup":
128-
api_version = settings.API_BIN_LOOKUP_VERSION
140+
api_version = self.api_bin_lookup_version
129141
else:
130-
api_version = settings.API_PAYMENT_VERSION
142+
api_version = self.api_payment_version
131143
return '/'.join([base_uri, service, api_version, action])
132144

133145
@staticmethod
@@ -153,7 +165,7 @@ def _determine_checkout_url(self, platform, action):
153165
platform (str): Adyen platform, ie 'live' or 'test'.
154166
action (str): the API action to perform.
155167
"""
156-
api_version = settings.API_CHECKOUT_VERSION
168+
api_version = self.api_checkout_version
157169
if platform == "test":
158170
base_uri = settings.ENDPOINT_CHECKOUT_TEST
159171
elif self.live_endpoint_prefix is not None and platform == "live":
@@ -172,7 +184,7 @@ def _determine_checkout_url(self, platform, action):
172184
if action == "paymentsResult":
173185
action = "payments/result"
174186
if action == "originKeys":
175-
api_version = settings.API_CHECKOUT_UTILITY_VERSION
187+
api_version = self.api_checkout_utility_version
176188
if action == "paymentMethodsBalance":
177189
action = "paymentMethods/balance"
178190
if action == "ordersCancel":

0 commit comments

Comments
 (0)