From a222bce6dbc063855b70ab1f38150af0a6599ef5 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 29 Apr 2022 11:34:01 +0100 Subject: [PATCH] Extra attributes for Barclays --- handler/sinks/nordigen.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/handler/sinks/nordigen.py b/handler/sinks/nordigen.py index 37a9f21..c24159b 100644 --- a/handler/sinks/nordigen.py +++ b/handler/sinks/nordigen.py @@ -16,6 +16,7 @@ from lib.serde.nordigen import ( RequisitionResponse, ) from serde import ValidationError +from hashlib import sha256 # Project imports from settings import settings @@ -228,6 +229,13 @@ class Nordigen(util.Base): return parsed["accounts"] 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): """ Get details of an account. @@ -238,6 +246,7 @@ class Nordigen(util.Base): } path = f"{settings.Nordigen.Base}/accounts/{account_id}/details/" r = requests.get(path, headers=headers) + print("GET ACCOUNT", account_id, r.content) try: obj = AccountDetails.from_json(r.content) except ValidationError as err: @@ -252,10 +261,16 @@ class Nordigen(util.Base): account_number = parsed["bban"][6:] if "ownerName" not in parsed: 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"] del parsed["bban"] - del parsed["iban"] + 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 @@ -334,6 +349,12 @@ class Nordigen(util.Base): if "transactionId" in transaction: transaction["transaction_id"] = 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 transaction["timestamp"] = transaction["bookingDate"]