Implement removing accounts from Nordigen

master
Mark Veidemanis 2 years ago
parent a7a2bb729c
commit f85342dc2e
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -97,3 +97,8 @@ class AccountBalances(Model):
class AccountBalancesRoot(Model): class AccountBalancesRoot(Model):
balances = fields.List(AccountBalances) balances = fields.List(AccountBalances)
class RequisitionResponse(Model):
summary: fields.Str()
detail: fields.Str()

@ -5,7 +5,16 @@ from twisted.internet.task import LoopingCall
import requests import requests
from simplejson.errors import JSONDecodeError from simplejson.errors import JSONDecodeError
from json import dumps, loads from json import dumps, loads
from lib.serde.nordigen import TXRoot, AccessToken, Institutions, Agreement, Requisitions, AccountDetails, AccountBalancesRoot from lib.serde.nordigen import (
TXRoot,
AccessToken,
Institutions,
Agreement,
Requisitions,
AccountDetails,
AccountBalancesRoot,
RequisitionResponse,
)
from serde import ValidationError from serde import ValidationError
# Project imports # Project imports
@ -163,6 +172,21 @@ class Nordigen(util.Base):
return False return False
def delete_requisition(self, requisition_id):
"""
Delete a requisision ID.
"""
headers = {"accept": "application/json", "Authorization": f"Bearer {self.token}"}
path = f"{settings.Nordigen.Base}/requisitions/{requisition_id}/"
r = requests.delete(path, headers=headers)
try:
obj = RequisitionResponse.from_json(r.content)
except ValidationError as err:
self.log.error(f"Validation error: {err}")
return
parsed = obj.to_dict()
return parsed
def get_accounts(self, requisition): def get_accounts(self, requisition):
""" """
Get a list of accounts for a requisition. Get a list of accounts for a requisition.
@ -231,6 +255,24 @@ class Nordigen(util.Base):
return currency return currency
def unmap_account(self, account_id):
"""
Unmap an account_id at a bank to an account_name.
This disables the account for fetching.
Data type: {"monzo": [account, ids, here],
"revolut": [account, ids, here]}
"""
existing_entry = loads(settings.Nordigen.Maps)
if account_id not in existing_entry:
return
else:
existing_entry.remove(account_id)
settings.Nordigen.Maps = dumps(existing_entry)
self.banks = existing_entry
settings.write()
def get_all_account_info(self): def get_all_account_info(self):
to_return = {} to_return = {}
requisitions = self.get_requisitions() requisitions = self.get_requisitions()

@ -586,6 +586,32 @@ class IRCCommands(object):
reference = transaction["reference"] reference = transaction["reference"]
msg(f"{timestamp} {txid} {amount}{currency} {reference}") msg(f"{timestamp} {txid} {amount}{currency} {reference}")
class nreqs(object):
name = "nreqs"
authed = True
helptext = "Get a list of requisitions from Nordigen."
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
reqs = tx.sinks.nordigen.get_requisitions()
for req in reqs:
id = req["id"]
institution_id = req["institution_id"]
redirect = req["link"]
msg(f"{id} {institution_id} {redirect}")
class ndelreq(object):
name = "ndelreq"
authed = True
helptext = "Delete a requisition from Nordigen."
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 2:
requisition_id = spl[1]
rtrn = tx.sinks.nordigen.delete_requisition(requisition_id)
msg(f"{rtrn['summary']}")
class mapaccount(object): class mapaccount(object):
name = "mapaccount" name = "mapaccount"
authed = True authed = True
@ -605,7 +631,7 @@ class IRCCommands(object):
class nmapaccount(object): class nmapaccount(object):
name = "nmapaccount" name = "nmapaccount"
authed = True authed = True
helptext = "Enable an account_id at a bank for use in Nordigen. Usage: nmapaccount <bank> <account_id>" helptext = "Enable an account_id at a bank for use in Nordigen. Usage: nmapaccount <account_id>"
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def run(cmd, spl, length, authed, msg, agora, tx, ux):
@ -617,6 +643,18 @@ class IRCCommands(object):
return return
msg(f"Mapped account ID {account_id} to {account_name}") msg(f"Mapped account ID {account_id} to {account_name}")
class nunmapaccount(object):
name = "nunmapaccount"
authed = True
helptext = "Disable an account_id at a bank for use in Nordigen. Usage: nunmapaccount <account_id>"
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 2:
account_id = spl[1]
tx.sinks.nordigen.unmap_account(account_id)
msg(f"Unmapped account ID {account_id}")
class unmapped(object): class unmapped(object):
name = "unmapped" name = "unmapped"
authed = True authed = True

Loading…
Cancel
Save