Extra attributes for Barclays

This commit is contained in:
Mark Veidemanis 2022-04-29 11:34:01 +01:00
parent 38c82862a4
commit a222bce6db
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 23 additions and 2 deletions

View File

@ -16,6 +16,7 @@ from lib.serde.nordigen import (
RequisitionResponse, RequisitionResponse,
) )
from serde import ValidationError from serde import ValidationError
from hashlib import sha256
# Project imports # Project imports
from settings import settings from settings import settings
@ -228,6 +229,13 @@ class Nordigen(util.Base):
return parsed["accounts"] return parsed["accounts"]
return False return False
def get_ownernames(self):
"""
Get list of supplementary owner names.
"""
ownernames = loads(settings.Nordigen.OwnerNames)
return ownernames
def get_account(self, account_id): def get_account(self, account_id):
""" """
Get details of an account. Get details of an account.
@ -238,6 +246,7 @@ class Nordigen(util.Base):
} }
path = f"{settings.Nordigen.Base}/accounts/{account_id}/details/" path = f"{settings.Nordigen.Base}/accounts/{account_id}/details/"
r = requests.get(path, headers=headers) r = requests.get(path, headers=headers)
print("GET ACCOUNT", account_id, r.content)
try: try:
obj = AccountDetails.from_json(r.content) obj = AccountDetails.from_json(r.content)
except ValidationError as err: except ValidationError as err:
@ -252,10 +261,16 @@ class Nordigen(util.Base):
account_number = parsed["bban"][6:] account_number = parsed["bban"][6:]
if "ownerName" not in parsed: if "ownerName" not in parsed:
self.log.warning(f"No owner name in parsed, cannot use: {account_id}") self.log.warning(f"No owner name in parsed, cannot use: {account_id}")
return False ownernames = self.get_ownernames()
if account_id in ownernames:
parsed["ownerName"] = ownernames[account_id]
self.log.info(f"Found supplementary owner name for {account_id}: {ownernames[account_id]}")
else:
return False
recipient = parsed["ownerName"] recipient = parsed["ownerName"]
del parsed["bban"] del parsed["bban"]
del parsed["iban"] if "iban" in parsed:
del parsed["iban"]
sort_code = "-".join(list(map("".join, zip(*[iter(sort_code)] * 2)))) sort_code = "-".join(list(map("".join, zip(*[iter(sort_code)] * 2))))
parsed["sort_code"] = sort_code parsed["sort_code"] = sort_code
parsed["number"] = account_number parsed["number"] = account_number
@ -334,6 +349,12 @@ class Nordigen(util.Base):
if "transactionId" in transaction: if "transactionId" in transaction:
transaction["transaction_id"] = transaction["transactionId"] transaction["transaction_id"] = transaction["transactionId"]
del transaction["transactionId"] del transaction["transactionId"]
else:
# No transaction ID. This is a problem for our implementation
tx_hash = sha256(dumps(transaction, sort_keys=True).encode("utf8")).hexdigest()
print("tx_hash", tx_hash)
transaction["transaction_id"] = tx_hash
# Rename timestamp # Rename timestamp
transaction["timestamp"] = transaction["bookingDate"] transaction["timestamp"] = transaction["bookingDate"]