Add gocardless support for Berliner Sparkasse (Germany) (#358)

This commit is contained in:
Peccadilloz
2024-08-03 18:00:54 +02:00
committed by GitHub
parent 6b57e45e04
commit df3aaf961d
3 changed files with 106 additions and 0 deletions

View File

@@ -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) =>

View File

@@ -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));
},
};

View File

@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [Peccadilloz]
---
Add gocardless support for Berliner Sparkasse (Germany)