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

Commit 41a34d0

Browse files
authored
Add gocardless support for Sparkasse Karlsruhe (Germany) (#346)
1 parent f148807 commit 41a34d0

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

src/app-gocardless/bank-factory.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SEBPrivat from './banks/seb-privat.js';
1212
import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
1313
import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
1414
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
15+
import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js';
1516

1617
const banks = [
1718
AmericanExpressAesudef1,
@@ -27,6 +28,7 @@ const banks = [
2728
SandboxfinanceSfin0000,
2829
SparNordSpNoDK22,
2930
SpkMarburgBiedenkopfHeladef1mar,
31+
SpkKarlsruhekarsde66,
3032
];
3133

3234
export default (institutionId) =>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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: ['SPK_KARLSRUHE_KARSDE66XXX'],
10+
11+
accessValidForDays: 90,
12+
13+
normalizeAccount(account) {
14+
return {
15+
account_id: account.id,
16+
institution: account.institution,
17+
mask: account.iban.slice(-4),
18+
iban: account.iban,
19+
name: [account.name, printIban(account)].join(' '),
20+
official_name: account.product,
21+
type: 'checking',
22+
};
23+
},
24+
25+
/**
26+
* Following the GoCardless documentation[0] we should prefer `bookingDate`
27+
* here, though some of their bank integrations uses the date field
28+
* differently from what's describen in their documentation and so it's
29+
* sometimes necessary to use `valueDate` instead.
30+
*
31+
* [0]: https://nordigen.zendesk.com/hc/en-gb/articles/7899367372829-valueDate-and-bookingDate-for-transactions
32+
*/
33+
normalizeTransaction(transaction, _booked) {
34+
const date =
35+
transaction.bookingDate ||
36+
transaction.bookingDateTime ||
37+
transaction.valueDate ||
38+
transaction.valueDateTime;
39+
40+
// If we couldn't find a valid date field we filter out this transaction
41+
// and hope that we will import it again once the bank has processed the
42+
// transaction further.
43+
if (!date) {
44+
return null;
45+
}
46+
47+
let remittanceInformationUnstructured;
48+
49+
if (transaction.remittanceInformationUnstructured) {
50+
remittanceInformationUnstructured =
51+
transaction.remittanceInformationUnstructured;
52+
} else if (transaction.remittanceInformationStructured) {
53+
remittanceInformationUnstructured =
54+
transaction.remittanceInformationStructured;
55+
} else if (transaction.remittanceInformationStructuredArray?.length > 0) {
56+
remittanceInformationUnstructured =
57+
transaction.remittanceInformationStructuredArray?.join(' ');
58+
}
59+
60+
if (transaction.additionalInformation)
61+
remittanceInformationUnstructured +=
62+
' ' + transaction.additionalInformation;
63+
64+
const usefulCreditorName =
65+
transaction.ultimateCreditor ||
66+
transaction.creditorName ||
67+
transaction.debtorName;
68+
69+
return {
70+
...transaction,
71+
creditorName: usefulCreditorName,
72+
remittanceInformationUnstructured: remittanceInformationUnstructured,
73+
date: transaction.bookingDate || transaction.valueDate,
74+
};
75+
},
76+
77+
sortTransactions(transactions = []) {
78+
return sortByBookingDateOrValueDate(transactions);
79+
},
80+
81+
/**
82+
* For SANDBOXFINANCE_SFIN0000 we don't know what balance was
83+
* after each transaction so we have to calculate it by getting
84+
* current balance from the account and subtract all the transactions
85+
*
86+
* As a current balance we use `interimBooked` balance type because
87+
* it includes transaction placed during current day
88+
*/
89+
calculateStartingBalance(sortedTransactions = [], balances = []) {
90+
const currentBalance = balances.find(
91+
(balance) => 'interimAvailable' === balance.balanceType,
92+
);
93+
94+
return sortedTransactions.reduce((total, trans) => {
95+
return total - amountToInteger(trans.transactionAmount.amount);
96+
}, amountToInteger(currentBalance.balanceAmount.amount));
97+
},
98+
};

upcoming-release-notes/346.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: Enhancements
3+
authors: [Nebukadneza]
4+
---
5+
6+
Add gocardless support for Sparkasse Karlsruhe (Germany)

0 commit comments

Comments
 (0)