Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Adyen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .services import (
AdyenBase,
AdyenPaymentsApi,
AdyenCapitalApi,
AdyenBinlookupApi,
AdyenRecurringApi,
AdyenPayoutsApi,
Expand All @@ -36,6 +37,7 @@ class Adyen(AdyenBase):
def __init__(self, **kwargs):
self.client = AdyenClient(**kwargs)
self.payment = AdyenPaymentsApi(client=self.client)
self.capital = AdyenCapitalApi(client=self.client)
self.binlookup = AdyenBinlookupApi(client=self.client)
self.payout = AdyenPayoutsApi(client=self.client)
self.recurring = AdyenRecurringApi(client=self.client)
Expand Down Expand Up @@ -65,4 +67,5 @@ def __init__(self, **kwargs):
storedValue = _base_adyen_obj.storedValue
balancePlatform = _base_adyen_obj.balancePlatform
disputes = _base_adyen_obj.disputes
sessionAuthentication = _base_adyen_obj.sessionAuthentication
sessionAuthentication = _base_adyen_obj.sessionAuthentication
capital = _base_adyen_obj.capital
10 changes: 8 additions & 2 deletions Adyen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__(
api_balance_platform_version=None,
api_disputes_version=None,
api_session_authentication_version=None,
api_capital_version=None

):
self.username = username
Expand Down Expand Up @@ -131,6 +132,8 @@ def __init__(
self.api_balance_platform_version = api_balance_platform_version
self.api_disputes_version = api_disputes_version
self.api_session_authentication_version = api_session_authentication_version
self.api_capital_version = api_capital_version


def _determine_api_url(self, platform, endpoint):
if platform == "test":
Expand Down Expand Up @@ -288,7 +291,8 @@ def _set_url_version(self, service, endpoint):
"storedValue": self.api_stored_value_version,
"balancePlatform": self.api_balance_platform_version,
"disputes": self.api_disputes_version,
"sessionAuthentication": self.api_session_authentication_version
"sessionAuthentication": self.api_session_authentication_version,
"capital": self.api_capital_version,
}

new_version = f"v{version_lookup[service]}"
Expand Down Expand Up @@ -345,7 +349,9 @@ def call_adyen_api(
self.api_stored_value_version,
self.api_balance_platform_version,
self.api_disputes_version,
self.api_session_authentication_version]
self.api_session_authentication_version,
self.api_capital_version,
]
if any(versions):
endpoint = self._set_url_version(service, endpoint)

Expand Down
3 changes: 2 additions & 1 deletion Adyen/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
from .storedValue import AdyenStoredValueApi
from .balancePlatform import AdyenBalancePlatformApi
from .disputes import AdyenDisputesApi
from .sessionAuthentication import AdyenSessionAuthenticationApi
from .sessionAuthentication import AdyenSessionAuthenticationApi
from .capital import AdyenCapitalApi
18 changes: 18 additions & 0 deletions Adyen/services/capital/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from ..base import AdyenServiceBase
from .grant_accounts_api import GrantAccountsApi
from .grant_offers_api import GrantOffersApi
from .grants_api import GrantsApi


class AdyenCapitalApi(AdyenServiceBase):
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech

Do not edit the class manually.
"""

def __init__(self, client=None):
super(AdyenCapitalApi, self).__init__(client=client)
self.grant_accounts_api = GrantAccountsApi(client=client)
self.grant_offers_api = GrantOffersApi(client=client)
self.grants_api = GrantsApi(client=client)
23 changes: 23 additions & 0 deletions Adyen/services/capital/grant_accounts_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from ..base import AdyenServiceBase


class GrantAccountsApi(AdyenServiceBase):
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech

Do not edit the class manually.
"""

def __init__(self, client=None):
super(GrantAccountsApi, self).__init__(client=client)
self.service = "capital"
self.baseUrl = "https://balanceplatform-api-test.adyen.com/capital/v1"

def get_grant_account_information(self, id, idempotency_key=None, **kwargs):
"""
Get the information of your grant account
"""
endpoint = self.baseUrl + f"/grantAccounts/{id}"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

31 changes: 31 additions & 0 deletions Adyen/services/capital/grant_offers_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from ..base import AdyenServiceBase


class GrantOffersApi(AdyenServiceBase):
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech

