Skip to content

A local-first personal finance app

Add gocardless support for Sparkasse Karlsruhe (Germany) (#346)

Dario Ernst41a34d0f1cf9
diff --git a/src/app-gocardless/bank-factory.js b/src/app-gocardless/bank-factory.js
index 623230a544..56bfb54646 100644
--- a/src/app-gocardless/bank-factory.js
+++ b/src/app-gocardless/bank-factory.js
@@ -12,6 +12,7 @@ import SEBPrivat from './banks/seb-privat.js';
import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
+import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js';
const banks = [
AmericanExpressAesudef1,
@@ -27,6 +28,7 @@ const banks = [
SandboxfinanceSfin0000,
SparNordSpNoDK22,
SpkMarburgBiedenkopfHeladef1mar,
+ SpkKarlsruhekarsde66,
];
export default (institutionId) =>
diff --git a/src/app-gocardless/banks/spk-karlsruhe-karsde66.js b/src/app-gocardless/banks/spk-karlsruhe-karsde66.js
new file mode 100644
index 0000000000..94af8b6683
--- /dev/null
+++ b/src/app-gocardless/banks/spk-karlsruhe-karsde66.js
@@ -0,0 +1,98 @@
+import {
+ printIban,
+ amountToInteger,
+ sortByBookingDateOrValueDate,
+} from '../utils.js';
+
+/** @type {import('./bank.interface.js').IBank} */
+export default {
+ institutionIds: ['SPK_KARLSRUHE_KARSDE66XXX'],
+
+ accessValidForDays: 90,
+
+ 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.product,
+ type: 'checking',
+ };
+ },
+
+ /**
+ * Following the GoCardless documentation[0] we should prefer `bookingDate`
+ * here, though some of their bank integrations uses the date field
+ * differently from what's describen in their documentation and so it's
+ * sometimes necessary to use `valueDate` instead.
+ *
+ * [0]: https://nordigen.zendesk.com/hc/en-gb/articles/7899367372829-valueDate-and-bookingDate-for-transactions
+ */
+ 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;
+ }
+
+ let remittanceInformationUnstructured;
+
+ if (transaction.remittanceInformationUnstructured) {
+ remittanceInformationUnstructured =
+ transaction.remittanceInformationUnstructured;
+ } else if (transaction.remittanceInformationStructured) {
+ remittanceInformationUnstructured =
+ transaction.remittanceInformationStructured;
+ } else if (transaction.remittanceInformationStructuredArray?.length > 0) {
+ remittanceInformationUnstructured =
+ transaction.remittanceInformationStructuredArray?.join(' ');
+ }
+
+ if (transaction.additionalInformation)
+ remittanceInformationUnstructured +=
+ ' ' + transaction.additionalInformation;
+
+ const usefulCreditorName =
+ transaction.ultimateCreditor ||
+ transaction.creditorName ||
+ transaction.debtorName;
+
+ return {
+ ...transaction,
+ creditorName: usefulCreditorName,
+ remittanceInformationUnstructured: remittanceInformationUnstructured,
+ date: transaction.bookingDate || transaction.valueDate,
+ };
+ },
+
+ sortTransactions(transactions = []) {
+ return sortByBookingDateOrValueDate(transactions);
+ },
+
+ /**
+ * For SANDBOXFINANCE_SFIN0000 we don't know what balance was
+ * after each transaction so we have to calculate it by getting
+ * current balance from the account and subtract all the transactions
+ *
+ * As a current balance we use `interimBooked` balance type because
+ * it includes transaction placed during current day
+ */
+ calculateStartingBalance(sortedTransactions = [], balances = []) {
+ const currentBalance = balances.find(
+ (balance) => 'interimAvailable' === balance.balanceType,
+ );
+
+ return sortedTransactions.reduce((total, trans) => {
+ return total - amountToInteger(trans.transactionAmount.amount);
+ }, amountToInteger(currentBalance.balanceAmount.amount));
+ },
+};
diff --git a/upcoming-release-notes/346.md b/upcoming-release-notes/346.md
new file mode 100644
index 0000000000..157e15313d
--- /dev/null
+++ b/upcoming-release-notes/346.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [Nebukadneza]
+---
+
+Add gocardless support for Sparkasse Karlsruhe (Germany)