Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gocardless support for Sparkasse Karlsruhe (Germany) #346

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +28,7 @@ const banks = [
SandboxfinanceSfin0000,
SparNordSpNoDK22,
SpkMarburgBiedenkopfHeladef1mar,
SpkKarlsruhekarsde66,
];

export default (institutionId) =>
Expand Down
98 changes: 98 additions & 0 deletions src/app-gocardless/banks/spk-karlsruhe-karsde66.js
Original file line number Diff line number Diff line change
@@ -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));
},
};
6 changes: 6 additions & 0 deletions upcoming-release-notes/346.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [Nebukadneza]
---

Add gocardless support for Sparkasse Karlsruhe (Germany)