diff --git a/src/app-gocardless/bank-factory.js b/src/app-gocardless/bank-factory.js index a38afa3bc..5b47710d2 100644 --- a/src/app-gocardless/bank-factory.js +++ b/src/app-gocardless/bank-factory.js @@ -8,6 +8,7 @@ import BnpBeGebabebb from './banks/bnp-be-gebabebb.js'; import CBCcregbebb from './banks/cbc_cregbebb.js'; import DanskeBankDabNO22 from './banks/danskebank-dabno22.js'; import EasybankBawaatww from './banks/easybank-bawaatww.js'; +import EntercardSwednokk from './banks/entercard-swednokk.js'; import Fortuneo from './banks/FORTUNEO_FTNOFRP1XXX.js'; import IngIngbrobu from './banks/ing-ingbrobu.js'; import IngIngddeff from './banks/ing-ingddeff.js'; @@ -19,9 +20,9 @@ import NationwideNaiaGB21 from './banks/nationwide-naiagb21.js'; import NbgEthngraaxxx from './banks/nbg_ethngraaxxx.js'; import NorwegianXxNorwnok1 from './banks/norwegian-xx-norwnok1.js'; import RevolutRevolt21 from './banks/revolut_revolt21.js'; -import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js'; import SEBKortBankAB from './banks/seb-kort-bank-ab.js'; import SEBPrivat from './banks/seb-privat.js'; +import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js'; import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js'; import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js'; import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js'; @@ -40,6 +41,7 @@ export const banks = [ CBCcregbebb, DanskeBankDabNO22, EasybankBawaatww, + EntercardSwednokk, Fortuneo, IngIngbrobu, IngIngddeff, @@ -50,9 +52,9 @@ export const banks = [ NbgEthngraaxxx, NorwegianXxNorwnok1, RevolutRevolt21, - SandboxfinanceSfin0000, SEBKortBankAB, SEBPrivat, + SandboxfinanceSfin0000, SparNordSpNoDK22, SpkKarlsruhekarsde66, SpkMarburgBiedenkopfHeladef1mar, diff --git a/src/app-gocardless/banks/entercard-swednokk.js b/src/app-gocardless/banks/entercard-swednokk.js new file mode 100644 index 000000000..2742e83bf --- /dev/null +++ b/src/app-gocardless/banks/entercard-swednokk.js @@ -0,0 +1,59 @@ +import * as d from 'date-fns'; +import { + amountToInteger, + printIban, + sortByBookingDateOrValueDate, +} from '../utils.js'; +import { formatPayeeName } from '../../util/payee-name.js'; + +/** @type {import('./bank.interface.js').IBank} */ +export default { + institutionIds: ['ENTERCARD_SWEDNOKK'], + + accessValidForDays: 180, + + normalizeAccount(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) { + // GoCardless's Entercard integration returns forex transactions with the + // foreign amount in `transactionAmount`, but at least the amount actually + // billed to the account is now available in + // `remittanceInformationUnstructured`. + const remittanceInformationUnstructured = + transaction.remittanceInformationUnstructured; + if (remittanceInformationUnstructured.startsWith('billingAmount: ')) { + transaction.transactionAmount = { + amount: remittanceInformationUnstructured.substring(15), + currency: 'SEK', + }; + } + + return { + ...transaction, + payeeName: formatPayeeName(transaction), + date: d.format(d.parseISO(transaction.valueDate), 'yyyy-MM-dd'), + }; + }, + + sortTransactions(transactions = []) { + return sortByBookingDateOrValueDate(transactions); + }, + + calculateStartingBalance(sortedTransactions = [], balances = []) { + return sortedTransactions.reduce((total, trans) => { + return total - amountToInteger(trans.transactionAmount.amount); + }, amountToInteger(balances[0]?.balanceAmount?.amount || 0)); + }, +}; diff --git a/upcoming-release-notes/506.md b/upcoming-release-notes/506.md new file mode 100644 index 000000000..a863badfb --- /dev/null +++ b/upcoming-release-notes/506.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [kyrias] +--- + +Add GoCardless integration for ENTERCARD_SWEDNOKK