Do not edit the class manually.
"""

def __init__(self, client=None):
super(GrantOffersApi, self).__init__(client=client)
self.service = "capital"
self.baseUrl = "https://balanceplatform-api-test.adyen.com/capital/v1"

def get_all_grant_offers(self, idempotency_key=None, **kwargs):
"""
Get all available grant offers
"""
endpoint = self.baseUrl + f"/grantOffers"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def get_grant_offer(self, id, idempotency_key=None, **kwargs):
"""
Get the details of a grant offer
"""
endpoint = self.baseUrl + f"/grantOffers/{id}"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

63 changes: 63 additions & 0 deletions Adyen/services/capital/grants_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from ..base import AdyenServiceBase


class GrantsApi(AdyenServiceBase):
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech

Do not edit the class manually.
"""

def __init__(self, client=None):
super(GrantsApi, self).__init__(client=client)
self.service = "capital"
self.baseUrl = "https://balanceplatform-api-test.adyen.com/capital/v1"

def get_all_grant_disbursements(self, grantId, idempotency_key=None, **kwargs):
"""
Get all the disbursements of a grant
"""
endpoint = self.baseUrl + f"/grants/{grantId}/disbursements"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def get_all_grants(self, idempotency_key=None, **kwargs):
"""
Get all the grants of an account holder
"""
endpoint = self.baseUrl + f"/grants"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def get_grant(self, grantId, idempotency_key=None, **kwargs):
"""
Get the details of a grant
"""
endpoint = self.baseUrl + f"/grants/{grantId}"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def get_grant_disbursement(self, grantId, disbursementId, idempotency_key=None, **kwargs):
"""
Get disbursement details
"""
endpoint = self.baseUrl + f"/grants/{grantId}/disbursements/{disbursementId}"
method = "GET"
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)

def request_grant(self, request, idempotency_key=None, **kwargs):
"""
Make a request for a grant
"""
endpoint = self.baseUrl + f"/grants"
method = "POST"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

