Skip to content

Commit

Permalink
Merge pull request #264 from Adyen/automation/release
Browse files Browse the repository at this point in the history
Release v9.0.3
  • Loading branch information
AdyenAutomationBot authored Sep 18, 2023
2 parents d81177b + 81ad204 commit e827bad
Show file tree
Hide file tree
Showing 85 changed files with 498 additions and 651 deletions.
200 changes: 72 additions & 128 deletions Adyen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
AdyenAPIUnprocessableEntity,
AdyenEndpointInvalidFormat)
from . import settings
from re import match
import re


class AdyenResult(object):
Expand Down Expand Up @@ -84,7 +84,6 @@ def __init__(
live_endpoint_prefix=None,
http_timeout=30,
api_bin_lookup_version=None,
api_checkout_utility_version=None,
api_checkout_version=None,
api_management_version=None,
api_payment_version=None,
Expand All @@ -96,6 +95,7 @@ def __init__(
api_transfers_version=None,
api_stored_value_version=None,
api_balance_platform_version=None,

):
self.username = username
self.password = password
Expand All @@ -115,130 +115,41 @@ def __init__(
self.http_force = http_force
self.live_endpoint_prefix = live_endpoint_prefix
self.http_timeout = http_timeout
self.api_bin_lookup_version = api_bin_lookup_version or settings.API_BIN_LOOKUP_VERSION
self.api_checkout_utility_version = api_checkout_utility_version or settings.API_CHECKOUT_UTILITY_VERSION
self.api_checkout_version = api_checkout_version or settings.API_CHECKOUT_VERSION
self.api_management_version = api_management_version or settings.API_MANAGEMENT_VERSION
self.api_payment_version = api_payment_version or settings.API_PAYMENT_VERSION
self.api_payout_version = api_payout_version or settings.API_PAYOUT_VERSION
self.api_recurring_version = api_recurring_version or settings.API_RECURRING_VERSION
self.api_terminal_version = api_terminal_version or settings.API_TERMINAL_VERSION
self.api_legal_entity_management_version = api_legal_entity_management_version or settings.API_LEGAL_ENTITY_MANAGEMENT_VERSION
self.api_data_protection_version = api_data_protection_version or settings.API_DATA_PROTECION_VERSION
self.api_transfers_version = api_transfers_version or settings.API_TRANSFERS_VERSION
self.api_stored_value_version = api_stored_value_version or settings.API_STORED_VALUE_VERSION
self.api_balance_platform_version = api_balance_platform_version or settings.API_BALANCE_PLATFORM_VERSION

def _determine_base_url_and_version(self, platform, service):

live_pal_url = settings.PAL_LIVE_ENDPOINT_URL_TEMPLATE
live_checkout_url = settings.ENDPOINT_CHECKOUT_LIVE_SUFFIX

if platform == 'live' and self.live_endpoint_prefix:
live_pal_url = live_pal_url.format(live_prefix=self.live_endpoint_prefix)
live_checkout_url = live_checkout_url.format(live_prefix=self.live_endpoint_prefix)

versions_and_urls = {
'recurring': {
'version': self.api_recurring_version,
'base_url': {
'live': live_pal_url + '/Recurring',
'test': settings.PAL_TEST_URL + '/Recurring',
}
},
'payouts': {
'version': self.api_payout_version,
'base_url': {
'live': live_pal_url + '/Payout',
'test': settings.PAL_TEST_URL + '/Payout'
}
},
'binlookup': {
'version': self.api_bin_lookup_version,
'base_url': {
'live': live_pal_url + '/BinLookup',
'test': settings.PAL_TEST_URL + '/BinLookup'
}
},
'terminal': {
'version': self.api_terminal_version,
'base_url': {
'live': settings.BASE_TERMINAL_URL.format(platform),
'test': settings.BASE_TERMINAL_URL.format(platform)
}
},
'payments': {
'version': self.api_payment_version,
'base_url': {
'live': live_pal_url + '/Payment',
'test': settings.PAL_TEST_URL + '/Payment'
}
},
'checkout': {
'version': self.api_checkout_version,
'base_url': {
'live': live_checkout_url,
'test': settings.ENDPOINT_CHECKOUT_TEST
}
},
'management': {
'version': self.api_management_version,
'base_url': {
'live': settings.BASE_MANAGEMENT_URL.format(platform),
'test': settings.BASE_MANAGEMENT_URL.format(platform)
}
},
'legalEntityManagement': {
'version': self.api_legal_entity_management_version,
'base_url': {
'live': settings.BASE_LEGAL_ENTITY_MANAGEMENT_URL.format(platform),
'test': settings.BASE_LEGAL_ENTITY_MANAGEMENT_URL.format(platform)
},
},
'balancePlatform': {
'version': self.api_balance_platform_version,
'base_url': {
'live': settings.BASE_CONFIGURATION_URL.format(platform),
'test': settings.BASE_CONFIGURATION_URL.format(platform)
}
},
'dataProtection': {
'version': self.api_data_protection_version,
'base_url': {
'live': settings.BASE_DATA_PROTECION_URL.format(platform),
'test': settings.BASE_DATA_PROTECION_URL.format(platform)
}
},
'transfers': {
'version': self.api_transfers_version,
'base_url': {
'live': settings.BASE_BTL_URL.format(platform),
'test': settings.BASE_BTL_URL.format(platform)
}
},
'storedValue': {
'version': self.api_stored_value_version,
'base_url': {
'live': settings.BASE_STORED_VALUE_URL.format(platform),
'test': settings.BASE_STORED_VALUE_URL.format(platform)
}
},
}

version = versions_and_urls[service]['version']
base_url = versions_and_urls[service]['base_url'][platform]
# Match urls that require a live prefix and do not have one

if platform == 'live' and '{live_prefix}' in base_url:
errorstring = "Please set your live suffix. You can set it by running " \
"adyen.client.live_endpoint_prefix = 'Your live suffix'"
raise AdyenEndpointInvalidFormat(errorstring)

return version, base_url

def _determine_api_url(self, platform, service, endpoint):
api_version, base_url = self._determine_base_url_and_version(platform, service)
return base_url + '/' + api_version + endpoint
self.api_bin_lookup_version = api_bin_lookup_version
self.api_checkout_version = api_checkout_version
self.api_management_version = api_management_version
self.api_payment_version = api_payment_version
self.api_payout_version = api_payout_version
self.api_recurring_version = api_recurring_version
self.api_terminal_version = api_terminal_version
self.api_legal_entity_management_version = api_legal_entity_management_version
self.api_data_protection_version = api_data_protection_version
self.api_transfers_version = api_transfers_version
self.api_stored_value_version = api_stored_value_version
self.api_balance_platform_version = api_balance_platform_version

def _determine_api_url(self, platform, endpoint):
if platform == "test":
return endpoint

if "pal-" in endpoint:
if self.live_endpoint_prefix is None:
error_string = "Please set your live suffix. You can set it by running " \
"adyen.client.live_endpoint_prefix = 'Your live suffix'"
raise AdyenEndpointInvalidFormat(error_string)
endpoint = endpoint.replace("https://pal-test.adyen.com/pal/servlet/",
"https://" + self.live_endpoint_prefix + "-pal-live.adyenpayments.com/pal/servlet/")
elif "checkout-" in endpoint:
if self.live_endpoint_prefix is None:
error_string = "Please set your live suffix. You can set it by running " \
"adyen.client.live_endpoint_prefix = 'Your live suffix'"
raise AdyenEndpointInvalidFormat(error_string)
endpoint = endpoint.replace("https://checkout-test.adyen.com/",
"https://" + self.live_endpoint_prefix + "-checkout-live.adyenpayments.com/checkout/")

endpoint = endpoint.replace("-test", "-live")

return endpoint

def _review_payout_username(self, **kwargs):
if 'username' in kwargs:
Expand Down Expand Up @@ -351,6 +262,24 @@ def _set_platform(self, **kwargs):

return platform

def _set_url_version(self, service, endpoint):
version_lookup = {"binlookup": self.api_bin_lookup_version,
"checkout": self.api_checkout_version,
"management": self.api_management_version,
"payments": self.api_payment_version,
"payouts": self.api_payout_version,
"recurring": self.api_recurring_version,
"terminal": self.api_terminal_version,
"legalEntityManagement": self.api_legal_entity_management_version,
"dataProtection": self.api_data_protection_version,
"transfers": self.api_transfers_version,
"storedValue": self.api_stored_value_version,
"balancePlatform": self.api_balance_platform_version}

new_version = f"v{version_lookup[service]}"
endpoint = re.sub(r'\.com/v\d{1,2}', f".com/{new_version}", endpoint)
return endpoint

def call_adyen_api(
self,
request_data,
Expand Down Expand Up @@ -383,10 +312,25 @@ def call_adyen_api(
self._init_http_client()

# Set credentials
xapikey, username, password, kwargs= self._set_credentials(service, endpoint, **kwargs)
xapikey, username, password, kwargs = self._set_credentials(service, endpoint, **kwargs)
# Set platform
platform = self._set_platform(**kwargs)
message = request_data
# Set version (if not default one)
versions = [self.api_bin_lookup_version,
self.api_checkout_version,
self.api_management_version,
self.api_payment_version,
self.api_payout_version,
self.api_recurring_version,
self.api_terminal_version,
self.api_legal_entity_management_version,
self.api_data_protection_version,
self.api_transfers_version,
self.api_stored_value_version,
self.api_balance_platform_version]
if any(versions):
endpoint = self._set_url_version(service, endpoint)

headers = {
self.APPLICATION_INFO_HEADER_NAME: settings.LIB_NAME,
Expand All @@ -398,7 +342,7 @@ def call_adyen_api(
if idempotency_key:
headers[self.IDEMPOTENCY_HEADER_NAME] = idempotency_key

url = self._determine_api_url(platform, service, endpoint)
url = self._determine_api_url(platform, endpoint)

if 'query_parameters' in kwargs:
url = url + util.get_query(kwargs['query_parameters'])
Expand Down
9 changes: 5 additions & 4 deletions Adyen/services/balancePlatform/account_holders_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,37 @@ class AccountHoldersApi(AdyenServiceBase):
def __init__(self, client=None):
super(AccountHoldersApi, self).__init__(client=client)
self.service = "balancePlatform"
self.baseUrl = "https://balanceplatform-api-test.adyen.com/bcl/v2"

def get_account_holder(self, id, idempotency_key=None, **kwargs):
"""
Get an account holder
"""
endpoint = f"/accountHolders/{id}"
endpoint = self.baseUrl + f"/accountHolders/{id}"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def get_all_balance_accounts_of_account_holder(self, id, idempotency_key=None, **kwargs):
"""
Get all balance accounts of an account holder
"""
endpoint = f"/accountHolders/{id}/balanceAccounts"
endpoint = self.baseUrl + f"/accountHolders/{id}/balanceAccounts"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def update_account_holder(self, request, id, idempotency_key=None, **kwargs):
"""
Update an account holder
"""
endpoint = f"/accountHolders/{id}"
endpoint = self.baseUrl + f"/accountHolders/{id}"
method = "PATCH"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

def create_account_holder(self, request, idempotency_key=None, **kwargs):
"""
Create an account holder
"""
endpoint = f"/accountHolders"
endpoint = self.baseUrl + f"/accountHolders"
method = "POST"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

19 changes: 10 additions & 9 deletions Adyen/services/balancePlatform/balance_accounts_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,77 @@ class BalanceAccountsApi(AdyenServiceBase):
def __init__(self, client=None):
super(BalanceAccountsApi, self).__init__(client=client)
self.service = "balancePlatform"
self.baseUrl = "https://balanceplatform-api-test.adyen.com/bcl/v2"

def delete_sweep(self, balanceAccountId, sweepId, idempotency_key=None, **kwargs):
"""
Delete a sweep
"""
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
method = "DELETE"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def get_all_sweeps_for_balance_account(self, balanceAccountId, idempotency_key=None, **kwargs):
"""
Get all sweeps for a balance account
"""
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps"
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def get_sweep(self, balanceAccountId, sweepId, idempotency_key=None, **kwargs):
"""
Get a sweep
"""
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def get_balance_account(self, id, idempotency_key=None, **kwargs):
"""
Get a balance account
"""
endpoint = f"/balanceAccounts/{id}"
endpoint = self.baseUrl + f"/balanceAccounts/{id}"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def get_all_payment_instruments_for_balance_account(self, id, idempotency_key=None, **kwargs):
"""
Get all payment instruments for a balance account
"""
endpoint = f"/balanceAccounts/{id}/paymentInstruments"
endpoint = self.baseUrl + f"/balanceAccounts/{id}/paymentInstruments"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def update_sweep(self, request, balanceAccountId, sweepId, idempotency_key=None, **kwargs):
"""
Update a sweep
"""
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps/{sweepId}"
method = "PATCH"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

def update_balance_account(self, request, id, idempotency_key=None, **kwargs):
"""
Update a balance account
"""
endpoint = f"/balanceAccounts/{id}"
endpoint = self.baseUrl + f"/balanceAccounts/{id}"
method = "PATCH"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

def create_balance_account(self, request, idempotency_key=None, **kwargs):
"""
Create a balance account
"""
endpoint = f"/balanceAccounts"
endpoint = self.baseUrl + f"/balanceAccounts"
method = "POST"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

def create_sweep(self, request, balanceAccountId, idempotency_key=None, **kwargs):
"""
Create a sweep
"""
endpoint = f"/balanceAccounts/{balanceAccountId}/sweeps"
endpoint = self.baseUrl + f"/balanceAccounts/{balanceAccountId}/sweeps"
method = "POST"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class BankAccountValidationApi(AdyenServiceBase):
def __init__(self, client=None):
super(BankAccountValidationApi, self).__init__(client=client)
self.service = "balancePlatform"
self.baseUrl = "https://balanceplatform-api-test.adyen.com/bcl/v2"

def validate_bank_account_identification(self, request, idempotency_key=None, **kwargs):
"""
Validate a bank account
"""
endpoint = f"/validateBankAccountIdentification"
endpoint = self.baseUrl + f"/validateBankAccountIdentification"
method = "POST"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

Loading

0 comments on commit e827bad

Please sign in to comment.