Skip to content

Commit

Permalink
Add BANKS_WITH_LIMITED_HISTORY constant and Implement BANKINTER_BKBKE…
Browse files Browse the repository at this point in the history
…SMM Bank Adapter (#355)
  • Loading branch information
hostyn authored May 16, 2024
1 parent 3a486ed commit c51e636
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
44 changes: 44 additions & 0 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -16,6 +17,7 @@ import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js';

const banks = [
AmericanExpressAesudef1,
BankinterBkbkesmm,
Belfius,
BnpBeGebabebb,
DanskeBankDabNO22,
Expand All @@ -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',
];
64 changes: 64 additions & 0 deletions src/app-gocardless/banks/bankinter-bkbkesmm.js
Original file line number Diff line number Diff line change
@@ -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));
},
};
8 changes: 6 additions & 2 deletions src/app-gocardless/services/gocardless-service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BankFactory from '../bank-factory.js';
import BankFactory, { BANKS_WITH_LIMITED_HISTORY } from '../bank-factory.js';
import {
RequisitionNotLinked,
AccountNotLinedToRequisition,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/355.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [hostyn]
---

Add BANKS_WITH_LIMITED_HISTORY constant and Implement BANKINTER_BKBKESMM Bank Adapter

0 comments on commit c51e636

Please sign in to comment.