Skip to content

Commit e827bad

Browse files
Merge pull request #264 from Adyen/automation/release
Release v9.0.3
2 parents d81177b + 81ad204 commit e827bad

File tree

85 files changed

+498
-651
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+498
-651
lines changed

Adyen/client.py

Lines changed: 72 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
AdyenAPIUnprocessableEntity,
1717
AdyenEndpointInvalidFormat)
1818
from . import settings
19-
from re import match
19+
import re
2020

2121

2222
class AdyenResult(object):
@@ -84,7 +84,6 @@ def __init__(
8484
live_endpoint_prefix=None,
8585
http_timeout=30,
8686
api_bin_lookup_version=None,
87-
api_checkout_utility_version=None,
8887
api_checkout_version=None,
8988
api_management_version=None,
9089
api_payment_version=None,
@@ -96,6 +95,7 @@ def __init__(
9695
api_transfers_version=None,
9796
api_stored_value_version=None,
9897
api_balance_platform_version=None,
98+
9999
):
100100
self.username = username
101101
self.password = password
@@ -115,130 +115,41 @@ def __init__(
115115
self.http_force = http_force
116116
self.live_endpoint_prefix = live_endpoint_prefix
117117
self.http_timeout = http_timeout
118-
self.api_bin_lookup_version = api_bin_lookup_version or settings.API_BIN_LOOKUP_VERSION
119-
self.api_checkout_utility_version = api_checkout_utility_version or settings.API_CHECKOUT_UTILITY_VERSION
120-
self.api_checkout_version = api_checkout_version or settings.API_CHECKOUT_VERSION
121-
self.api_management_version = api_management_version or settings.API_MANAGEMENT_VERSION
122-
self.api_payment_version = api_payment_version or settings.API_PAYMENT_VERSION
123-
self.api_payout_version = api_payout_version or settings.API_PAYOUT_VERSION
124-
self.api_recurring_version = api_recurring_version or settings.API_RECURRING_VERSION
125-
self.api_terminal_version = api_terminal_version or settings.API_TERMINAL_VERSION
126-
self.api_legal_entity_management_version = api_legal_entity_management_version or settings.API_LEGAL_ENTITY_MANAGEMENT_VERSION
127-
self.api_data_protection_version = api_data_protection_version or settings.API_DATA_PROTECION_VERSION
128-
self.api_transfers_version = api_transfers_version or settings.API_TRANSFERS_VERSION
129-
self.api_stored_value_version = api_stored_value_version or settings.API_STORED_VALUE_VERSION
130-
self.api_balance_platform_version = api_balance_platform_version or settings.API_BALANCE_PLATFORM_VERSION
131-
132-
def _determine_base_url_and_version(self, platform, service):
133-
134-
live_pal_url = settings.PAL_LIVE_ENDPOINT_URL_TEMPLATE
135-
live_checkout_url = settings.ENDPOINT_CHECKOUT_LIVE_SUFFIX
136-
137-
if platform == 'live' and self.live_endpoint_prefix:
138-
live_pal_url = live_pal_url.format(live_prefix=self.live_endpoint_prefix)
139-
live_checkout_url = live_checkout_url.format(live_prefix=self.live_endpoint_prefix)
140-
141-
versions_and_urls = {
142-
'recurring': {
143-
'version': self.api_recurring_version,
144-
'base_url': {
145-
'live': live_pal_url + '/Recurring',
146-
'test': settings.PAL_TEST_URL + '/Recurring',
147-
}
148-
},
149-
'payouts': {
150-
'version': self.api_payout_version,
151-
'base_url': {
152-
'live': live_pal_url + '/Payout',
153-
'test': settings.PAL_TEST_URL + '/Payout'
154-
}
155-
},
156-
'binlookup': {
157-
'version': self.api_bin_lookup_version,
158-
'base_url': {
159-
'live': live_pal_url + '/BinLookup',
160-
'test': settings.PAL_TEST_URL + '/BinLookup'
161-
}
162-
},
163-
'terminal': {
164-
'version': self.api_terminal_version,
165-
'base_url': {
166-
'live': settings.BASE_TERMINAL_URL.format(platform),
167-
'test': settings.BASE_TERMINAL_URL.format(platform)
168-
}
169-
},
170-
'payments': {
171-
'version': self.api_payment_version,
172-
'base_url': {
173-
'live': live_pal_url + '/Payment',
174-
'test': settings.PAL_TEST_URL + '/Payment'
175-
}
176-
},
177-
'checkout': {
178-
'version': self.api_checkout_version,
179-
'base_url': {
180-
'live': live_checkout_url,
181-
'test': settings.ENDPOINT_CHECKOUT_TEST
182-
}
183-
},
184-
'management': {
185-
'version': self.api_management_version,
186-
'base_url': {
187-
'live': settings.BASE_MANAGEMENT_URL.format(platform),
188-
'test': settings.BASE_MANAGEMENT_URL.format(platform)
189-
}
190-
},
191-
'legalEntityManagement': {
192-
'version': self.api_legal_entity_management_version,
193-
'base_url': {
194-
'live': settings.BASE_LEGAL_ENTITY_MANAGEMENT_URL.format(platform),
195-
'test': settings.BASE_LEGAL_ENTITY_MANAGEMENT_URL.format(platform)
196-
},
197-
},
198-
'balancePlatform': {
199-
'version': self.api_balance_platform_version,
200-
'base_url': {
201-
'live': settings.BASE_CONFIGURATION_URL.format(platform),
202-
'test': settings.BASE_CONFIGURATION_URL.format(platform)
203-
}
204-
},
205-
'dataProtection': {
206-
'version': self.api_data_protection_version,
207-
'base_url': {
208-
'live': settings.BASE_DATA_PROTECION_URL.format(platform),
209-
'test': settings.BASE_DATA_PROTECION_URL.format(platform)
210-
}
211-
},
212-
'transfers': {
213-
'version': self.api_transfers_version,
214-
'base_url': {
215-
'live': settings.BASE_BTL_URL.format(platform),
216-
'test': settings.BASE_BTL_URL.format(platform)
217-
}
218-
},
219-
'storedValue': {
220-
'version': self.api_stored_value_version,
221-
'base_url': {
222-
'live': settings.BASE_STORED_VALUE_URL.format(platform),
223-
'test': settings.BASE_STORED_VALUE_URL.format(platform)
224-
}
225-
},
226-
}
227-
228-
version = versions_and_urls[service]['version']
229-
base_url = versions_and_urls[service]['base_url'][platform]
230-
# Match urls that require a live prefix and do not have one
231-
232-
if platform == 'live' and '{live_prefix}' in base_url:
233-
errorstring = "Please set your live suffix. You can set it by running " \
234-
"adyen.client.live_endpoint_prefix = 'Your live suffix'"
235-
raise AdyenEndpointInvalidFormat(errorstring)
236-
237-
return version, base_url
238-
239-
def _determine_api_url(self, platform, service, endpoint):
240-
api_version, base_url = self._determine_base_url_and_version(platform, service)
241-
return base_url + '/' + api_version + endpoint
118+
self.api_bin_lookup_version = api_bin_lookup_version
119+
self.api_checkout_version = api_checkout_version
120+
self.api_management_version = api_management_version
121+
self.api_payment_version = api_payment_version
122+
self.api_payout_version = api_payout_version
123+
self.api_recurring_version = api_recurring_version
124+
self.api_terminal_version = api_terminal_version
125+
self.api_legal_entity_management_version = api_legal_entity_management_version
126+
self.api_data_protection_version = api_data_protection_version
127+
self.api_transfers_version = api_transfers_version
128+
self.api_stored_value_version = api_stored_value_version
129+
self.api_balance_platform_version = api_balance_platform_version
130+
131+
def _determine_api_url(self, platform, endpoint):
132+
if platform == "test":
133+
return endpoint
134+
135+
if "pal-" in endpoint:
136+
if self.live_endpoint_prefix is None:
137+
error_string = "Please set your live suffix. You can set it by running " \
138+
"adyen.client.live_endpoint_prefix = 'Your live suffix'"
139+
raise AdyenEndpointInvalidFormat(error_string)
140+
endpoint = endpoint.replace("https://pal-test.adyen.com/pal/servlet/",
141+
"https://" + self.live_endpoint_prefix + "-pal-live.adyenpayments.com/pal/servlet/")
142+
elif "checkout-" in endpoint:
143+
if self.live_endpoint_prefix is None:
144+
error_string = "Please set your live suffix. You can set it by running " \
145+
"adyen.client.live_endpoint_prefix = 'Your live suffix'"
146+
raise AdyenEndpointInvalidFormat(error_string)
147+
endpoint = endpoint.replace("https://checkout-test.adyen.com/",
148+
"https://" + self.live_endpoint_prefix + "-checkout-live.adyenpayments.com/checkout/")
149+
150+
endpoint = endpoint.replace("-test", "-live")
151+
152+
return endpoint
242153

243154
def _review_payout_username(self, **kwargs):
244155
if 'username' in kwargs:
@@ -351,6 +262,24 @@ def _set_platform(self, **kwargs):
351262

352263
return platform
353264

265+
def _set_url_version(self, service, endpoint):
266+
version_lookup = {"binlookup": self.api_bin_lookup_version,
267+
"checkout": self.api_checkout_version,
268+
"management": self.api_management_version,
269+
"payments": self.api_payment_version,
270+
"payouts": self.api_payout_version,
271+
"recurring": self.api_recurring_version,
272+
"terminal": self.api_terminal_version,
273+
"legalEntityManagement": self.api_legal_entity_management_version,
274+
"dataProtection": self.api_data_protection_version,
275+
"transfers": self.api_transfers_version,
276+
"storedValue": self.api_stored_value_version,
277+
"balancePlatform": self.api_balance_platform_version}
278+
279+
new_version = f"v{version_lookup[service]}"
280+
endpoint = re.sub(r'\.com/v\d{1,2}', f".com/{new_version}", endpoint)
281+
return endpoint
282+
354283
def call_adyen_api(
355284
self,
356285
request_data,
@@ -383,10 +312,25 @@ def call_adyen_api(
383312
self._init_http_client()
384313

385314
# Set credentials
386-
xapikey, username, password, kwargs= self._set_credentials(service, endpoint, **kwargs)
315+
xapikey, username, password, kwargs = self._set_credentials(service, endpoint, **kwargs)
387316
# Set platform
388317
platform = self._set_platform(**kwargs)
389318
message = request_data
319+
# Set version (if not default one)
320+
versions = [self.api_bin_lookup_version,
321+
self.api_checkout_version,
322+
self.api_management_version,
323+
self.api_payment_version,
324+
self.api_payout_version,
325+
self.api_recurring_version,
326+
self.api_terminal_version,
327+
self.api_legal_entity_management_version,
328+
self.api_data_protection_version,
329+
self.api_transfers_version,
330+
self.api_stored_value_version,
331+
self.api_balance_platform_version]
332+
if any(versions):
333+
endpoint = self._set_url_version(service, endpoint)
390334

391335
headers = {
392336
self.APPLICATION_INFO_HEADER_NAME: settings.LIB_NAME,
@@ -398,7 +342,7 @@ def call_adyen_api(
398342
if idempotency_key:
399343
headers[self.IDEMPOTENCY_HEADER_NAME] = idempotency_key
400344

401-
url = self._determine_api_url(platform, service, endpoint)
345+
url = self._determine_api_url(platform, endpoint)
402346

403347
if 'query_parameters' in kwargs:
404348
url = url + util.get_query(kwargs['query_parameters'])

Adyen/services/balancePlatform/account_holders_api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,37 @@ class AccountHoldersApi(AdyenServiceBase):
1111
def __init__(self, client=None):
1212
super(AccountHoldersApi, self).__init__(client=client)
1313
self.service = "balancePlatform"
14+
self.baseUrl = "https://balanceplatform-api-test.adyen.com/bcl/v2"
1415

1516
def get_account_holder(self, id, idempotency_key=None, **kwargs):
1617
"""
1718
Get an account holder
1819
"""
19-
endpoint = f"/accountHolders/{id}"
20+
endpoint = self.baseUrl + f"/accountHolders/{id}"
2021
method = "GET"
2122
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
2223

2324
def get_all_balance_accounts_of_account_holder(self, id, idempotency_key=None, **kwargs):
2425
"""
2526
Get all balance accounts of an account holder
2627
"""
27-
endpoint = f"/accountHolders/{id}/balanceAccounts"
28+
endpoint = self.baseUrl + f"/accountHolders/{id}/balanceAccounts"
2829
method = "GET"
2930
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
3031

3132
def update_account_holder(self, request, id, idempotency_key=None, **kwargs):
3233
"""
3334
Update an account holder
3435
"""
35-
endpoint = f"/accountHolders/{id}"
36+
endpoint = self.baseUrl + f"/accountHolders/{id}"
3637
method = "PATCH"
3738
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)
3839

3940
def create_account_holder(self, request, idempotency_key=None, **kwargs):
4041
"""
4142
Create an account holder
4243
"""
43-
endpoint = f"/accountHolders"
44+
endpoint = self.baseUrl + f"/accountHolders"
4445
method = "POST"
4546
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)
4647

Adyen/services/balancePlatform/balance_accounts_api.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,76 +11,77 @@ class BalanceAccountsApi(AdyenServiceBase):
1111
def __init__(self, client=None):
1212
super(BalanceAccountsApi, self).__init__(client=client)
1313
self.service = "balancePlatform"
14+
self.baseUrl = "https://balanceplatform-api-test.adyen.com/bcl/v2"
1415

1516
def delete_sweep(self, balanceAccountId, sweepId, idempotency_key=None, **kwargs):
1617
"""
1718
Delete a sweep
1819
"""
19-
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
20+
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
2021
method = "DELETE"
2122
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
2223

2324
def get_all_sweeps_for_balance_account(self, balanceAccountId, idempotency_key=None, **kwargs):
2425
"""
2526
Get all sweeps for a balance account
2627
"""
27-
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps"
28+
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps"
2829
method = "GET"
2930
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
3031

3132
def get_sweep(self, balanceAccountId, sweepId, idempotency_key=None, **kwargs):
3233
"""
3334
Get a sweep
3435
"""
35-
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
36+
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
3637
method = "GET"
3738
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
3839

3940
def get_balance_account(self, id, idempotency_key=None, **kwargs):
4041
"""
4142
Get a balance account
4243
"""
43-
endpoint = f"/balanceAccounts/{id}"
44+
endpoint = self.baseUrl + f"/balanceAccounts/{id}"
4445
method = "GET"
4546
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
4647

4748
def get_all_payment_instruments_for_balance_account(self, id, idempotency_key=None, **kwargs):
4849
"""
4950
Get all payment instruments for a balance account
5051
"""
51-
endpoint = f"/balanceAccounts/{id}/paymentInstruments"
52+
endpoint = self.baseUrl + f"/balanceAccounts/{id}/paymentInstruments"
5253
method = "GET"
5354
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
5455

5556
def update_sweep(self, request, balanceAccountId, sweepId, idempotency_key=None, **kwargs):
5657
"""
5758
Update a sweep
5859
"""
59-
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
60+
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
6061
method = "PATCH"
6162
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)
6263

6364
def update_balance_account(self, request, id, idempotency_key=None, **kwargs):
6465
"""
6566
Update a balance account
6667
"""
67-
endpoint = f"/balanceAccounts/{id}"
68+
endpoint = self.baseUrl + f"/balanceAccounts/{id}"
6869
method = "PATCH"
6970
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)
7071

7172
def create_balance_account(self, request, idempotency_key=None, **kwargs):
7273
"""
7374
Create a balance account
7475
"""
75-
endpoint = f"/balanceAccounts"
76+
endpoint = self.baseUrl + f"/balanceAccounts"
7677
method = "POST"
7778
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)
7879

7980
def create_sweep(self, request, balanceAccountId, idempotency_key=None, **kwargs):
8081
"""
8182
Create a sweep
8283
"""
83-
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps"
84+
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps"
8485
method = "POST"
8586
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)
8687

Adyen/services/balancePlatform/bank_account_validation_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ class BankAccountValidationApi(AdyenServiceBase):
1111
def __init__(self, client=None):
1212
super(BankAccountValidationApi, self).__init__(client=client)
1313
self.service = "balancePlatform"
14+
self.baseUrl = "https://balanceplatform-api-test.adyen.com/bcl/v2"
1415

1516
def validate_bank_account_identification(self, request, idempotency_key=None, **kwargs):
1617
"""
1718
Validate a bank account
1819
"""
19-
endpoint = f"/validateBankAccountIdentification"
20+
endpoint = self.baseUrl + f"/validateBankAccountIdentification"
2021
method = "POST"
2122
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)
2223

0 commit comments

Comments
 (0)