Fetch account details and display
This commit is contained in:
@@ -3,13 +3,14 @@ from datetime import timedelta
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
|
||||
from core.clients.aggregator import AggregatorClient
|
||||
from core.clients.base import BaseClient
|
||||
from core.util import logs
|
||||
|
||||
log = logs.get_logger("nordigen")
|
||||
|
||||
|
||||
class NordigenClient(BaseClient):
|
||||
class NordigenClient(BaseClient, AggregatorClient):
|
||||
url = "https://ob.nordigen.com/api/v2"
|
||||
|
||||
async def connect(self):
|
||||
@@ -60,7 +61,7 @@ class NordigenClient(BaseClient):
|
||||
"""
|
||||
# This function is a stub.
|
||||
|
||||
return ["GB", "SE"]
|
||||
return ["GB", "SE", "BG", "UA"]
|
||||
|
||||
async def get_banks(self, country):
|
||||
"""
|
||||
@@ -128,28 +129,31 @@ class NordigenClient(BaseClient):
|
||||
|
||||
path = f"accounts/{account_id}/details"
|
||||
response = await self.call(path, schema="AccountDetails")
|
||||
print("RESPONSE", response)
|
||||
if "account" not in response:
|
||||
return False
|
||||
parsed = response["account"]
|
||||
if "bban" in parsed and parsed["currency"] == "GBP":
|
||||
sort_code = parsed["bban"][0:6]
|
||||
account_number = parsed["bban"][6:]
|
||||
del parsed["bban"]
|
||||
if "iban" in parsed:
|
||||
if "iban" in parsed and parsed["currency"] == "GBP":
|
||||
if parsed["iban"]:
|
||||
sort_code = parsed["iban"][-14:-8]
|
||||
account_number = parsed["iban"][-8:]
|
||||
del parsed["iban"]
|
||||
sort_code = "-".join(list(map("".join, zip(*[iter(sort_code)] * 2))))
|
||||
parsed["sort_code"] = sort_code
|
||||
parsed["number"] = account_number
|
||||
parsed["recipient"] = "TODO"
|
||||
# if "iban" in parsed:
|
||||
# del parsed["iban"]
|
||||
sort_code = "-".join(list(map("".join, zip(*[iter(sort_code)] * 2))))
|
||||
parsed["sort_code"] = sort_code
|
||||
parsed["number"] = account_number
|
||||
parsed["recipient"] = "TODO"
|
||||
# Let's add the account ID so we can reference it later
|
||||
parsed["account_id"] = account_id
|
||||
return parsed
|
||||
|
||||
async def get_all_account_info(self, requisition=None):
|
||||
async def get_all_account_info(self, requisition=None, store=False):
|
||||
to_return = {}
|
||||
if not requisition:
|
||||
raise NotImplementedError
|
||||
# requisitions = await self.get_requisitions()
|
||||
print("NOT REQUISITION")
|
||||
requisitions = await self.get_requisitions()
|
||||
print("GOT REQS", requisitions)
|
||||
else:
|
||||
requisitions = [await self.get_requisition(requisition)]
|
||||
|
||||
@@ -163,4 +167,8 @@ class NordigenClient(BaseClient):
|
||||
to_return[req["institution_id"]].append(account_info)
|
||||
else:
|
||||
to_return[req["institution_id"]] = [account_info]
|
||||
|
||||
if store:
|
||||
print("TO STORE IS TRUE")
|
||||
self.store_account_info(to_return)
|
||||
return to_return
|
||||
|
||||
Reference in New Issue
Block a user