-
-
Notifications
You must be signed in to change notification settings - Fork 655
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 CBC_CREGBEBB
- Loading branch information
Showing
3 changed files
with
90 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,52 @@ | ||
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 "Paiement". | ||
* f.e. ONKART FR Viry Paiement Maestro par Carte de débit CBC 05-09-2024 à 15.43 heures 6703 19XX XXXX X... -> ONKART FR Viry | ||
*/ | ||
function extractPayeeName(remittanceInformationUnstructured) { | ||
const indices = [ | ||
remittanceInformationUnstructured.lastIndexOf(' Paiement'), | ||
remittanceInformationUnstructured.lastIndexOf(' Domiciliation'), | ||
remittanceInformationUnstructured.lastIndexOf(' Transfert'), | ||
remittanceInformationUnstructured.lastIndexOf(' Ordre permanent'), | ||
]; | ||
|
||
const indexForRemoval = Math.max(...indices); | ||
|
||
return indexForRemoval > -1 | ||
? remittanceInformationUnstructured.substring(0, indexForRemoval) | ||
: remittanceInformationUnstructured; | ||
} | ||
|
||
/** @type {import('./bank.interface.js').IBank} */ | ||
export default { | ||
...Fallback, | ||
|
||
institutionIds: ['CBC_CREGBEBB'], | ||
|
||
/** | ||
* 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 CBCcregbebb from '../cbc_cregbebb.js'; | ||
|
||
describe('cbc_cregbebb', () => { | ||
describe('#normalizeTransaction', () => { | ||
it('returns the remittanceInformationUnstructured as payeeName when the amount is negative', () => { | ||
const transaction = { | ||
remittanceInformationUnstructured: | ||
'ONKART FR Viry Paiement Maestro par Carte de débit CBC 05-09-2024 à 15.43 heures 6703 19XX XXXX X201 5 JOHN DOE', | ||
transactionAmount: { amount: '-45.00', currency: 'EUR' }, | ||
}; | ||
const normalizedTransaction = CBCcregbebb.normalizeTransaction( | ||
transaction, | ||
true, | ||
); | ||
expect(normalizedTransaction.payeeName).toEqual( | ||
'ONKART FR Viry', | ||
); | ||
}); | ||
|
||
it('returns the debtorName as payeeName when the amount is positive', () => { | ||
const transaction = { | ||
debtorName: 'ONKART FR Viry', | ||
remittanceInformationUnstructured: | ||
'ONKART FR Viry Paiement Maestro par Carte de débit CBC 05-09-2024 à 15.43 heures 6703 19XX XXXX X201 5 JOHN DOE', | ||
transactionAmount: { amount: '10.99', currency: 'EUR' }, | ||
}; | ||
const normalizedTransaction = CBCcregbebb.normalizeTransaction( | ||
transaction, | ||
true, | ||
); | ||
expect(normalizedTransaction.payeeName).toEqual( | ||
'ONKART FR Viry', | ||
); | ||
}); | ||
}); | ||
}); |