A local-first personal finance app
feat: add SEB Privat bank (#316)
Martin Myhrman6e9eddeb561b
diff --git a/src/app-gocardless/bank-factory.js b/src/app-gocardless/bank-factory.jsindex f0c30b625a..42bc1384d9 100644--- a/src/app-gocardless/bank-factory.js+++ b/src/app-gocardless/bank-factory.js@@ -10,6 +10,7 @@ import DanskeBankDabNO22 from './banks/danskebank-dabno22.js';import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';import Belfius from './banks/belfius_gkccbebb.js';import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';+import SEBPrivat from './banks/seb-privat.js';const banks = [AmericanExpressAesudef1,@@ -23,6 +24,7 @@ const banks = [SparNordSpNoDK22,Belfius,SpkMarburgBiedenkopfHeladef1mar,+ SEBPrivat,];export default (institutionId) =>diff --git a/src/app-gocardless/banks/seb-privat.js b/src/app-gocardless/banks/seb-privat.jsnew file mode 100644index 0000000000..a7ac8cd59c--- /dev/null+++ b/src/app-gocardless/banks/seb-privat.js@@ -0,0 +1,67 @@+import * as d from 'date-fns';+import {+ sortByBookingDateOrValueDate,+ amountToInteger,+ printIban,+} from '../utils.js';++/** @type {import('./bank.interface.js').IBank} */+export default {+ institutionIds: ['SEB_ESSESESS_PRIVATE'],+ normalizeAccount(account) {+ console.log(+ 'Available account properties for new institution integration',+ { account: JSON.stringify(account) },+ );++ return {+ account_id: account.id,+ institution: account.institution,+ mask: (account?.iban || '0000').slice(-4),+ iban: account?.iban || null,+ name: [account.name, printIban(account), account.currency]+ .filter(Boolean)+ .join(' '),+ official_name: `integration-${account.institution_id}`,+ type: 'checking',+ };+ },++ normalizeTransaction(transaction, _booked) {+ const date =+ transaction.bookingDate ||+ transaction.bookingDateTime ||+ transaction.valueDate ||+ transaction.valueDateTime;+ // If we couldn't find a valid date field we filter out this transaction+ // and hope that we will import it again once the bank has processed the+ // transaction further.+ if (!date) {+ return null;+ }+ return {+ ...transaction,+ // Creditor name is stored in additionInformation for SEB+ creditorName: transaction.additionalInformation,+ date: d.format(d.parseISO(date), 'yyyy-MM-dd'),+ };+ },++ sortTransactions(transactions = []) {+ console.log(+ 'Available (first 10) transactions properties for new integration of institution in sortTransactions function',+ { top10Transactions: JSON.stringify(transactions.slice(0, 10)) },+ );+ return sortByBookingDateOrValueDate(transactions);+ },++ calculateStartingBalance(sortedTransactions = [], balances = []) {+ const currentBalance = balances.find(+ (balance) => 'interimBooked' === balance.balanceType,+ );++ return sortedTransactions.reduce((total, trans) => {+ return total - amountToInteger(trans.transactionAmount.amount);+ }, amountToInteger(currentBalance.balanceAmount.amount));+ },+};diff --git a/upcoming-release-notes/316.md b/upcoming-release-notes/316.mdnew file mode 100644index 0000000000..b3d2665794--- /dev/null+++ b/upcoming-release-notes/316.md@@ -0,0 +1,6 @@+---+category: Features+authors: [myhrmans]+---++Add SEB Private Bank integration to gocardless. Handle that SEB is sending the creditor name in additionalInfo.\ No newline at end of file