Skip to content

Commit 2b69f03

Browse files
committed
Introduce Capital API Service
Add the generated capital-related service and exports to the client. In addition, the changes add test coverage for simple flows and assertions over endpoints. README file updated with Capital description.
1 parent cb273be commit 2b69f03

19 files changed

Lines changed: 492 additions & 4 deletions

Adyen/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .services import (
1515
AdyenBase,
1616
AdyenPaymentsApi,
17+
AdyenCapitalApi,
1718
AdyenBinlookupApi,
1819
AdyenRecurringApi,
1920
AdyenPayoutsApi,
@@ -36,6 +37,7 @@ class Adyen(AdyenBase):
3637
def __init__(self, **kwargs):
3738
self.client = AdyenClient(**kwargs)
3839
self.payment = AdyenPaymentsApi(client=self.client)
40+
self.capital = AdyenCapitalApi(client=self.client)
3941
self.binlookup = AdyenBinlookupApi(client=self.client)
4042
self.payout = AdyenPayoutsApi(client=self.client)
4143
self.recurring = AdyenRecurringApi(client=self.client)
@@ -65,4 +67,5 @@ def __init__(self, **kwargs):
6567
storedValue = _base_adyen_obj.storedValue
6668
balancePlatform = _base_adyen_obj.balancePlatform
6769
disputes = _base_adyen_obj.disputes
68-
sessionAuthentication = _base_adyen_obj.sessionAuthentication
70+
sessionAuthentication = _base_adyen_obj.sessionAuthentication
71+
capital = _base_adyen_obj.capital

Adyen/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(
9696
api_balance_platform_version=None,
9797
api_disputes_version=None,
9898
api_session_authentication_version=None,
99+
api_capital_version=None
99100

100101
):
101102
self.username = username
@@ -131,6 +132,8 @@ def __init__(
131132
self.api_balance_platform_version = api_balance_platform_version
132133
self.api_disputes_version = api_disputes_version
133134
self.api_session_authentication_version = api_session_authentication_version
135+
self.api_capital_version = api_capital_version
136+
134137

135138
def _determine_api_url(self, platform, endpoint):
136139
if platform == "test":
@@ -288,7 +291,8 @@ def _set_url_version(self, service, endpoint):
288291
"storedValue": self.api_stored_value_version,
289292
"balancePlatform": self.api_balance_platform_version,
290293
"disputes": self.api_disputes_version,
291-
"sessionAuthentication": self.api_session_authentication_version
294+
"sessionAuthentication": self.api_session_authentication_version,
295+
"capital": self.api_capital_version,
292296
}
293297

294298
new_version = f"v{version_lookup[service]}"
@@ -345,7 +349,9 @@ def call_adyen_api(
345349
self.api_stored_value_version,
346350
self.api_balance_platform_version,
347351
self.api_disputes_version,
348-
self.api_session_authentication_version]
352+
self.api_session_authentication_version,
353+
self.api_capital_version,
354+
]
349355
if any(versions):
350356
endpoint = self._set_url_version(service, endpoint)
351357

Adyen/services/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
from .storedValue import AdyenStoredValueApi
1313
from .balancePlatform import AdyenBalancePlatformApi
1414
from .disputes import AdyenDisputesApi
15-
from .sessionAuthentication import AdyenSessionAuthenticationApi
15+
from .sessionAuthentication import AdyenSessionAuthenticationApi
16+
from .capital import AdyenCapitalApi

