-
-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GoCardless integration for ABNAMRO_ABNANL2A #513
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
); | ||
} | ||
Comment on lines
+73
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle cases where 'interimBooked' balance is not found If no balance with Apply this diff to add error handling: } else {
+ const interimBalance = balances.find(
+ (balance) => 'interimBooked' === balance.balanceType,
+ );
+ if (!interimBalance) {
+ // Handle the case where no interimBooked balance is found
+ throw new Error('No interimBooked balance found');
+ }
return amountToInteger(
- balances.find((balance) => 'interimBooked' === balance.balanceType)
- .balanceAmount.amount,
+ interimBalance.balanceAmount.amount,
);
}
|
||
}, | ||
}; |
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'); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Enhancements | ||
authors: [nsulzer] | ||
--- | ||
|
||
Add GoCardless integration for ABNAMRO_ABNANL2A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for missing 'remittanceInformationUnstructuredArray'
If
transaction.remittanceInformationUnstructuredArray
is undefined, calling.join(' ')
will result in a runtime error. Consider providing a default empty array to prevent this issue.Apply this diff to add a default value:
📝 Committable suggestion