Implement removing accounts from Nordigen
This commit is contained in:
@@ -5,7 +5,16 @@ from twisted.internet.task import LoopingCall
|
||||
import requests
|
||||
from simplejson.errors import JSONDecodeError
|
||||
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
|
||||
|
||||
# Project imports
|
||||
@@ -163,6 +172,21 @@ class Nordigen(util.Base):
|
||||
|
||||
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):
|
||||
"""
|
||||
Get a list of accounts for a requisition.
|
||||
@@ -231,6 +255,24 @@ class Nordigen(util.Base):
|
||||
|
||||
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):
|
||||
to_return = {}
|
||||
requisitions = self.get_requisitions()
|
||||
|
||||
Reference in New Issue
Block a user