Skip to content

A local-first personal finance app

Add BoursoBank GoCardless Integration (#4958)

Guillaume Taquet Gasperini6e5f4bfb1816
diff --git a/packages/sync-server/src/app-gocardless/bank-factory.js b/packages/sync-server/src/app-gocardless/bank-factory.js
index 2b5cb86341..52a8435913 100644
--- a/packages/sync-server/src/app-gocardless/bank-factory.js
+++ b/packages/sync-server/src/app-gocardless/bank-factory.js
@@ -39,6 +39,7 @@ export const BANKS_WITH_LIMITED_HISTORY = [
'BANKINTER_BKBKESMM',
'BBVA_BBVAESMM',
'BNP_PL_PPABPLPK',
+ 'BOURSORAMA_BOUSFRPP',
'BRED_BREDFRPPXXX',
'CAIXA_GERAL_DEPOSITOS_CGDIPTPL',
'CAIXABANK_CAIXESBB',
diff --git a/packages/sync-server/src/app-gocardless/banks/boursobank_bousfrppxxx.js b/packages/sync-server/src/app-gocardless/banks/boursobank_bousfrppxxx.js
new file mode 100644
index 0000000000..3b508d5f19
--- /dev/null
+++ b/packages/sync-server/src/app-gocardless/banks/boursobank_bousfrppxxx.js
@@ -0,0 +1,81 @@
+import { title } from '../../util/title/index.js';
+
+import Fallback from './integration-bank.js';
+
+const regexCard =
+ /^CARTE \d{2}\/\d{2}\/\d{2} (?<payeeName>.+?)( CB\*)?( ?\d{4,})?$/;
+const regexAtmWithdrawal =
+ /^RETRAIT DAB \d{2}\/\d{2}\/\d{2} (?<locationName>.+?) CB\*\d{4,}/;
+const regexTransfer = /^VIR /;
+const regexInstantTransfer = /^VIR INST /;
+const regexSepa = /^(PRLV|VIR) SEPA /;
+const regexLoan = /^ECH PRET:/;
+
+/** @type {import('./bank.interface.js').IBank} */
+export default {
+ ...Fallback,
+
+ institutionIds: ['BOURSORAMA_BOUSFRPP'],
+
+ normalizeTransaction(transaction, booked) {
+ const editedTrans = { ...transaction };
+
+ editedTrans.remittanceInformationUnstructuredArray =
+ // Remove the backslashes that are sometimes present
+ transaction.remittanceInformationUnstructuredArray
+ .map(line => line.replace(/\\ ?/g, ' '))
+ // Remove an unwanted line that pollutes the remittance information
+ .filter(line => line.startsWith('Réf : ') === false);
+
+ const infoArray = editedTrans.remittanceInformationUnstructuredArray;
+ const firstLine = infoArray[0];
+
+ if (firstLine.match(regexCard)) {
+ // Card transaction
+ const payeeName = firstLine.replace(regexCard, '$1');
+ editedTrans.payeeName = title(payeeName);
+ } else if (firstLine.match(regexInstantTransfer)) {
+ // Instant transfer
+ editedTrans.payeeName = title(
+ firstLine.replace(regexInstantTransfer, ''),
+ );
+ } else if (firstLine.match(regexSepa)) {
+ // SEPA transfer
+ editedTrans.payeeName = title(firstLine.replace(regexSepa, ''));
+ } else if (firstLine.match(regexTransfer) && infoArray.length > 1) {
+ // Other transfer
+ // Must be evaluated after the other transfers as they're more specific (here VIR only)
+ editedTrans.payeeName = title(infoArray[1]);
+ editedTrans.notes = firstLine.replace(regexTransfer, '');
+ } else if (firstLine.match(regexLoan)) {
+ // Loan
+ editedTrans.payeeName = 'Prêt bancaire';
+ editedTrans.notes = firstLine;
+ } else if (firstLine.match(regexAtmWithdrawal)) {
+ // ATM withdrawal
+ editedTrans.payeeName = 'Retrait DAB';
+ editedTrans.notes =
+ firstLine.match(regexAtmWithdrawal).groups.locationName;
+ if (infoArray.length > 1) {
+ editedTrans.notes += ' ' + infoArray[1];
+ }
+ } else {
+ editedTrans.payeeName = title(firstLine);
+ }
+
+ if (editedTrans.notes === undefined) {
+ // We managed to extract the payee name, but nothing specific in the notes
+
+ if (infoArray.length === 2) {
+ // If there are only two lines, the second one is the notes
+ editedTrans.notes = infoArray[1];
+ } else {
+ // Unfortunately, the order of the lines is not always the same, which causes issues on multiple syncs
+ // Thus, do not set the notes if we have more than two lines
+ editedTrans.notes = '';
+ }
+ }
+
+ return Fallback.normalizeTransaction(transaction, booked, editedTrans);
+ },
+};
diff --git a/packages/sync-server/src/app-gocardless/banks/tests/boursobank_bousfrppxxx.spec.js b/packages/sync-server/src/app-gocardless/banks/tests/boursobank_bousfrppxxx.spec.js
new file mode 100644
index 0000000000..e6024ed73a
--- /dev/null
+++ b/packages/sync-server/src/app-gocardless/banks/tests/boursobank_bousfrppxxx.spec.js
@@ -0,0 +1,115 @@
+import BoursoBank from '../boursobank_bousfrppxxx.js';
+
+describe('BoursoBank', () => {
+ describe('#normalizeTransaction', () => {
+ it.each([
+ [['CARTE 01/03/25 PAYEE NAME CB*4567'], 'Payee Name', ''],
+ [['CARTE 01/03/25 PAYEE NAME'], 'Payee Name', ''],
+ [['CARTE 01/03/25 PAYEE NAME 7428347'], 'Payee Name', ''],
+ [
+ [
+ 'CARTE 03/02/25 PAYEE NAME CB*1234',
+ '2,80 NZD / 1 euro = 1,818181818',
+ ],
+ 'Payee Name',
+ '2,80 NZD / 1 euro = 1,818181818',
+ ],
+ [
+ ['RETRAIT DAB 01/03/25 My location CB*9876'],
+ 'Retrait DAB',
+ 'My location',
+ ],
+ [
+ [
+ 'RETRAIT DAB 01/03/25 My location CB*9876',
+ '2,80 NZD / 1 euro = 1,818181818',
+ ],
+ 'Retrait DAB',
+ 'My location 2,80 NZD / 1 euro = 1,818181818',
+ ],
+ [
+ ['VIR Text put by the sender', 'PAYEE NAME'],
+ 'Payee Name',
+ 'Text put by the sender',
+ ],
+ [
+ [
+ 'VIR Text put by the sender',
+ 'PAYEE NAME',
+ 'Réf : SOME TEXT PUT BY THE BANK',
+ ],
+ 'Payee Name',
+ 'Text put by the sender',
+ ],
+ [
+ [
+ 'VIR Text put by the sender',
+ 'Réf : SOME TEXT PUT BY THE BANK',
+ 'PAYEE NAME',
+ ],
+ 'Payee Name',
+ 'Text put by the sender',
+ ],
+ [
+ ['VIR INST PAYEE NAME', 'Text put by the sender'],
+ 'Payee Name',
+ 'Text put by the sender',
+ ],
+ [
+ [
+ 'VIR SEPA PAYEE NAME',
+ 'SOME TEXT',
+ 'ANOTHER TEXT',
+ 'YET ANOTHER TEXT',
+ ],
+ 'Payee Name',
+ '',
+ ],
+ [
+ [
+ 'PRLV SEPA PAYEE NAME',
+ 'HERE IS SOMETHING',
+ 'SOME OTHER TEXT',
+ '30/04/2025',
+ 'PRELEVEMENT FOO BAR BAZ du',
+ ],
+ 'Payee Name',
+ '',
+ ],
+ [
+ ['ECH PRET:1823918329832913'],
+ 'Prêt bancaire',
+ 'ECH PRET:1823918329832913',
+ ],
+ [['PAYEE NAME'], 'Payee Name', ''],
+ [['PAYEE\\NAME\\ BIS'], 'Payee Name Bis', ''],
+ ])(
+ 'normalizes transaction with %s',
+ (
+ remittanceInformationUnstructuredArray,
+ expectedPayeeName,
+ expectedNotes,
+ ) => {
+ const transaction = {
+ transactionId: '1234567890',
+ bookingDate: '2025-01-01',
+ valueDate: '2025-01-01',
+ transactionAmount: {
+ amount: '100.00',
+ currency: 'EUR',
+ },
+ remittanceInformationUnstructuredArray,
+ internalTransactionId: 'abcdef1234567890',
+ };
+
+ const normalizedTransaction = BoursoBank.normalizeTransaction(
+ transaction,
+ true,
+ );
+
+ expect(normalizedTransaction.payeeName).toEqual(expectedPayeeName);
+ expect(normalizedTransaction.notes).toEqual(expectedNotes);
+ },
+ );
+ });
+});
diff --git a/upcoming-release-notes/4958.md b/upcoming-release-notes/4958.md
new file mode 100644
index 0000000000..f181096e31
--- /dev/null
+++ b/upcoming-release-notes/4958.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [Aerion]
+---
+
+Add BoursoBank GoCardless Integration