Implement getting bank account details
This commit is contained in:
@@ -104,3 +104,78 @@ class NordigenClient(BaseClient):
|
||||
path, schema="RequisitionDelete", http_method="delete"
|
||||
)
|
||||
return response
|
||||
|
||||
async def get_requisition(self, requisition):
|
||||
"""
|
||||
Get a list of accounts for a requisition.
|
||||
:param requisition: requisition ID"""
|
||||
path = f"requisitions/{requisition}"
|
||||
response = await self.call(path, schema="Requisition")
|
||||
|
||||
return response
|
||||
|
||||
# def get_ownernames(self):
|
||||
# """
|
||||
# Get list of supplementary owner names.
|
||||
# """
|
||||
# ownernames = loads(settings.Nordigen.OwnerNames)
|
||||
# return ownernames
|
||||
|
||||
async def get_account(self, account_id):
|
||||
"""
|
||||
Get details of an account.
|
||||
:param requisition: requisition ID"""
|
||||
|
||||
path = f"accounts/{account_id}/details"
|
||||
response = await self.call(path, schema="AccountDetails")
|
||||
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:]
|
||||
# if "ownerName" not in parsed:
|
||||
# ownernames = self.get_ownernames()
|
||||
# if account_id in ownernames:
|
||||
# parsed["ownerName"] = ownernames[account_id]
|
||||
|
||||
# else:
|
||||
# return False
|
||||
# recipient = parsed["ownerName"]
|
||||
del parsed["bban"]
|
||||
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
|
||||
print("PARSED", parsed)
|
||||
return parsed
|
||||
|
||||
async def get_all_account_info(self, requisition=None):
|
||||
print("GET ALL ACCOU T INFO", requisition)
|
||||
to_return = {}
|
||||
if not requisition:
|
||||
raise NotImplementedError
|
||||
# requisitions = await self.get_requisitions()
|
||||
else:
|
||||
requisitions = [await self.get_requisition(requisition)]
|
||||
print("REQUISITIONS", requisitions)
|
||||
|
||||
print("REQUISITIONS", requisitions)
|
||||
|
||||
for req in requisitions:
|
||||
print("REQ ITER", req)
|
||||
accounts = req["accounts"]
|
||||
print("ACCOUNTS", accounts)
|
||||
for account_id in accounts:
|
||||
account_info = await self.get_account(account_id)
|
||||
if not account_info:
|
||||
continue
|
||||
if req["institution_id"] in to_return:
|
||||
to_return[req["institution_id"]].append(account_info)
|
||||
else:
|
||||
to_return[req["institution_id"]] = [account_info]
|
||||
return to_return
|
||||
|
||||
Reference in New Issue
Block a user