-
-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FINTRO_BE_GEBABEBB GoCardless integration (Include additionalInfo…
…rmation in notes) (#242)
- Loading branch information
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |