Skip to content

Commit

Permalink
Add GoCardless integration for ENTERCARD_SWEDNOKK
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Löthberg <[email protected]>
  • Loading branch information
kyrias committed Nov 23, 2024
1 parent 69a04a5 commit 3560f73
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BnpBeGebabebb from './banks/bnp-be-gebabebb.js';
import CBCcregbebb from './banks/cbc_cregbebb.js';
import DanskeBankDabNO22 from './banks/danskebank-dabno22.js';
import EasybankBawaatww from './banks/easybank-bawaatww.js';
import EntercardSwednokk from './banks/entercard-swednokk.js';
import Fortuneo from './banks/FORTUNEO_FTNOFRP1XXX.js';
import IngIngbrobu from './banks/ing-ingbrobu.js';
import IngIngddeff from './banks/ing-ingddeff.js';
Expand All @@ -19,9 +20,9 @@ import NationwideNaiaGB21 from './banks/nationwide-naiagb21.js';
import NbgEthngraaxxx from './banks/nbg_ethngraaxxx.js';
import NorwegianXxNorwnok1 from './banks/norwegian-xx-norwnok1.js';
import RevolutRevolt21 from './banks/revolut_revolt21.js';
import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
import SEBKortBankAB from './banks/seb-kort-bank-ab.js';
import SEBPrivat from './banks/seb-privat.js';
import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js';
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
Expand All @@ -40,6 +41,7 @@ export const banks = [
CBCcregbebb,
DanskeBankDabNO22,
EasybankBawaatww,
EntercardSwednokk,
Fortuneo,
IngIngbrobu,
IngIngddeff,
Expand All @@ -50,9 +52,9 @@ export const banks = [
NbgEthngraaxxx,
NorwegianXxNorwnok1,
RevolutRevolt21,
SandboxfinanceSfin0000,
SEBKortBankAB,
SEBPrivat,
SandboxfinanceSfin0000,
SparNordSpNoDK22,
SpkKarlsruhekarsde66,
SpkMarburgBiedenkopfHeladef1mar,
Expand Down
59 changes: 59 additions & 0 deletions src/app-gocardless/banks/entercard-swednokk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as d from 'date-fns';
import {
amountToInteger,
printIban,
sortByBookingDateOrValueDate,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
institutionIds: ['ENTERCARD_SWEDNOKK'],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
institution: account.institution,
mask: (account?.iban || '0000').slice(-4),
iban: account?.iban || null,
name: [account.name, printIban(account), account.currency]
.filter(Boolean)
.join(' '),
official_name: `integration-${account.institution_id}`,
type: 'checking',
};
},

normalizeTransaction(transaction, _booked) {
// GoCardless's Entercard integration returns forex transactions with the
// foreign amount in `transactionAmount`, but at least the amount actually
// billed to the account is now available in
// `remittanceInformationUnstructured`.
const remittanceInformationUnstructured =
transaction.remittanceInformationUnstructured;
if (remittanceInformationUnstructured.startsWith('billingAmount: ')) {
transaction.transactionAmount = {
amount: remittanceInformationUnstructured.substring(15),
currency: 'SEK',
};
}

return {
...transaction,
payeeName: formatPayeeName(transaction),
date: d.format(d.parseISO(transaction.valueDate), 'yyyy-MM-dd'),
};
},

sortTransactions(transactions = []) {
return sortByBookingDateOrValueDate(transactions);
},

calculateStartingBalance(sortedTransactions = [], balances = []) {
return sortedTransactions.reduce((total, trans) => {
return total - amountToInteger(trans.transactionAmount.amount);
}, amountToInteger(balances[0]?.balanceAmount?.amount || 0));
},
};
6 changes: 6 additions & 0 deletions upcoming-release-notes/506.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [kyrias]
---

Add GoCardless integration for ENTERCARD_SWEDNOKK

0 comments on commit 3560f73

Please sign in to comment.