alyf-de / banking

An Open Banking Integration with ERPNext
GNU General Public License v3.0
38 stars 18 forks source link

refactor: New client for Kosma Integration #5

Closed marination closed 1 year ago

marination commented 1 year ago

Resolves https://github.com/alyf-de/klarna_kosma_integration/issues/6

Usage

KlarnaKosmaFlow and KlarnaKosmaConsent are the clients for Kosma's Flow and Consent APIs

Flow API #### Instantiate the Flow object ```py flow = KlarnaKosmaFlow(env, api_token) # Where `env` is 'Playground'/'Production' and `api_token` is the token received from your service provider ``` #### Start a session ```py flow.start_session() # Returns a dict with session details like `session_id`, `session_id_short`, `flows`, etc. ``` #### End a session ```py flow.end_session(session_id) ``` #### Get session ```py flow.get_session(session_id) # Returns a dict containing current session's details e.g. bank, current flow, session ID, etc. # Must be used while the session is active ``` #### Start a Flow ```py flow.start(flow_type, flows) # `flow_type` can be 'accounts'/'transactions' and `flows` is a Dict of flows and their endpoints obtained after `start_session` ``` #### Get Accounts ```py flow.accounts(session_id, flow_id) # `flow_id` is obtained after starting a flow ``` #### Get Consent ```py flow.get_consent(session_id) # Get Bank consent at the end of a flow. Return values include Consent ID, Consent Token, Consent Expiry ```
Consent API #### Instantiate the Consent API object ```py consent = KlarnaKosmaConsent(env, api_token) # Where `env` is 'Playground'/'Production' and `api_token` is the token received from your service provider ``` #### Get Accounts ```py consent.accounts(consent_id, consent_token) # `consent_id` and `consent_token` are obtained after `flow.get_consent` and must be stored safely ``` #### Get Transactions ```py consent.transactions( account_id, start_date, consent_id, consent_token, url, # Optional offset # Optional ) ``` - This returns a single page of transactions - To obtain the next pages, this API must be called in a loop **with changes in `consent_token`, `url` and `offset`** - The response from the first call will tell you if there is a next page. If yes, retrieve the new `consent_token`, `url` and `offset` from the response and pass it on to the next call - **`url` and `offset` can be skipped for the first call**

Also added a wrapper class Kosma over the above client

ToDo:

marination commented 1 year ago

Tested, functionally all good