fill in creditor name for BNP bank transactions (#349)

This commit is contained in:
vojeroen
2024-05-16 20:57:24 +02:00
committed by GitHub
parent c51e636637
commit abd049e715
2 changed files with 28 additions and 0 deletions

View File

@@ -49,15 +49,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;
@@ -68,11 +80,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,
};
},

View File

@@ -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.