Skip to content

Commit

Permalink
Merge branch 'master' into payee-name
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd committed May 20, 2024
2 parents 87d6b89 + db6b4e4 commit ffdc968
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@actual-app/crdt": "2.1.0",
"@actual-app/web": "24.5.0",
"bcrypt": "^5.1.0",
"better-sqlite3": "^9.1.1",
"better-sqlite3": "^9.6.0",
"body-parser": "^1.20.1",
"cors": "^2.8.5",
"date-fns": "^2.30.0",
Expand Down
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));
},
};
22 changes: 22 additions & 0 deletions src/app-gocardless/banks/bnp-be-gebabebb.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,27 @@ export default {
* field in the remittanceInformationUnstructuredArray field.
*/
normalizeTransaction(transaction, _booked) {
// Extract the creditor name to fill it in with information from the
// additionalInformation field in case it's not yet defined.
let creditorName = transaction.creditorName;

if (transaction.additionalInformation) {
let additionalInformationObject = {};
const additionalInfoRegex = /(, )?([^:]+): ((\[.*?\])|([^,]*))/g;
let matches =
transaction.additionalInformation.matchAll(additionalInfoRegex);
if (matches) {
let creditorNameFromNarrative; // Possible value for creditorName
for (let match of matches) {
let key = match[2].trim();
let value = (match[4] || match[5]).trim();
if (key === 'narrative') {
// Set narrativeName to the first element in the "narrative" array.
creditorNameFromNarrative = value
.matchAll(/'([a-zA-Z0-9\s]*)'/g)
?.next()
.value[1].trim();
}
// Remove square brackets and single quotes and commas
value = value.replace(/[[\]',]/g, '');
additionalInformationObject[key] = value;
Expand All @@ -69,11 +81,21 @@ export default {
additionalInformationObject?.atmPosName ?? '',
additionalInformationObject?.narrative ?? '',
].filter(Boolean);

// If the creditor name doesn't exist in the original transactions,
// set it to the atmPosName or narrativeName if they exist; otherwise
// leave empty and let the default rules handle it.
creditorName =
creditorName ??
additionalInformationObject?.atmPosName ??
creditorNameFromNarrative ??
null;
}
}

return {
...transaction,
creditorName: creditorName,
date: transaction.valueDate || transaction.bookingDate,
payeeName: formatPayeeName(transaction),
};
Expand Down
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/349.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [vojeroen]
---

Ensure payee names don't contain transactional information when pulling in transactions from BNP bank with GoCardless.
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
6 changes: 6 additions & 0 deletions upcoming-release-notes/357.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MikesGlitch]
---

Update better-sqlite3 to 9.6.0
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": "npm:^5.51.0"
"@typescript-eslint/parser": "npm:^5.51.0"
bcrypt: "npm:^5.1.0"
better-sqlite3: "npm:^9.1.1"
better-sqlite3: "npm:^9.6.0"
body-parser: "npm:^1.20.1"
cors: "npm:^2.8.5"
date-fns: "npm:^2.30.0"
Expand Down Expand Up @@ -1922,14 +1922,14 @@ __metadata:
languageName: node
linkType: hard

"better-sqlite3@npm:^9.1.1":
version: 9.1.1
resolution: "better-sqlite3@npm:9.1.1"
"better-sqlite3@npm:^9.6.0":
version: 9.6.0
resolution: "better-sqlite3@npm:9.6.0"
dependencies:
bindings: "npm:^1.5.0"
node-gyp: "npm:latest"
prebuild-install: "npm:^7.1.1"
checksum: 2efb945ed741477401bd438db343db251702c7011eb1f4a5800c440afc89708ae6268c11a4331b18e0080a02fa1a2d6f48cef8df830710563fedb8b728f6d6da
checksum: 8db9b38f414e26a56d4c40fc16e94a253118491dae0e2c054338a9e470f1a883c7eb4cb330f2f5737db30f704d4f2e697c59071ca04e03364ee9fe04375aa9c8
languageName: node
linkType: hard

Expand Down

0 comments on commit ffdc968

Please sign in to comment.