diff --git a/src/app-gocardless/banks/abnamro_abnanl2a.js b/src/app-gocardless/banks/abnamro_abnanl2a.js index 1b6bd8fd5..5d5332d32 100644 --- a/src/app-gocardless/banks/abnamro_abnanl2a.js +++ b/src/app-gocardless/banks/abnamro_abnanl2a.js @@ -24,26 +24,17 @@ export default { normalizeTransaction(transaction, _booked) { // There is no remittanceInformationUnstructured, so we'll make it - let remittanceInformationUnstructured = - transaction.remittanceInformationUnstructuredArray.join(' '); + transaction.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; + const payeeName = transaction.remittanceInformationUnstructuredArray + .map((el) => el.match(/^(?:.*\*)?(.+),PAS\d+$/)) + .find((match) => match)?.[1]; 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), diff --git a/src/app-gocardless/banks/tests/abnamro_abnanl2a.spec.js b/src/app-gocardless/banks/tests/abnamro_abnanl2a.spec.js index 295b41077..db93bd2c7 100644 --- a/src/app-gocardless/banks/tests/abnamro_abnanl2a.spec.js +++ b/src/app-gocardless/banks/tests/abnamro_abnanl2a.spec.js @@ -25,9 +25,37 @@ describe('AbnamroAbnanl2a', () => { ); expect(normalizedTransaction.remittanceInformationUnstructured).toEqual( - 'My Payee Name 09.12.23/15:43 CITY', + 'BEA, Betaalpas, My Payee Name,PAS123, NR:123A4B, 09.12.23/15:43, CITY', ); expect(normalizedTransaction.payeeName).toEqual('My Payee Name'); }); + + it('correctly extracts the payee for google pay', () => { + const transaction = { + transactionId: '0123456789012345', + bookingDate: '2023-12-11', + valueDateTime: '2023-12-09T15:43:37.950', + transactionAmount: { + amount: '-10.00', + currency: 'EUR', + }, + remittanceInformationUnstructuredArray: [ + 'BEA, Google Pay', + 'CCV*Other payee name,PAS123', + 'NR:123A4B, 09.12.23/15:43', + 'CITY', + ], + }; + + const normalizedTransaction = AbnamroAbnanl2a.normalizeTransaction( + transaction, + false, + ); + + expect(normalizedTransaction.remittanceInformationUnstructured).toEqual( + 'BEA, Google Pay, CCV*Other payee name,PAS123, NR:123A4B, 09.12.23/15:43, CITY', + ); + expect(normalizedTransaction.payeeName).toEqual('Other Payee Name'); + }); }); }); diff --git a/upcoming-release-notes/534.md b/upcoming-release-notes/534.md new file mode 100644 index 000000000..3d03094a6 --- /dev/null +++ b/upcoming-release-notes/534.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [UnderKoen] +--- + +Make Google Pay transactions work for ABNAMRO_ABNANL2A