Banking API¶
Initialize the client¶
To initialize the client you’ll need to provide your api key and the environment (either testing
or production
)
from prometeo import Client
client = Client('<YOUR_API_KEY>', environment='testing')
Log in¶
session = client.banking.login(
provider='test',
username='12345',
password='gfdsa',
)
To get a list of available provider codes, use get_providers()
Becuase some banks require extra fields to log in, these must be provided inside kwargs
as a dictionary. To see if a provider requires extra auth fields to log in, use get_provider_detail()
Example with extra auth fields:
session = client.banking.login(
provider='bbva_mx',
username='12345',
password='gfdsa',
otp=11223
)
The following is a table with all the extra auth fields and their respective providers.
Field |
Provider |
Required |
Description |
---|---|---|---|
|
bbva_mx |
True |
One-time password |
|
banco_general, intermatico |
True |
Personal question |
|
banorte |
True |
Provider authorization token |
|
pe_bbva_netcash |
True |
Company code |
|
davivienda |
False |
|
Select client¶
In some banks a user can have access to more than one profile (called client), in those cases, the session status after login will be select_client
. It is then necessary to select the client, for that, first list the available clients and pass one to session.select_client
if session.get_status() == 'select_client':
clients = session.get_clients()
session.select_client(clients[0])
assert session.status == 'logged_in'
If the bank doesn’t uses multiple clients, calling get_clients
will return an empty list.
Handling security questions and OTPs¶
In cases where the bank requires additional steps to login, such as answering a personal security question or using a 2FA device like an OTP, the status of the session will be set as interaction_required
, which can be handled like this:
session = client.login(provider='test', username='user', password='pass')
if session.get_status() == 'interaction_required':
# necessary context, like the security question to answer.
print(session.get_interactive_context())
session.finish_login(
provider='test',
username='user',
password='pass',
answer='1234',
)
Restoring a session¶
In some cases it may be useful to serialize the session to be used later or to transfer to another process, like in a task queue job. For this use get_session_key()
and get_session()
:
session_key = session.get_session_key()
# save session_key somewhere...
restored_session = client.banking.get_session(session_key)
Listing accounts and movements¶
from datetime import datetime
accounts = session.get_accounts()
for account in accounts:
movements = account.get_movements(
datetime(2019, 2, 1), datetime(2019, 15, 1)
)
For more detailed information, refer to the docs for get_accounts()
and get_movements()
Listing credit cards and their movements¶
Credit cards can have movements in more than one currency, so it’s necessary to specify it when listing movements.
from datetime import datetime
cards = session.get_credit_cards()
for card in cards:
movements = card.get_movements(
'USD', datetime(2019, 2, 1), datetime(2019, 15, 1)
)
Listing available banks¶
We recommend that the list of available banks be stored on a database and updated weekly.
providers = client.banking.get_providers()
Preprocess transfer¶
preprocess = session.preprocess_transfer(
origin_account='002206345988',
destination_institution='0',
destination_account='001002363321',
currency='UYU',
amount='1.3',
concept='transfer description',
destination_owner_name='John Doe',
branch='62',
)
print(preprocess)
Confirm transfer¶
confirmation = session.confirm_transfer(
request_id='0b7d6b32d1be4c11bde21e7ddc08cc36',
authorization_type='cardCode',
authorization_data='1, 2, 3',
)
print(confirmation)
List transfer institutions¶
institutions_list = session.list_transfer_institutions()
for intitution in institutions_list:
print(intitution)