Fix transaction IDs and make Nordigen validation stricter
This commit is contained in:
parent
af65433c55
commit
6d6b370327
|
@ -1,9 +1,9 @@
|
|||
from datetime import timedelta
|
||||
from hashlib import sha256
|
||||
|
||||
import orjson
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from orjson import dumps
|
||||
|
||||
from core.clients.aggregator import AggregatorClient
|
||||
from core.clients.base import BaseClient
|
||||
|
@ -250,17 +250,16 @@ class NordigenClient(BaseClient, AggregatorClient):
|
|||
def normalise_transactions(self, transactions, state=None):
|
||||
for transaction in transactions:
|
||||
# Rename ID
|
||||
if "transactionId" in transaction:
|
||||
if transaction["transactionId"]:
|
||||
transaction["transaction_id"] = transaction["transactionId"]
|
||||
del transaction["transactionId"]
|
||||
elif "internalTransactionId" in transaction:
|
||||
elif transaction["internalTransactionId"]:
|
||||
transaction["transaction_id"] = transaction["internalTransactionId"]
|
||||
del transaction["internalTransactionId"]
|
||||
else:
|
||||
# No transaction ID. This is a problem for our implementation
|
||||
|
||||
tx_hash = sha256(
|
||||
dumps(transaction, sort_keys=True).encode("utf8")
|
||||
orjson.dumps(transaction, option=orjson.OPT_SORT_KEYS)
|
||||
).hexdigest()
|
||||
transaction["transaction_id"] = tx_hash
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class MyModel(BaseModel):
|
|||
# TODO: inherit from MyModel
|
||||
|
||||
|
||||
class TokenNew(BaseModel):
|
||||
class TokenNew(MyModel):
|
||||
access: str
|
||||
access_expires: int
|
||||
refresh: str
|
||||
|
@ -24,7 +24,7 @@ TokenNewSchema = {
|
|||
}
|
||||
|
||||
|
||||
class RequisitionResult(BaseModel):
|
||||
class RequisitionResult(MyModel):
|
||||
id: str
|
||||
created: str
|
||||
redirect: str
|
||||
|
@ -39,7 +39,7 @@ class RequisitionResult(BaseModel):
|
|||
redirect_immediate: bool
|
||||
|
||||
|
||||
class Requisitions(BaseModel):
|
||||
class Requisitions(MyModel):
|
||||
count: int
|
||||
next: str | None
|
||||
previous: str | None
|
||||
|
@ -54,7 +54,7 @@ RequisitionsSchema = {
|
|||
}
|
||||
|
||||
|
||||
class RequisitionsPost(BaseModel):
|
||||
class RequisitionsPost(MyModel):
|
||||
id: str
|
||||
created: str
|
||||
redirect: str
|
||||
|
@ -85,7 +85,7 @@ RequisitionsPostSchema = {
|
|||
}
|
||||
|
||||
|
||||
class Requisition(BaseModel):
|
||||
class Requisition(MyModel):
|
||||
id: str
|
||||
created: str
|
||||
redirect: str
|
||||
|
@ -116,7 +116,7 @@ RequisitionSchema = {
|
|||
}
|
||||
|
||||
|
||||
class AccountDetailsNested(BaseModel):
|
||||
class AccountDetailsNested(MyModel):
|
||||
resourceId: str
|
||||
currency: str
|
||||
ownerName: str
|
||||
|
@ -128,9 +128,10 @@ class AccountDetailsNested(BaseModel):
|
|||
bban: str | None
|
||||
name: str | None
|
||||
product: str | None
|
||||
bic: str | None
|
||||
|
||||
|
||||
class AccountDetails(BaseModel):
|
||||
class AccountDetails(MyModel):
|
||||
account: AccountDetailsNested
|
||||
|
||||
|
||||
|
@ -139,13 +140,13 @@ AccountDetailsSchema = {
|
|||
}
|
||||
|
||||
|
||||
class AccountBalance(BaseModel):
|
||||
class AccountBalance(MyModel):
|
||||
balanceAmount: dict[str, str]
|
||||
balanceType: str | None
|
||||
referenceDate: str | None
|
||||
|
||||
|
||||
class AccountBalances(BaseModel):
|
||||
class AccountBalances(MyModel):
|
||||
balances: list[AccountBalance]
|
||||
summary: str | None
|
||||
|
||||
|
@ -156,12 +157,12 @@ AccountBalancesSchema = {
|
|||
}
|
||||
|
||||
|
||||
class TXCurrencyAmount(BaseModel):
|
||||
class TXCurrencyAmount(MyModel):
|
||||
amount: str
|
||||
currency: str
|
||||
|
||||
|
||||
class TransactionsCurrencyExchange(BaseModel):
|
||||
class TransactionsCurrencyExchange(MyModel):
|
||||
instructedAmount: TXCurrencyAmount
|
||||
sourceCurrency: str
|
||||
exchangeRate: str
|
||||
|
@ -169,15 +170,15 @@ class TransactionsCurrencyExchange(BaseModel):
|
|||
targetCurrency: str
|
||||
|
||||
|
||||
class TXAccount(BaseModel):
|
||||
class TXAccount(MyModel):
|
||||
iban: str
|
||||
bban: str | None
|
||||
|
||||
|
||||
class TransactionsNested(BaseModel):
|
||||
class TransactionsNested(MyModel):
|
||||
transactionId: str | None
|
||||
bookingDate: str | None
|
||||
valueDate: str
|
||||
valueDate: str | None
|
||||
bookingDateTime: str | None
|
||||
valueDateTime: str | None
|
||||
transactionAmount: TXCurrencyAmount
|
||||
|
@ -192,12 +193,12 @@ class TransactionsNested(BaseModel):
|
|||
currencyExchange: TransactionsCurrencyExchange | None
|
||||
|
||||
|
||||
class TransactionsBookedPending(BaseModel):
|
||||
class TransactionsBookedPending(MyModel):
|
||||
booked: list[TransactionsNested]
|
||||
pending: list[TransactionsNested]
|
||||
|
||||
|
||||
class Transactions(BaseModel):
|
||||
class Transactions(MyModel):
|
||||
transactions: TransactionsBookedPending
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue