A local-first personal finance app
Add gocardless support for Berliner Sparkasse (Germany) (#358)
Peccadillozdf3aaf961d57
diff --git a/src/app-gocardless/bank-factory.js b/src/app-gocardless/bank-factory.jsindex 4bc99b441c..d192aaa1a3 100644--- a/src/app-gocardless/bank-factory.js+++ b/src/app-gocardless/bank-factory.js@@ -20,6 +20,7 @@ import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js';import VirginNrnbgb22 from './banks/virgin_nrnbgb22.js';+import Berliner_Sparkasse_beladebexxx from './banks/berliner_sparkasse_beladebexxx.js';export const banks = [AbancaCaglesmm,@@ -43,6 +44,7 @@ export const banks = [SpkMarburgBiedenkopfHeladef1mar,SpkKarlsruhekarsde66,VirginNrnbgb22,+ Berliner_Sparkasse_beladebexxx,];export default (institutionId) =>diff --git a/src/app-gocardless/banks/berliner_sparkasse_beladebexxx.js b/src/app-gocardless/banks/berliner_sparkasse_beladebexxx.jsnew file mode 100644index 0000000000..6279d9e38e--- /dev/null+++ b/src/app-gocardless/banks/berliner_sparkasse_beladebexxx.js@@ -0,0 +1,98 @@+import Fallback from './integration-bank.js';++import { printIban, amountToInteger } from '../utils.js';+import { formatPayeeName } from '../../util/payee-name.js';++/** @type {import('./bank.interface.js').IBank} */+export default {+ ...Fallback,++ institutionIds: ['BERLINER_SPARKASSE_BELADEBEXXX'],++ 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 described 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;++ transaction.creditorName = usefulCreditorName;+ transaction.remittanceInformationUnstructured =+ remittanceInformationUnstructured;++ return {+ ...transaction,+ payeeName: formatPayeeName(transaction),+ date: transaction.bookingDate || transaction.valueDate,+ };+ },++ /**+ * 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/358.md b/upcoming-release-notes/358.mdnew file mode 100644index 0000000000..e0f8ab6ea8--- /dev/null+++ b/upcoming-release-notes/358.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [Peccadilloz]+---++Add gocardless support for Berliner Sparkasse (Germany)