def update_grant_disbursement(self, request, grantId, disbursementId, idempotency_key=None, **kwargs):
"""
Update the repayment configuration of a disbursement
"""
endpoint = self.baseUrl + f"/grants/{grantId}/disbursements/{disbursementId}"
method = "PATCH"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This is the officially supported Python library for using Adyen's APIs.
| [BIN lookup API](https://docs.adyen.com/api-explorer/BinLookup/54/overview) | The BIN Lookup API provides endpoints for retrieving information based on a given BIN. | binLookup | **v54** |
| [Balance Platform API](https://docs.adyen.com/api-explorer/balanceplatform/2/overview) | The Balance Platform API enables you to create a platform where you can onboard your users as account holders and create balance accounts, cards, and business accounts. | balancePlatform | **v2** |
| [Checkout API](https://docs.adyen.com/api-explorer/Checkout/71/overview) | Our latest integration for accepting online payments. | checkout | **v71** |
| [Capital API](https://docs.adyen.com/api-explorer/capital/1/overview) | Provides endpoints for embedding Adyen Capital into your marketplace or platform. | capital | **v1** |
| [Data Protection API](https://docs.adyen.com/development-resources/data-protection-api) | Endpoint for requesting data erasure. | dataProtection | **v1** |
| [Legal Entity Management API](https://docs.adyen.com/api-explorer/legalentity/4/overview) | The Legal Entity Management API enables you to manage legal entities that contain information required for verification. | legalEntityManagement | **v4** |
| [Management API](https://docs.adyen.com/api-explorer/Management/3/overview) | Configure and manage your Adyen company and merchant accounts, stores, and payment terminals. | management | **v3** |
Expand Down
114 changes: 114 additions & 0 deletions test/CapitalTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import Adyen
import unittest
from Adyen import settings

try:
from BaseTest import BaseTest
except ImportError:
from .BaseTest import BaseTest


class TestCapital(unittest.TestCase):
adyen = Adyen.Adyen()

client = adyen.client
test = BaseTest(adyen)
client.xapikey = "YourXapikey"
client.platform = "test"
lib_version = settings.LIB_VERSION

def test_request_grant(self):
request = {}
self.adyen.client = self.test.create_client_from_file(
200,
request,
"test/mocks/capital/grants-success.json"
)
result = self.adyen.capital.grants_api.request_grant(request)
self.assertEqual(1, len(result.message['grants']))
self.assertEqual("GR00000000000000000000001", result.message['grants'][0]['id'])

def test_get_all_grant_offers(self):
request = {}
self.adyen.client = self.test.create_client_from_file(
200,
request,
"test/mocks/capital/grant-offers-success.json"
)
result = self.adyen.capital.grant_offers_api.get_all_grant_offers(request)
self.assertEqual(1, len(result.message['grantOffers']))
self.assertEqual("GO00000000000000000000001", result.message['grantOffers'][0]['id'])

def test_get_all_grants(self):
request = {}
self.adyen.client = self.test.create_client_from_file(
200,
request,
"test/mocks/capital/grants-success.json"
)
result = self.adyen.capital.grants_api.get_all_grants(counterparty_account_holder_id="AH00000000000000000000001")
self.assertEqual(1, len(result.message['grants']))
self.assertEqual("GR00000000000000000000001", result.message['grants'][0]['id'])

def test_get_grant(self):
request = {}
self.adyen.client = self.test.create_client_from_file(
200,
request,
"test/mocks/capital/get-grant-success.json"
)
result = self.adyen.capital.grants_api.get_grant(grantId="GR00000000000000000000001")
self.assertEqual("GR00000000000000000000001", result.message['id'])

def test_get_all_grant_disbursements(self):
request = {}
self.adyen.client = self.test.create_client_from_file(
200,
request,
"test/mocks/capital/get-grant-disbursements-success.json"
)
result = self.adyen.capital.grants_api.get_all_grant_disbursements(grantId="GR00000000000000000000001")
self.assertEqual(1, len(result.message['disbursements']))
self.assertEqual("DI00000000000000000000001", result.message['disbursements'][0]['id'])

def test_get_grant_disbursement(self):
request = {}
self.adyen.client = self.test.create_client_from_file(
200,
request,
"test/mocks/capital/get-grant-disbursement-success.json"
)
result = self.adyen.capital.grants_api.get_grant_disbursement(grantId="GR00000000000000000000001",
disbursementId="DI00000000000000000000001")
self.assertEqual("DI00000000000000000000001", result.message['id'])

def test_update_grant_disbursement(self):
request = {}
self.adyen.client = self.test.create_client_from_file(
200,
request,
"test/mocks/capital/update-grant-disbursement-success.json"
)
result = self.adyen.capital.grants_api.update_grant_disbursement(request, grantId="GR00000000000000000000001",
disbursementId="DI00000000000000000000001")
self.assertEqual(1500, result.message['repayment']['basisPoints'])

def test_get_grant_account_information(self):
request = {}
self.adyen.client = self.test.create_client_from_file(
200,
request,
"test/mocks/capital/get-grant-account-success.json"
)
result = self.adyen.capital.grant_accounts_api.get_grant_account_information(id="CG00000000000000000000001")
self.assertEqual("CG00000000000000000000001", result.message['id'])

def test_get_grant_offer(self):
request = {}
self.adyen.client = self.test.create_client_from_file(
200,
request,
"test/mocks/capital/get-grant-offer-success.json"
)
result = self.adyen.capital.grant_offers_api.get_grant_offer(id="GO00000000000000000000001")
self.assertEqual("GO00000000000000000000001", result.message['id'])
10 changes: 10 additions & 0 deletions test/DetermineEndpointTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class TestDetermineUrl(unittest.TestCase):
management_url = adyen.management.account_merchant_level_api.baseUrl
sessionauth_url = adyen.sessionAuthentication.session_authentication_api.baseUrl
sessionauth_version = sessionauth_url.split('/')[-1]
capital_url = adyen.capital.grants_api.baseUrl
capital_version = capital_url.split('/')[-1]

def test_checkout_api_url_custom(self):
self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
Expand Down Expand Up @@ -143,3 +145,11 @@ def test_secureauthentication_api_url(self):
def test_live_secureauthentication_api_url(self):
url = self.adyen.client._determine_api_url("live", self.sessionauth_url + "/sessions")
self.assertEqual(url, f"https://authe-live.adyen.com/authe/api/{self.sessionauth_version}/sessions")

def test_capital_api_url(self):
url = self.adyen.client._determine_api_url("test", self.capital_url)
self.assertEqual(url, self.capital_url)

def test_live_capital_api_url(self):
url = self.adyen.client._determine_api_url("live", self.capital_url)
self.assertEqual(url, f"https://balanceplatform-api-live.adyen.com/capital/{self.capital_version}")
21 changes: 21 additions & 0 deletions test/mocks/capital/get-grant-account-success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

{
"id": "CG00000000000000000000001",
"fundingBalanceAccountId": "BA00000000000000000000001",
"limits": [
{
"amount": {
"currency": "EUR",
"value": 100000
}
}
],
"balances": [
{
"currency": "EUR",
"principal": 10000,
"fee": 1000,
"total": 11000
}
]
}
Loading