Skip to content

Commit

Permalink
Fix pending transaction amount sign and payee name for National Bank …
Browse files Browse the repository at this point in the history
…of Greece import (#448)

* fixed pending transaction amount sign and payeeName for NBG bank import

* added release note

---------

Co-authored-by: Stefanos Chatzimichelakis <[email protected]>
  • Loading branch information
mezger6 and Stefanos Chatzimichelakis authored Sep 17, 2024
1 parent 9ea7bd2 commit f78383b
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js';
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
import VirginNrnbgb22 from './banks/virgin_nrnbgb22.js';
import NbgEthngraaxxx from './banks/nbg_ethngraaxxx.js';

export const banks = [
AbancaCaglesmm,
Expand All @@ -49,6 +50,7 @@ export const banks = [
SpkKarlsruhekarsde66,
SpkMarburgBiedenkopfHeladef1mar,
VirginNrnbgb22,
NbgEthngraaxxx,
];

export default (institutionId) =>
Expand Down
71 changes: 71 additions & 0 deletions src/app-gocardless/banks/nbg_ethngraaxxx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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: ['NBG_ETHNGRAAXXX'],

accessValidForDays: 90,

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',
};
},

/**
* Fixes for the pending transactions:
* - Corrects amount to negative (nbg erroneously omits the minus sign in pending transactions)
* - Removes prefix 'ΑΓΟΡΑ' from remittance information to align with the booked transaction (necessary for fuzzy matching to work)
*/
normalizeTransaction(transaction, _booked) {
if (
!transaction.transactionId &&
transaction.remittanceInformationUnstructured.startsWith('ΑΓΟΡΑ ')
) {
transaction = {
...transaction,
transactionAmount: {
amount: '-' + transaction.transactionAmount.amount,
currency: transaction.transactionAmount.currency,
},
remittanceInformationUnstructured:
transaction.remittanceInformationUnstructured.substring(6),
};
}

return {
...transaction,
payeeName: formatPayeeName(transaction),
date: transaction.bookingDate || transaction.valueDate,
};
},

/**
* For NBG_ETHNGRAAXXX we don't know what balance was
* after each transaction so we have to calculate it by getting
* current balance from the account and subtract all the transactions
*
* As a current balance we use `interimBooked` balance type because
* it includes transaction placed during current day
*/
calculateStartingBalance(sortedTransactions = [], balances = []) {
const currentBalance = balances.find(
(balance) => 'interimAvailable' === balance.balanceType,
);

return sortedTransactions.reduce((total, trans) => {
return total - amountToInteger(trans.transactionAmount.amount);
}, amountToInteger(currentBalance.balanceAmount.amount));
},
};
48 changes: 48 additions & 0 deletions src/app-gocardless/banks/tests/nbg_ethngraaxxx.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import NbgEthngraaxxx from '../nbg_ethngraaxxx.js';

describe('NbgEthngraaxxx', () => {
describe('#normalizeTransaction', () => {
it('provides correct amount in pending transaction and removes payee prefix', () => {
const transaction = {
bookingDate: '2024-09-03',
date: '2024-09-03',
remittanceInformationUnstructured: 'ΑΓΟΡΑ testingson',
transactionAmount: {
amount: '100.00',
currency: 'EUR',
},
valueDate: '2024-09-03',
};

const normalizedTransaction = NbgEthngraaxxx.normalizeTransaction(
transaction,
false,
);

expect(normalizedTransaction.transactionAmount.amount).toEqual('-100.00');
expect(normalizedTransaction.payeeName).toEqual('Testingson');
});
});

it('provides correct amount and payee in booked transaction', () => {
const transaction = {
transactionId: 'O244015L68IK',
bookingDate: '2024-09-03',
date: '2024-09-03',
remittanceInformationUnstructured: 'testingson',
transactionAmount: {
amount: '-100.00',
currency: 'EUR',
},
valueDate: '2024-09-03',
};

const normalizedTransaction = NbgEthngraaxxx.normalizeTransaction(
transaction,
true,
);

expect(normalizedTransaction.transactionAmount.amount).toEqual('-100.00');
expect(normalizedTransaction.payeeName).toEqual('Testingson');
});
});
6 changes: 6 additions & 0 deletions upcoming-release-notes/448.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [mezger6]
---

Fix pending purchases amount sign and payee name for National Bank of Greece import

0 comments on commit f78383b

Please sign in to comment.