diff --git a/src/tink/client.py b/src/tink/client.py index 17a71c4..3e305fa 100644 --- a/src/tink/client.py +++ b/src/tink/client.py @@ -1,6 +1,9 @@ """ Tink API client — async httpx wrapper covering auth, users, accounts (v2), transactions (v2), events (v2), and bank connectivity. + +Tink API reference: https://docs.tink.com/api-introduction +Endpoint reference: https://docs.tink.com/api#overview """ import json @@ -89,7 +92,10 @@ class TinkClient: # ------------------------------------------------------------------------- async def get_app_token(self, scope: str = "user:create") -> dict: - """Client credentials flow — returns app-level token.""" + """ + Client credentials flow — returns app-level access token. + Docs: https://docs.tink.com/api#connectivity/oauth/create-an-oauth-token + """ return await self._post( f"{self.api_base}/api/v1/oauth/token", headers={"Content-Type": "application/x-www-form-urlencoded"}, @@ -103,6 +109,10 @@ class TinkClient: async def exchange_code_for_token(self, code: str, redirect_uri: str | None = None) -> dict: + """ + Exchange the authorization_code from Tink Link callback for a user-scoped token. + Docs: https://docs.tink.com/api#connectivity/oauth/create-an-oauth-token + """ data: dict = { "client_id": self.client_id, "client_secret": self.client_secret, @@ -123,6 +133,11 @@ class TinkClient: async def create_user(self, app_token: str, external_user_id: str, market: str = "DK", locale: str = "da_DK") -> dict: + """ + Create a Tink user linked to your internal customer reference. + external_user_id = your system's reference (e.g. "moneycapp-42"). Tink returns a user_id. + Docs: https://docs.tink.com/api#user/create-user + """ return await self._post( f"{self.api_base}/api/v1/user/create", headers={"Authorization": f"Bearer {app_token}"}, @@ -137,6 +152,11 @@ class TinkClient: async def get_authorization_grant_token(self, app_token: str, user_id: str, scope: str) -> dict: + """ + Delegate an authorization grant for a specific user — generates a one-time code + that binds the Tink Link session to that user. + Docs: https://docs.tink.com/api#connectivity/oauth/create-authorization + """ return await self._post( f"{self.api_base}/api/v1/oauth/authorization-grant/delegate", headers={ @@ -153,6 +173,12 @@ class TinkClient: def get_tink_link_url(self, market: str = "DK", authorization_code: str | None = None, redirect_uri_override: str | None = None) -> str: + """ + Build the Tink Link URL for bank connection. + With authorization_code: links the session to a specific Tink user (production flow). + Without: anonymous flow (sandbox only). + Docs: https://docs.tink.com/resources/tink-link/tink-link-web-permanent-users + """ from urllib.parse import urlencode params: dict = { "client_id": self.client_id, @@ -184,6 +210,10 @@ class TinkClient: async def list_accounts(self, user_token: str, page_size: int = 50, page_token: Optional[str] = None) -> dict: + """ + List all accounts for a user including balance and IBAN. + Docs: https://docs.tink.com/api#account-service-v2/account/list-accounts + """ params: dict = {"pageSize": page_size} if page_token: params["pageToken"] = page_token @@ -206,6 +236,10 @@ class TinkClient: async def list_transactions(self, user_token: str, page_size: int = 25, page_token: Optional[str] = None, account_id: Optional[str] = None) -> dict: + """ + List transactions with cursor-based pagination. + Docs: https://docs.tink.com/api#transaction-service-v2/transaction/list-transactions + """ params: dict = {"pageSize": page_size} if page_token: params["pageToken"] = page_token @@ -265,6 +299,10 @@ class TinkClient: async def register_webhook(self, app_token: str, url: str, enabled_events: list[str] | None = None) -> dict: + """ + Register a webhook endpoint for real-time transaction notifications. + Docs: https://docs.tink.com/api#webhook/create-webhook-endpoint + """ return await self._post( f"{self.api_base}/api/v1/webhooks", headers={"Authorization": f"Bearer {app_token}"},