From c63885f0770391d1dc2058053f05ee65946f0082 Mon Sep 17 00:00:00 2001 From: hsk-dk Date: Fri, 27 Sep 2024 12:51:25 +0200 Subject: [PATCH] Create nordea_ndeadkkk.js --- src/app-gocardless/banks/nordea_ndeadkkk.js | 67 +++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/app-gocardless/banks/nordea_ndeadkkk.js diff --git a/src/app-gocardless/banks/nordea_ndeadkkk.js b/src/app-gocardless/banks/nordea_ndeadkkk.js new file mode 100644 index 000000000..02981c0ce --- /dev/null +++ b/src/app-gocardless/banks/nordea_ndeadkkk.js @@ -0,0 +1,67 @@ +import Fallback from './integration-bank.js'; + +import { printIban, amountToInteger } from '../utils.js'; +import { formatPayeeName } from '../../util/payee-name.js'; + +/** @type {import('./bank.interface.js').IBank} */ +export default { + ...Fallback, + + institutionIds: ['NORDEA_NDEADKKK'], + + accessValidForDays: 90, + + normalizeAccount(account) { + return { + account_id: account.id, + institution: account.institution, + mask: account.iban.slice(-4), + iban: account.iban, + name: [account.name, printIban(account)].join(' '), + official_name: account.product, + type: 'checking', + }; + }, + + /** + * Following the GoCardless documentation[0] we should prefer `bookingDate` + * here, though some of their bank integrations uses the date field + * differently from what's described in their documentation and so it's + * sometimes necessary to use `valueDate` instead. + * + * [0]: https://nordigen.zendesk.com/hc/en-gb/articles/7899367372829-valueDate-and-bookingDate-for-transactions + */ + normalizeTransaction(transaction, _booked) { + //transactions "transactionId" starts with P must be ignored + if ( + transaction.transactionId.startsWith( + 'P', + ) + ) { + return {Null}; + } + return { + ...transaction, + payeeName: formatPayeeName(transaction), + date: transaction.bookingDate || transaction.valueDate, + }; + }, + + /** + * For NORDEA_NDEADKKK we don't know what balance was + * after each transaction so we have to calculate it by getting + * current balance from the account and subtract all the transactions + * + * As a current balance we use `interimBooked` balance type because + * it includes transaction placed during current day + */ + calculateStartingBalance(sortedTransactions = [], balances = []) { + const currentBalance = balances.find( + (balance) => 'interimAvailable' === balance.balanceType, + ); + + return sortedTransactions.reduce((total, trans) => { + return total - amountToInteger(trans.transactionAmount.amount); + }, amountToInteger(currentBalance.balanceAmount.amount)); + }, +};