Skip to content

Commit

Permalink
Add FINTRO_BE_GEBABEBB GoCardless integration (Include additionalInfo…
Browse files Browse the repository at this point in the history
…rmation in notes) (#242)
  • Loading branch information
CharlieMK authored Aug 9, 2023
1 parent 52c1676 commit 09380db
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import IntegrationBank from './banks/integration-bank.js';
import MbankRetailBrexplpw from './banks/mbank-retail-brexplpw.js';
import NorwegianXxNorwnok1 from './banks/norwegian-xx-norwnok1.js';
import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
import FintroBeGebabebb from './banks/fintro-be-gebabebb.js';

const banks = [
AmericanExpressAesudef1,
IngPlIngbplpw,
MbankRetailBrexplpw,
SandboxfinanceSfin0000,
NorwegianXxNorwnok1,
FintroBeGebabebb,
];

export default (institutionId) =>
Expand Down
105 changes: 105 additions & 0 deletions src/app-gocardless/banks/fintro-be-gebabebb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import {
sortByBookingDateOrValueDate,
amountToInteger,
printIban,
} from '../utils.js';

const SORTED_BALANCE_TYPE_LIST = [
'closingBooked',
'expected',
'forwardAvailable',
'interimAvailable',
'interimBooked',
'nonInvoiced',
'openingBooked',
];

/** @type {import('./bank.interface.js').IBank} */
export default {
institutionIds: ['FINTRO_BE_GEBABEBB'],

normalizeAccount(account) {
console.log(
'Available account properties for new institution integration',
{ account: JSON.stringify(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',
};
},

/** FINTRO_BE_GEBABEBB provides a lot of useful information via the 'additionalField'
* There does not seem to be a specification of this field, but the following information is contained in its subfields:
* - for pending transactions: the 'atmPosName'
* - for booked transactions: the 'narrative'.
* This narrative subfield is most useful as it contains information required to identify the transaction,
* especially in case of debit card or instant payment transactions.
* Do note that the narrative subfield ALSO contains the remittance information if any.
* The goal of the normalization is to place any relevant information of the additionalInformation
* field in the remittanceInformationUnstructuredArray field.
*/
normalizeTransaction(transaction, _booked) {
if (transaction.additionalInformation) {
let additionalInformationObject = {};
const additionalInfoRegex = /(, )?([^:]+): ((\[.*?\])|([^,]*))/g;
let matches =
transaction.additionalInformation.matchAll(additionalInfoRegex);
if (matches) {
for (let match of matches) {
let key = match[2].trim();
let value = (match[4] || match[5]).trim();
// Remove square brackets and single quotes and commas
value = value.replace(/[[\]',]/g, '');
additionalInformationObject[key] = value;
}
// Keep existing unstructuredArray and add atmPosName and narrative
transaction.remittanceInformationUnstructuredArray = [
transaction.remittanceInformationUnstructuredArray ?? '',
additionalInformationObject?.atmPosName ?? '',
additionalInformationObject?.narrative ?? '',
].filter(Boolean);
}
}
return transaction;
},

sortTransactions(transactions = []) {
console.log(
'Available (first 10) transactions properties for new integration of institution in sortTransactions function',
{ top10Transactions: JSON.stringify(transactions.slice(0, 10)) },
);
return sortByBookingDateOrValueDate(transactions);
},

calculateStartingBalance(sortedTransactions = [], balances = []) {
console.log(
'Available (first 10) transactions properties for new integration of institution in calculateStartingBalance function',
{
balances: JSON.stringify(balances),
top10SortedTransactions: JSON.stringify(
sortedTransactions.slice(0, 10),
),
},
);

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));
},
};
10 changes: 10 additions & 0 deletions src/app-gocardless/gocardless-node.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,16 @@ export type Transaction = {
*/
remittanceInformationStructured?: string;

/**
* Reference as contained in the unstructured remittance reference structure
*/
remittanceInformationUnstructured?: string;

/**
* Reference as contained in the unstructured remittance array reference structure
*/
remittanceInformationUnstructuredArray?: string[];

/**
* The amount of the transaction as billed to the account
*/
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/242.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [CharlieMK]
---

Add GoCardless integration for Fintro BE to use additional transaction information.

0 comments on commit 09380db

Please sign in to comment.