Extra attributes for Barclays
This commit is contained in:
parent
38c82862a4
commit
a222bce6db
|
@ -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,9 +261,15 @@ 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}")
|
||||
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"]
|
||||
if "iban" in parsed:
|
||||
del parsed["iban"]
|
||||
sort_code = "-".join(list(map("".join, zip(*[iter(sort_code)] * 2))))
|
||||
parsed["sort_code"] = sort_code
|
||||
|
@ -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"]
|
||||
|
|
Loading…
Reference in New Issue