Skip to content

Commit

Permalink
feat: add SEB Privat bank (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
myhrmans authored Mar 3, 2024
1 parent b926af2 commit 6e9edde
Show file tree
Hide file tree
Showing 3 changed files with 75 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 @@ -10,6 +10,7 @@ import DanskeBankDabNO22 from './banks/danskebank-dabno22.js';
import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
import Belfius from './banks/belfius_gkccbebb.js';
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
import SEBPrivat from './banks/seb-privat.js';

const banks = [
AmericanExpressAesudef1,
Expand All @@ -23,6 +24,7 @@ const banks = [
SparNordSpNoDK22,
Belfius,
SpkMarburgBiedenkopfHeladef1mar,
SEBPrivat,
];

export default (institutionId) =>
Expand Down
67 changes: 67 additions & 0 deletions src/app-gocardless/banks/seb-privat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import * as d from 'date-fns';
import {
sortByBookingDateOrValueDate,
amountToInteger,
printIban,
} from '../utils.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
institutionIds: ['SEB_ESSESESS_PRIVATE'],
normalizeAccount(account) {
console.log(
'Available account properties for new institution integration',
{ account: JSON.stringify(account) },
);

return {
account_id: account.id,
institution: account.institution,
mask: (account?.iban || '0000').slice(-4),
iban: account?.iban || null,
name: [account.name, printIban(account), account.currency]
.filter(Boolean)
.join(' '),
official_name: `integration-${account.institution_id}`,
type: 'checking',
};
},

normalizeTransaction(transaction, _booked) {
const date =
transaction.bookingDate ||
transaction.bookingDateTime ||
transaction.valueDate ||
transaction.valueDateTime;
// If we couldn't find a valid date field we filter out this transaction
// and hope that we will import it again once the bank has processed the
// transaction further.
if (!date) {
return null;
}
return {
...transaction,
// Creditor name is stored in additionInformation for SEB
creditorName: transaction.additionalInformation,
date: d.format(d.parseISO(date), 'yyyy-MM-dd'),
};
},

sortTransactions(transactions = []) {
console.log(
'Available (first 10) transactions properties for new integration of institution in sortTransactions function',
{ top10Transactions: JSON.stringify(transactions.slice(0, 10)) },
);
return sortByBookingDateOrValueDate(transactions);
},

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

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

Add SEB Private Bank integration to gocardless. Handle that SEB is sending the creditor name in additionalInfo.

0 comments on commit 6e9edde

Please sign in to comment.