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

Add support for LHV_LHVBEE22 #542

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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 @@ -20,6 +20,7 @@ import IngPlIngbplpw from './banks/ing-pl-ingbplpw.js';
import IntegrationBank from './banks/integration-bank.js';
import IsyBankItbbitmm from './banks/isybank-itbbitmm.js';
import KBCkredbebb from './banks/kbc_kredbebb.js';
import LhvLhvbee22 from './banks/lhv-lhvbee22.js';
import MbankRetailBrexplpw from './banks/mbank-retail-brexplpw.js';
import NationwideNaiaGB21 from './banks/nationwide-naiagb21.js';
import NbgEthngraaxxx from './banks/nbg_ethngraaxxx.js';
Expand Down Expand Up @@ -58,6 +59,7 @@ export const banks = [
IngPlIngbplpw,
IsyBankItbbitmm,
KBCkredbebb,
LhvLhvbee22,
MbankRetailBrexplpw,
NationwideNaiaGB21,
NbgEthngraaxxx,
Expand Down
38 changes: 38 additions & 0 deletions src/app-gocardless/banks/lhv-lhvbee22.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Fallback from './integration-bank.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
...Fallback,

institutionIds: ['LHV_LHVBEE22'],

accessValidForDays: 90,

normalizeTransaction(transaction, booked) {
// extract bookingDate and creditorName for card transactions, e.g.
// (..1234) 2025-01-02 09:32 CrustumOU\Poordi 3\Tallinn\10156 ESTEST
// bookingDate: 2025-01-02
// creditorName: CrustumOU
const cardTxRegex =
/^\(\.\.(\d{4})\) (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}) (.+)$/g;
const cardTxMatch = cardTxRegex.exec(
transaction?.remittanceInformationUnstructured,
);

if (cardTxMatch) {
transaction = {
...transaction,
creditorName: cardTxMatch[4].split('\\')[0].trim(),
};

if (booked) {
transaction = {
...transaction,
bookingDate: cardTxMatch[2],
};
}
}
lnagel marked this conversation as resolved.
Show resolved Hide resolved

return Fallback.normalizeTransaction(transaction, booked);
},
};
79 changes: 79 additions & 0 deletions src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import LhvLhvbee22 from '../lhv-lhvbee22.js';

describe('#normalizeTransaction', () => {
const bookedCardTransaction = {
transactionId: '2025010300000000-1',
bookingDate: '2025-01-03',
valueDate: '2025-01-03',
transactionAmount: {
amount: '-22.99',
currency: 'EUR',
},
creditorName: null,
remittanceInformationUnstructured:
'(..1234) 2025-01-02 09:32 CrustumOU\\Poordi 3\\Tallinn\\10156 ESTEST',
bankTransactionCode: 'PMNT-CCRD-POSD',
internalTransactionId: 'fa000f86afb2cc7678bcff0000000000',
};

it('extracts booked card transaction creditor name', () => {
expect(
LhvLhvbee22.normalizeTransaction(bookedCardTransaction, true)
.creditorName,
).toEqual('CrustumOU');
});

it('extracts booked card transaction date', () => {
expect(
LhvLhvbee22.normalizeTransaction(bookedCardTransaction, true).bookingDate,
).toEqual('2025-01-02');

expect(
LhvLhvbee22.normalizeTransaction(bookedCardTransaction, true).date,
).toEqual('2025-01-02');
});

it.each([
['regular text', 'Some info'],
['partial card text', 'PIRKUMS xxx'],
['null value', null],
])('normalizes non-card transaction with %s', (_, remittanceInfo) => {
const transaction = {
...bookedCardTransaction,
remittanceInformationUnstructured: remittanceInfo,
};
const normalized = LhvLhvbee22.normalizeTransaction(transaction, true);

expect(normalized.bookingDate).toEqual('2025-01-03');
expect(normalized.date).toEqual('2025-01-03');
});

const pendingCardTransaction = {
transactionId: '2025010300000000-1',
valueDate: '2025-01-03',
transactionAmount: {
amount: '-22.99',
currency: 'EUR',
},
remittanceInformationUnstructured:
'(..1234) 2025-01-02 09:32 CrustumOU\\Poordi 3\\Tallinn\\10156 ESTEST',
};

it('extracts pending card transaction creditor name', () => {
expect(
LhvLhvbee22.normalizeTransaction(pendingCardTransaction, false)
.creditorName,
).toEqual('CrustumOU');
});

it('extracts pending card transaction date', () => {
expect(
LhvLhvbee22.normalizeTransaction(pendingCardTransaction, false)
.bookingDate,
).toEqual(undefined);

expect(
LhvLhvbee22.normalizeTransaction(pendingCardTransaction, false).date,
).toEqual('2025-01-03');
});
});
6 changes: 6 additions & 0 deletions upcoming-release-notes/542.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [lnagel]
---

Add GoCardless formatter for LHV Estonia (`LHV_LHVBEE22`).
Loading