Skip to content

Commit

Permalink
Add DANSKEBANK_DABANO22 integration (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
LudvigHz authored Aug 15, 2023
1 parent 95c7d5b commit 0501dea
Show file tree
Hide file tree
Showing 3 changed files with 68 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 @@ -5,6 +5,7 @@ import MbankRetailBrexplpw from './banks/mbank-retail-brexplpw.js';
import NorwegianXxNorwnok1 from './banks/norwegian-xx-norwnok1.js';
import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
import FintroBeGebabebb from './banks/fintro-be-gebabebb.js';
import DanskeBankDabNO22 from './banks/danskebank-dabno22.js';

const banks = [
AmericanExpressAesudef1,
Expand All @@ -13,6 +14,7 @@ const banks = [
SandboxfinanceSfin0000,
NorwegianXxNorwnok1,
FintroBeGebabebb,
DanskeBankDabNO22,
];

export default (institutionId) =>
Expand Down
60 changes: 60 additions & 0 deletions src/app-gocardless/banks/danskebank-dabno22.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
printIban,
amountToInteger,
sortByBookingDateOrValueDate,
} from '../utils.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
institutionIds: ['DANSKEBANK_DABANO22'],

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.name,
type: 'checking',
};
},

normalizeTransaction(transaction, _booked) {
/**
* Danske Bank appends the EndToEndID: NOTPROVIDED to
* remittanceInformationUnstructured, cluttering the data.
*
* We clean thais up by removing any instances of this string from all transactions.
*
*/
transaction.remittanceInformationUnstructured =
transaction.remittanceInformationUnstructured.replace(
'\nEndToEndID: NOTPROVIDED',
'',
);

/**
* The valueDate in transactions from Danske Bank is not the one expected, but rather the date
* the funds are expected to be paid back for credit accounts.
*/
return {
...transaction,
date: transaction.bookingDate,
};
},

sortTransactions(transactions = []) {
return sortByBookingDateOrValueDate(transactions);
},

calculateStartingBalance(sortedTransactions = [], balances = []) {
const currentBalance = balances.find(
(balance) => balance.balanceType === 'interimAvailable',
);

return sortedTransactions.reduce((total, trans) => {
return total - amountToInteger(trans.transactionAmount.amount);
}, amountToInteger(currentBalance.balanceAmount.amount));
},
};
6 changes: 6 additions & 0 deletions upcoming-release-notes/244.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [LudvigHz]
---

Add GoCardless integration for Danske Bank Private NO

0 comments on commit 0501dea

Please sign in to comment.