Make Nordigen and TrueLayer compatible with Transactions
This commit is contained in:
@@ -33,12 +33,12 @@ class Sinks(util.Base):
|
||||
self.truelayer = sinks.truelayer.TrueLayer(self)
|
||||
# setattr(self.truelayer, "sinks", self)
|
||||
|
||||
def got_transactions(self, bank, account_id, transactions):
|
||||
def got_transactions(self, subclass, account_id, transactions):
|
||||
if not transactions:
|
||||
return False
|
||||
transaction_ids = [x["transaction_id"] for x in transactions]
|
||||
new_key_name = f"new.transactions.{bank}.{account_id}"
|
||||
old_key_name = f"transactions.{bank}.{account_id}"
|
||||
new_key_name = f"new.transactions.{subclass}.{account_id}"
|
||||
old_key_name = f"transactions.{subclass}.{account_id}"
|
||||
# for transaction_id in transaction_ids:
|
||||
if not transaction_ids:
|
||||
return
|
||||
@@ -53,6 +53,7 @@ class Sinks(util.Base):
|
||||
# Rename the new key to the old key so we can run the diff again
|
||||
r.rename(new_key_name, old_key_name)
|
||||
for transaction in new_transactions:
|
||||
transaction["subclass"] = subclass
|
||||
self.tx.transaction(transaction)
|
||||
|
||||
def got_account_info(self, subclass, account_infos):
|
||||
|
||||
@@ -45,6 +45,14 @@ class Nordigen(util.Base):
|
||||
|
||||
self.sinks.got_account_info("nordigen", account_infos)
|
||||
|
||||
self.lc_tx = LoopingCall(self.transaction_loop)
|
||||
self.lc_tx.start(int(settings.Nordigen.RefreshSec))
|
||||
|
||||
def transaction_loop(self):
|
||||
for account_id in self.banks:
|
||||
transactions = self.get_transactions(account_id)
|
||||
self.sinks.got_transactions("nordigen", account_id, transactions)
|
||||
|
||||
def get_access_token(self):
|
||||
"""
|
||||
Get an access token.
|
||||
@@ -246,6 +254,23 @@ class Nordigen(util.Base):
|
||||
to_return[req["institution_id"]] = [account_info]
|
||||
return to_return
|
||||
|
||||
def normalise_transactions(self, transactions):
|
||||
for transaction in transactions:
|
||||
# Rename ID
|
||||
transaction["transaction_id"] = transaction["transactionId"]
|
||||
del transaction["transactionId"]
|
||||
|
||||
# Rename timestamp
|
||||
transaction["timestamp"] = transaction["bookingDate"]
|
||||
del transaction["bookingDate"]
|
||||
|
||||
transaction["amount"] = float(transaction["transactionAmount"]["amount"])
|
||||
transaction["currency"] = transaction["transactionAmount"]["currency"]
|
||||
del transaction["transactionAmount"]
|
||||
|
||||
transaction["reference"] = transaction["remittanceInformationUnstructured"]
|
||||
del transaction["remittanceInformationUnstructured"]
|
||||
|
||||
def get_transactions(self, account_id):
|
||||
"""
|
||||
Get all transactions for an account.
|
||||
@@ -257,4 +282,6 @@ class Nordigen(util.Base):
|
||||
path = f"{settings.Nordigen.Base}/accounts/{account_id}/transactions/"
|
||||
r = requests.get(path, headers=headers)
|
||||
obj = TXRoot.from_json(r.content)
|
||||
return obj.to_dict()["transactions"]["booked"]
|
||||
parsed = obj.to_dict()["transactions"]["booked"]
|
||||
self.normalise_transactions(parsed)
|
||||
return parsed
|
||||
|
||||
@@ -54,7 +54,7 @@ class TrueLayer(util.Base):
|
||||
for account_id in self.banks[bank]:
|
||||
# account_data = self.get_account(bank, account_id)
|
||||
transactions = self.get_transactions(bank, account_id)
|
||||
self.sinks.got_transactions(bank, account_id, transactions)
|
||||
self.sinks.got_transactions("truelayer", account_id, transactions)
|
||||
|
||||
def add_refresh_token(self, refresh_token):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user