From c51e636637187b88f887831a3504c3663f30d940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Mart=C3=ADnez=20Hostyn?= Date: Thu, 16 May 2024 20:56:51 +0200 Subject: [PATCH] Add BANKS_WITH_LIMITED_HISTORY constant and Implement BANKINTER_BKBKESMM Bank Adapter (#355) --- src/app-gocardless/bank-factory.js | 44 +++++++++++++ .../banks/bankinter-bkbkesmm.js | 64 +++++++++++++++++++ .../services/gocardless-service.js | 8 ++- upcoming-release-notes/355.md | 6 ++ 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 src/app-gocardless/banks/bankinter-bkbkesmm.js create mode 100644 upcoming-release-notes/355.md diff --git a/src/app-gocardless/bank-factory.js b/src/app-gocardless/bank-factory.js index 56bfb5464..45947c78d 100644 --- a/src/app-gocardless/bank-factory.js +++ b/src/app-gocardless/bank-factory.js @@ -1,4 +1,5 @@ import AmericanExpressAesudef1 from './banks/american-express-aesudef1.js'; +import BankinterBkbkesmm from './banks/bankinter-bkbkesmm.js'; import Belfius from './banks/belfius_gkccbebb.js'; import BnpBeGebabebb from './banks/bnp-be-gebabebb.js'; import DanskeBankDabNO22 from './banks/danskebank-dabno22.js'; @@ -16,6 +17,7 @@ import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js'; const banks = [ AmericanExpressAesudef1, + BankinterBkbkesmm, Belfius, BnpBeGebabebb, DanskeBankDabNO22, @@ -34,3 +36,45 @@ const banks = [ export default (institutionId) => banks.find((b) => b.institutionIds.includes(institutionId)) || IntegrationBank; + +export const BANKS_WITH_LIMITED_HISTORY = [ + 'BRED_BREDFRPPXXX', + 'INDUSTRA_MULTLV2X', + 'MEDICINOSBANK_MDBALT22XXX', + 'CESKA_SPORITELNA_LONG_GIBACZPX', + 'LHV_LHVBEE22', + 'LUMINOR_NDEALT2X', + 'LUMINOR_RIKOEE22', + 'LUMINOR_AGBLLT2X', + 'LUMINOR_NDEALV2X', + 'LUMINOR_NDEAEE2X', + 'LUMINOR_RIKOLV2X', + 'SWEDBANK_HABAEE2X', + 'SWEDBANK_HABALT22', + 'SWEDBANK_HABALV22', + 'SWEDBANK_SWEDSESS', + 'SEB_CBVILT2X', + 'SEB_UNLALV2X', + 'SEB_EEUHEE2X', + 'LABORALKUTXA_CLPEES2M', + 'BANKINTER_BKBKESMM', + 'CAIXABANK_CAIXESBB', + 'JEKYLL_JEYKLL002', + 'SANTANDER_DE_SCFBDE33', + 'BBVA_BBVAESMM', + 'COOP_EKRDEE22', + 'BANCA_AIDEXA_AIDXITMM', + 'BANCA_PATRIMONI_SENVITT1', + 'BANCA_SELLA_SELBIT2B', + 'CARTALIS_CIMTITR1', + 'DOTS_HYEEIT22', + 'HYPE_BUSINESS_HYEEIT22', + 'HYPE_HYEEIT2', + 'ILLIMITY_ITTPIT2M', + 'SMARTIKA_SELBIT22', + 'TIM_HYEEIT22', + 'TOT_SELBIT2B', + 'OPYN_BITAITRRB2B', + 'PAYTIPPER_PAYTITM1', + 'SELLA_PERSONAL_CREDIT_SELBIT22', +]; diff --git a/src/app-gocardless/banks/bankinter-bkbkesmm.js b/src/app-gocardless/banks/bankinter-bkbkesmm.js new file mode 100644 index 000000000..a14dfcdc1 --- /dev/null +++ b/src/app-gocardless/banks/bankinter-bkbkesmm.js @@ -0,0 +1,64 @@ +import { + printIban, + amountToInteger, + sortByBookingDateOrValueDate, +} from '../utils.js'; + +const SORTED_BALANCE_TYPE_LIST = [ + 'closingBooked', + 'expected', + 'forwardAvailable', + 'interimAvailable', + 'interimBooked', + 'nonInvoiced', + 'openingBooked', +]; + +/** @type {import('./bank.interface.js').IBank} */ +export default { + institutionIds: ['BANKINTER_BKBKESMM'], + + 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', + }; + }, + + normalizeTransaction(transaction, _booked) { + return { + ...transaction, + debtorName: transaction.debtorName?.replaceAll(';', ' '), + creditorName: transaction.creditorName?.replaceAll(';', ' '), + remittanceInformationUnstructured: + transaction.remittanceInformationUnstructured + .replaceAll(/\/Txt\/(\w\|)?/gi, '') + .replaceAll(';', ' '), + date: transaction.bookingDate || transaction.valueDate, + }; + }, + + sortTransactions(transactions = []) { + return sortByBookingDateOrValueDate(transactions); + }, + + calculateStartingBalance(sortedTransactions = [], balances = []) { + const currentBalance = balances + .filter((item) => SORTED_BALANCE_TYPE_LIST.includes(item.balanceType)) + .sort( + (a, b) => + SORTED_BALANCE_TYPE_LIST.indexOf(a.balanceType) - + SORTED_BALANCE_TYPE_LIST.indexOf(b.balanceType), + )[0]; + return sortedTransactions.reduce((total, trans) => { + return total - amountToInteger(trans.transactionAmount.amount); + }, amountToInteger(currentBalance?.balanceAmount?.amount || 0)); + }, +}; diff --git a/src/app-gocardless/services/gocardless-service.js b/src/app-gocardless/services/gocardless-service.js index 733d26b6d..7f32578b1 100644 --- a/src/app-gocardless/services/gocardless-service.js +++ b/src/app-gocardless/services/gocardless-service.js @@ -1,4 +1,4 @@ -import BankFactory from '../bank-factory.js'; +import BankFactory, { BANKS_WITH_LIMITED_HISTORY } from '../bank-factory.js'; import { RequisitionNotLinked, AccountNotLinedToRequisition, @@ -268,7 +268,11 @@ export const goCardlessService = { institutionId, referenceId: uuid.v4(), accessValidForDays: bank.accessValidForDays, - maxHistoricalDays: institution.transaction_total_days, + maxHistoricalDays: BANKS_WITH_LIMITED_HISTORY.includes(institutionId) + ? Number(institution.transaction_total_days) >= 90 + ? '89' + : institution.transaction_total_days + : institution.transaction_total_days, userLanguage: 'en', ssn: null, redirectImmediate: false, diff --git a/upcoming-release-notes/355.md b/upcoming-release-notes/355.md new file mode 100644 index 000000000..575f51b65 --- /dev/null +++ b/upcoming-release-notes/355.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [hostyn] +--- + +Add BANKS_WITH_LIMITED_HISTORY constant and Implement BANKINTER_BKBKESMM Bank Adapter