-
-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GoCardless integration for ABNAMRO_ABNANL2A
- Loading branch information
Showing
4 changed files
with
120 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,79 @@ | ||
import Fallback from './integration-bank.js'; | ||
import { printIban, amountToInteger } from '../utils.js'; | ||
import { formatPayeeName } from '../../util/payee-name.js'; | ||
|
||
/** @type {import('./bank.interface.js').IBank} */ | ||
export default { | ||
...Fallback, | ||
|
||
institutionIds: ['ABNAMRO_ABNANL2A'], | ||
|
||
accessValidForDays: 180, | ||
|
||
normalizeAccount(account) { | ||
return { | ||
account_id: account.id, | ||
institution: account.institution, | ||
mask: account.iban.slice(-4), | ||
iban: account.iban, | ||
name: [account.name, printIban(account)].join(' '), | ||
official_name: account.product, | ||
type: 'checking', | ||
}; | ||
}, | ||
|
||
normalizeTransaction(transaction, _booked) { | ||
// There is no remittanceInformationUnstructured, so we'll make it | ||
let remittanceInformationUnstructured = | ||
transaction.remittanceInformationUnstructuredArray.join(' '); | ||
|
||
// Remove clutter to extract the payee from remittanceInformationUnstructured ... | ||
// ... when not otherwise provided. | ||
const matches = | ||
remittanceInformationUnstructured.match(/Betaalpas(.+),PAS/); | ||
const payeeName = matches | ||
? matches[1].replace(/.+\*/, '').trim() | ||
: undefined; | ||
transaction.debtorName = transaction.debtorName || payeeName; | ||
transaction.creditorName = transaction.creditorName || payeeName; | ||
|
||
// There are anumber of superfluous keywords in the remittanceInformation. | ||
// Remove them to aboid clutter in notes. | ||
const keywordsToRemove = ['.EA, Betaalpas', ',PAS\\d{3}', 'NR:.+, ']; | ||
const regex = new RegExp(keywordsToRemove.join('|'), 'g'); | ||
transaction.remittanceInformationUnstructured = | ||
remittanceInformationUnstructured.replace(regex, '').trim(); | ||
|
||
return { | ||
...transaction, | ||
payeeName: formatPayeeName(transaction), | ||
date: transaction.valueDateTime.slice(0, 10), | ||
}; | ||
}, | ||
|
||
sortTransactions(transactions = []) { | ||
return transactions.sort( | ||
(a, b) => +new Date(b.valueDateTime) - +new Date(a.valueDateTime), | ||
); | ||
}, | ||
|
||
calculateStartingBalance(sortedTransactions = [], balances = []) { | ||
if (sortedTransactions.length) { | ||
const oldestTransaction = | ||
sortedTransactions[sortedTransactions.length - 1]; | ||
const oldestKnownBalance = amountToInteger( | ||
oldestTransaction.balanceAfterTransaction.balanceAmount.amount, | ||
); | ||
const oldestTransactionAmount = amountToInteger( | ||
oldestTransaction.transactionAmount.amount, | ||
); | ||
|
||
return oldestKnownBalance - oldestTransactionAmount; | ||
} else { | ||
return amountToInteger( | ||
balances.find((balance) => 'interimBooked' === balance.balanceType) | ||
.balanceAmount.amount, | ||
); | ||
} | ||
}, | ||
}; |
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,33 @@ | ||
import AbnamroAbnanl2a from '../abnamro_abnanl2a.js'; | ||
|
||
describe('AbnamroAbnanl2a', () => { | ||
describe('#normalizeTransaction', () => { | ||
it('correctly extracts the payee and when not provided', () => { | ||
const transaction = { | ||
transactionId: '0123456789012345', | ||
bookingDate: '2023-12-11', | ||
valueDateTime: '2023-12-09T15:43:37.950', | ||
transactionAmount: { | ||
amount: '-10.00', | ||
currency: 'EUR', | ||
}, | ||
remittanceInformationUnstructuredArray: [ | ||
'BEA, Betaalpas', | ||
'My Payee Name,PAS123', | ||
'NR:123A4B, 09.12.23/15:43', | ||
'CITY', | ||
], | ||
}; | ||
|
||
const normalizedTransaction = AbnamroAbnanl2a.normalizeTransaction( | ||
transaction, | ||
false, | ||
); | ||
|
||
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual( | ||
'My Payee Name 09.12.23/15:43 CITY', | ||
); | ||
expect(normalizedTransaction.payeeName).toEqual('My Payee Name'); | ||
}); | ||
}); | ||
}); |
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: [nsulzer] | ||
--- | ||
|
||
Add GoCardless integration for ABNAMRO_ABNANL2A |