Skip to content
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

Fix pending transaction amount sign and payee name for National Bank of Greece import #448

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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