-
-
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.
Fix wrong payeeName used for KBC_KREDBEBB (#442)
- Loading branch information
1 parent
c4d01fe
commit 7a018e0
Showing
4 changed files
with
99 additions
and
4 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,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, | ||
}; | ||
}, | ||
}; |
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,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', | ||
); | ||
}); | ||
}); | ||
}); |
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: Bugfix | ||
authors: [ArnaudWeyts] | ||
--- | ||
|
||
Fix wrong payeeName used for KBC_KREDBEBB |