Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit bf40410

Browse files
authored
feat: add 'SEB Kort Bank AB' credit card support (#325)
* feat: add 'SEB Kort Bank AB' credit card support * add: release notes for #325 * Calculate balance correctly for SEB Kort credit cards
1 parent 5fde656 commit bf40410

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

src/app-gocardless/bank-factory.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
1111
import Belfius from './banks/belfius_gkccbebb.js';
1212
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
1313
import SEBPrivat from './banks/seb-privat.js';
14+
import SEBKortBankAB from './banks/seb-kort-bank-ab.js';
1415

1516
const banks = [
1617
AmericanExpressAesudef1,
@@ -25,6 +26,7 @@ const banks = [
2526
Belfius,
2627
SpkMarburgBiedenkopfHeladef1mar,
2728
SEBPrivat,
29+
SEBKortBankAB,
2830
];
2931

3032
export default (institutionId) =>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {
2+
printIban,
3+
amountToInteger,
4+
sortByBookingDateOrValueDate,
5+
} from '../utils.js';
6+
7+
/** @type {import('./bank.interface.js').IBank} */
8+
export default {
9+
institutionIds: ['SEB_KORT_AB_SE_SKHSFI21'],
10+
11+
normalizeAccount(account) {
12+
return {
13+
account_id: account.id,
14+
institution: account.institution,
15+
mask: account.iban.slice(-4),
16+
iban: account.iban,
17+
name: [account.name, printIban(account)].join(' '),
18+
official_name: account.product,
19+
type: 'checking',
20+
};
21+
},
22+
23+
/**
24+
* Sign of transaction amount needs to be flipped for SEB credit cards
25+
*/
26+
normalizeTransaction(transaction, _booked) {
27+
return {
28+
...transaction,
29+
// Creditor name is stored in additionInformation for SEB
30+
creditorName: transaction.additionalInformation,
31+
date: transaction.valueDate,
32+
transactionAmount: {
33+
// Flip transaction amount sign
34+
amount: (-parseFloat(transaction.transactionAmount.amount)).toString(),
35+
currency: transaction.transactionAmount.currency,
36+
},
37+
};
38+
},
39+
40+
sortTransactions(transactions = []) {
41+
return sortByBookingDateOrValueDate(transactions);
42+
},
43+
44+
/**
45+
* For SEB_KORT_AB_SE_SKHSFI21 we don't know what balance was
46+
* after each transaction so we have to calculate it by getting
47+
* current balance from the account and subtract all the transactions
48+
*
49+
* As a current balance we use `expected` balance type because it
50+
* corresponds to the current running balance, whereas `interimAvailable`
51+
* holds the remaining credit limit.
52+
*/
53+
calculateStartingBalance(sortedTransactions = [], balances = []) {
54+
const currentBalance = balances.find(
55+
(balance) => 'expected' === balance.balanceType,
56+
);
57+
58+
return sortedTransactions.reduce((total, trans) => {
59+
return total - amountToInteger(trans.transactionAmount.amount);
60+
}, -amountToInteger(currentBalance.balanceAmount.amount));
61+
},
62+
};

upcoming-release-notes/325.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: Features
3+
authors: [walleb]
4+
---
5+
6+
Add custom bank adapter for 'SEB Kort Bank AB' to properly sync credit card transactions.

0 commit comments

Comments
 (0)