Adyen/services/capital/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from ..base import AdyenServiceBase
2+
from .grant_accounts_api import GrantAccountsApi
3+
from .grant_offers_api import GrantOffersApi
4+
from .grants_api import GrantsApi
5+
6+
7+
class AdyenCapitalApi(AdyenServiceBase):
8+
"""NOTE: This class is auto generated by OpenAPI Generator
9+
Ref: https://openapi-generator.tech
10+
11+
Do not edit the class manually.
12+
"""
13+
14+
def __init__(self, client=None):
15+
super(AdyenCapitalApi, self).__init__(client=client)
16+
self.grant_accounts_api = GrantAccountsApi(client=client)
17+
self.grant_offers_api = GrantOffersApi(client=client)
18+
self.grants_api = GrantsApi(client=client)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from ..base import AdyenServiceBase
2+
3+
4+
class GrantAccountsApi(AdyenServiceBase):
5+
"""NOTE: This class is auto generated by OpenAPI Generator
6+
Ref: https://openapi-generator.tech
7+
8+
Do not edit the class manually.
9+
"""
10+
11+
def __init__(self, client=None):
12+
super(GrantAccountsApi, self).__init__(client=client)
13+
self.service = "capital"
14+
self.baseUrl = "https://balanceplatform-api-test.adyen.com/capital/v1"
15+
16+
def get_grant_account_information(self, id, idempotency_key=None, **kwargs):
17+
"""
18+
Get the information of your grant account
19+
"""
20+
endpoint = self.baseUrl + f"/grantAccounts/{id}"
21+
method = "GET"
22+
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
23+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from ..base import AdyenServiceBase
2+
3+
4+
class GrantOffersApi(AdyenServiceBase):
5+
"""NOTE: This class is auto generated by OpenAPI Generator
6+
Ref: https://openapi-generator.tech
7+
8+
Do not edit the class manually.
9+
"""
10+
11+
def __init__(self, client=None):
12+
super(GrantOffersApi, self).__init__(client=client)
13+
self.service = "capital"
14+
self.baseUrl = "https://balanceplatform-api-test.adyen.com/capital/v1"
15+
16+
def get_all_grant_offers(self, idempotency_key=None, **kwargs):
17+
"""
18+
Get all available grant offers
19+
"""
20+
endpoint = self.baseUrl + f"/grantOffers"
21+
method = "GET"
22+
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
23+
24+
def get_grant_offer(self, id, idempotency_key=None, **kwargs):
25+
"""
26+
Get the details of a grant offer
27+
"""
28+
endpoint = self.baseUrl + f"/grantOffers/{id}"
29+
method = "GET"
30+
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
31+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from ..base import AdyenServiceBase
2+
3+
4+
class GrantsApi(AdyenServiceBase):
5+
"""NOTE: This class is auto generated by OpenAPI Generator
6+
Ref: https://openapi-generator.tech
7+
8+
Do not edit the class manually.
9+
"""
10+
11+
def __init__(self, client=None):
12+
super(GrantsApi, self).__init__(client=client)
13+
self.service = "capital"
14+
self.baseUrl = "https://balanceplatform-api-test.adyen.com/capital/v1"
15+
16+
def get_all_grant_disbursements(self, grantId, idempotency_key=None, **kwargs):
17+
"""
18+
Get all the disbursements of a grant
19+
"""
20+
endpoint = self.baseUrl + f"/grants/{grantId}/disbursements"
21+
method = "GET"
22+
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
23+
24+
def get_all_grants(self, idempotency_key=None, **kwargs):
25+
"""
26+
Get all the grants of an account holder
27+
"""
28+
endpoint = self.baseUrl + f"/grants"
29+
method = "GET"
30+
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
31+
32+
def get_grant(self, grantId, idempotency_key=None, **kwargs):
33+
"""
34+
Get the details of a grant
35+
"""
36+
endpoint = self.baseUrl + f"/grants/{grantId}"
37+
method = "GET"
38+
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
39+
40+
def get_grant_disbursement(self, grantId, disbursementId, idempotency_key=None, **kwargs):
41+
"""
42+
Get disbursement details
43+
"""
44+
endpoint = self.baseUrl + f"/grants/{grantId}/disbursements/{disbursementId}"
45+
method = "GET"
46+
return self.client.call_adyen_api(None, self.service, method, endpoint, idempotency_key, **kwargs)
47+
48+
def request_grant(self, request, idempotency_key=None, **kwargs):
49+
"""
50+
Make a request for a grant
51+
"""
52+
endpoint = self.baseUrl + f"/grants"
53+
method = "POST"
54+
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)
55+
56+
def update_grant_disbursement(self, request, grantId, disbursementId, idempotency_key=None, **kwargs):
57+
"""
58+
Update the repayment configuration of a disbursement
59+
"""
60+
endpoint = self.baseUrl + f"/grants/{grantId}/disbursements/{disbursementId}"
61+
method = "PATCH"
62+
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)
63+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This is the officially supported Python library for using Adyen's APIs.
1313
| [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** |
1414
| [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** |
1515
| [Checkout API](https://docs.adyen.com/api-explorer/Checkout/71/overview) | Our latest integration for accepting online payments. | checkout | **v71** |
16+
| [Capital API](https://docs.adyen.com/api-explorer/capital/1/overview) | Provides endpoints for embedding Adyen Capital into your marketplace or platform. | capital | **v1** |
1617
| [Data Protection API](https://docs.adyen.com/development-resources/data-protection-api) | Endpoint for requesting data erasure. | dataProtection | **v1** |
1718
| [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** |
1819
| [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** |

test/CapitalTest.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import Adyen
2+
import unittest
3+
from Adyen import settings
4+
5+
try:
6+
from BaseTest import BaseTest
7+
except ImportError:
8+
from .BaseTest import BaseTest
9+
10+
11+
class TestCapital(unittest.TestCase):
12+
adyen = Adyen.Adyen()
13+
14+
client = adyen.client
15+
test = BaseTest(adyen)
16+
client.xapikey = "YourXapikey"
17+
client.platform = "test"
18+
lib_version = settings.LIB_VERSION
19+
20+
def test_request_grant(self):
21+
request = {}
22+
self.adyen.client = self.test.create_client_from_file(
23+
200,
24+
request,
25+
"test/mocks/capital/grants-success.json"
26+
)
27+
result = self.adyen.capital.grants_api.request_grant(request)
28+
self.assertEqual(1, len(result.message['grants']))
29+
self.assertEqual("GR00000000000000000000001", result.message['grants'][0]['id'])
30+
31+
def test_get_all_grant_offers(self):
32+
request = {}
33+
self.adyen.client = self.test.create_client_from_file(
34+
200,
35+
request,
36+
"test/mocks/capital/grant-offers-success.json"
37+
)
38+
result = self.adyen.capital.grant_offers_api.get_all_grant_offers(request)
39+
self.assertEqual(1, len(result.message['grantOffers']))
40+
self.assertEqual("GO00000000000000000000001", result.message['grantOffers'][0]['id'])
41+
42+
def test_get_all_grants(self):
43+
request = {}
44+
self.adyen.client = self.test.create_client_from_file(
45+
200,
46+
request,
47+
"test/mocks/capital/grants-success.json"
48+
)
49+
result = self.adyen.capital.grants_api.get_all_grants(counterparty_account_holder_id="AH00000000000000000000001")
50+
self.assertEqual(1, len(result.message['grants']))
51+
self.assertEqual("GR00000000000000000000001", result.message['grants'][0]['id'])
52+
53+
def test_get_grant(self):
54+
request = {}
55+
self.adyen.client = self.test.create_client_from_file(
56+
200,
57+
request,
58+
"test/mocks/capital/get-grant-success.json"
59+
)
60+
result = self.adyen.capital.grants_api.get_grant(grantId="GR00000000000000000000001")
61+
self.assertEqual("GR00000000000000000000001", result.message['id'])
62+
63+
def test_get_all_grant_disbursements(self):
64+
request = {}
65+
self.adyen.client = self.test.create_client_from_file(
66+
200,
67+
request,
68+
"test/mocks/capital/get-grant-disbursements-success.json"
69+
)
70+
result = self.adyen.capital.grants_api.get_all_grant_disbursements(grantId="GR00000000000000000000001")
71+
self.assertEqual(1, len(result.message['disbursements']))
72+
self.assertEqual("DI00000000000000000000001", result.message['disbursements'][0]['id'])
73+
74+
def test_get_grant_disbursement(self):
75+
request = {}
76+
self.adyen.client = self.test.create_client_from_file(
77+
200,
78+
request,
79+
"test/mocks/capital/get-grant-disbursement-success.json"
80+
)
81+
result = self.adyen.capital.grants_api.get_grant_disbursement(grantId="GR00000000000000000000001",
82+
disbursementId="DI00000000000000000000001")
83+
self.assertEqual("DI00000000000000000000001", result.message['id'])
84+
85+
def test_update_grant_disbursement(self):
86+
request = {}
87+
self.adyen.client = self.test.create_client_from_file(
88+
200,
89+
request,
90+
"test/mocks/capital/update-grant-disbursement-success.json"
91+
)
92+
result = self.adyen.capital.grants_api.update_grant_disbursement(request, grantId="GR00000000000000000000001",
93+
disbursementId="DI00000000000000000000001")
94+
self.assertEqual(1500, result.message['repayment']['basisPoints'])
95+
96+
def test_get_grant_account_information(self):
97+
request = {}
98+
self.adyen.client = self.test.create_client_from_file(
99+
200,
100+
request,
101+
"test/mocks/capital/get-grant-account-success.json"
102+
)
103+
result = self.adyen.capital.grant_accounts_api.get_grant_account_information(id="CG00000000000000000000001")
104+
self.assertEqual("CG00000000000000000000001", result.message['id'])
105+
106+
def test_get_grant_offer(self):
107+
request = {}
108+
self.adyen.client = self.test.create_client_from_file(
109+
200,
110+
request,
111+
"test/mocks/capital/get-grant-offer-success.json"
112+
)
113+
result = self.adyen.capital.grant_offers_api.get_grant_offer(id="GO00000000000000000000001")
114+
self.assertEqual("GO00000000000000000000001", result.message['id'])

test/DetermineEndpointTest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class TestDetermineUrl(unittest.TestCase):
2525
management_url = adyen.management.account_merchant_level_api.baseUrl
2626
sessionauth_url = adyen.sessionAuthentication.session_authentication_api.baseUrl
2727
sessionauth_version = sessionauth_url.split('/')[-1]
28+
capital_url = adyen.capital.grants_api.baseUrl
29+
capital_version = capital_url.split('/')[-1]
2830

2931
def test_checkout_api_url_custom(self):
3032
self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
@@ -143,3 +145,11 @@ def test_secureauthentication_api_url(self):
143145
def test_live_secureauthentication_api_url(self):
144146
url = self.adyen.client._determine_api_url("live", self.sessionauth_url + "/sessions")
145147
self.assertEqual(url, f"https://authe-live.adyen.com/authe/api/{self.sessionauth_version}/sessions")
148+
149+
def test_capital_api_url(self):
150+
url = self.adyen.client._determine_api_url("test", self.capital_url)
151+
self.assertEqual(url, self.capital_url)
152+
153+
def test_live_capital_api_url(self):
154+
url = self.adyen.client._determine_api_url("live", self.capital_url)
155+
self.assertEqual(url, f"https://balanceplatform-api-live.adyen.com/capital/{self.capital_version}")

0 commit comments

Comments
 (0)