Skip to content

Commit

Permalink
Fix wrong payeeName used for KBC_KREDBEBB (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudWeyts authored Sep 2, 2024
1 parent c4d01fe commit 7a018e0
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AbancaCaglesmm from './banks/abanca-caglesmm.js';
import AmericanExpressAesudef1 from './banks/american-express-aesudef1.js';
import BankinterBkbkesmm from './banks/bankinter-bkbkesmm.js';
import Belfius from './banks/belfius_gkccbebb.js';
import Berliner_Sparkasse_beladebexxx from './banks/berliner_sparkasse_beladebexxx.js';
import BnpBeGebabebb from './banks/bnp-be-gebabebb.js';
import DanskeBankDabNO22 from './banks/danskebank-dabno22.js';
import EasybankBawaatww from './banks/easybank-bawaatww.js';
Expand All @@ -10,41 +11,42 @@ import IngIngbrobu from './banks/ing-ingbrobu.js';
import IngIngddeff from './banks/ing-ingddeff.js';
import IngPlIngbplpw from './banks/ing-pl-ingbplpw.js';
import IntegrationBank from './banks/integration-bank.js';
import KBCkredbebb from './banks/kbc_kredbebb.js';
import MbankRetailBrexplpw from './banks/mbank-retail-brexplpw.js';
import NationwideNaiaGB21 from './banks/nationwide-naiagb21.js';
import NorwegianXxNorwnok1 from './banks/norwegian-xx-norwnok1.js';
import SEBKortBankAB from './banks/seb-kort-bank-ab.js';
import SEBPrivat from './banks/seb-privat.js';
import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js';
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
import VirginNrnbgb22 from './banks/virgin_nrnbgb22.js';
import Berliner_Sparkasse_beladebexxx from './banks/berliner_sparkasse_beladebexxx.js';

export const banks = [
AbancaCaglesmm,
AmericanExpressAesudef1,
BankinterBkbkesmm,
Belfius,
Berliner_Sparkasse_beladebexxx,
BnpBeGebabebb,
DanskeBankDabNO22,
EasybankBawaatww,
Fortuneo,
IngIngbrobu,
IngIngddeff,
IngPlIngbplpw,
KBCkredbebb,
MbankRetailBrexplpw,
NationwideNaiaGB21,
NorwegianXxNorwnok1,
SEBKortBankAB,
SEBPrivat,
SandboxfinanceSfin0000,
SparNordSpNoDK22,
SpkMarburgBiedenkopfHeladef1mar,
SpkKarlsruhekarsde66,
SpkMarburgBiedenkopfHeladef1mar,
VirginNrnbgb22,
Berliner_Sparkasse_beladebexxx,
];

export default (institutionId) =>
Expand Down
51 changes: 51 additions & 0 deletions src/app-gocardless/banks/kbc_kredbebb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Fallback from './integration-bank.js';

/**
* The remittance information contains creditorName, payments method, dates, etc.
* This function makes sure to only extract the creditorName based on the different indicators like "Betaling met".
* f.e. Proxy Poel BE Gent Betaling met Apple Pay via Maestro 23-08-2024 om 14.03 uur XXXX XXXX XXXX XXXX -> Proxy Poel BE Gent
*/
function extractPayeeName(remittanceInformationUnstructured) {
const indices = [
remittanceInformationUnstructured.lastIndexOf(' Betaling met'),
remittanceInformationUnstructured.lastIndexOf(' Domiciliëring'),
remittanceInformationUnstructured.lastIndexOf(' Overschrijving'),
];

const indexForRemoval = Math.max(...indices);

return indexForRemoval > -1
? remittanceInformationUnstructured.substring(0, indexForRemoval)
: remittanceInformationUnstructured;
}

/** @type {import('./bank.interface.js').IBank} */
export default {
...Fallback,

institutionIds: ['KBC_KREDBEBB'],

/**
* For negative amounts, the only payee information we have is returned in
* remittanceInformationUnstructured.
*/
normalizeTransaction(transaction, _booked) {
if (Number(transaction.transactionAmount.amount) > 0) {
return {
...transaction,
payeeName:
transaction.debtorName ||
transaction.remittanceInformationUnstructured,
date: transaction.bookingDate || transaction.valueDate,
};
}

return {
...transaction,
payeeName:
transaction.creditorName ||
extractPayeeName(transaction.remittanceInformationUnstructured),
date: transaction.bookingDate || transaction.valueDate,
};
},
};
36 changes: 36 additions & 0 deletions src/app-gocardless/banks/tests/kbc_kredbebb.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import KBCkredbebb from '../kbc_kredbebb.js';

describe('kbc_kredbebb', () => {
describe('#normalizeTransaction', () => {
it('returns the remittanceInformationUnstructured as payeeName when the amount is negative', () => {
const transaction = {
remittanceInformationUnstructured:
'CARREFOUR ST GIL BE1060 BRUXELLES Betaling met Google Pay via Debit Mastercard 28-08-2024 om 19.15 uur 5127 04XX XXXX 1637 5853 98XX XXXX 2266 JOHN SMITH',
transactionAmount: { amount: '-10.99', currency: 'EUR' },
};
const normalizedTransaction = KBCkredbebb.normalizeTransaction(
transaction,
true,
);
expect(normalizedTransaction.payeeName).toEqual(
'CARREFOUR ST GIL BE1060 BRUXELLES',
);
});

it('returns the debtorName as payeeName when the amount is positive', () => {
const transaction = {
debtorName: 'CARREFOUR ST GIL BE1060 BRUXELLES',
remittanceInformationUnstructured:
'CARREFOUR ST GIL BE1060 BRUXELLES Betaling met Google Pay via Debit Mastercard 28-08-2024 om 19.15 uur 5127 04XX XXXX 1637 5853 98XX XXXX 2266 JOHN SMITH',
transactionAmount: { amount: '10.99', currency: 'EUR' },
};
const normalizedTransaction = KBCkredbebb.normalizeTransaction(
transaction,
true,
);
expect(normalizedTransaction.payeeName).toEqual(
'CARREFOUR ST GIL BE1060 BRUXELLES',
);
});
});
});
6 changes: 6 additions & 0 deletions upcoming-release-notes/442.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [ArnaudWeyts]
---

Fix wrong payeeName used for KBC_KREDBEBB

0 comments on commit 7a018e0

Please sign in to comment.