Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

♻️ standardise GoCardless handlers #541

Merged
merged 11 commits into from
Jan 10, 2025
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
94 changes: 47 additions & 47 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import AbancaCaglesmm from './banks/abanca-caglesmm.js';
import AbancaCaglesmm from './banks/abanca_caglesmm.js';
import AbnamroAbnanl2a from './banks/abnamro_abnanl2a.js';
import AmericanExpressAesudef1 from './banks/american-express-aesudef1.js';
import BancsabadellBsabesbb from './banks/bancsabadell-bsabesbbb.js';
import BankinterBkbkesmm from './banks/bankinter-bkbkesmm.js';
import BankOfIrelandB365 from './banks/bank_of_ireland_b365_bofiie2d.js';
import Belfius from './banks/belfius_gkccbebb.js';
import Berliner_Sparkasse_beladebexxx from './banks/berliner_sparkasse_beladebexxx.js';
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 HanseaticBank from './banks/HANSEATIC_HSTBDEHH.js';
import Hype_HYEEIT22 from './banks/hype_hyeeit22.js';
import IngIngbrobu from './banks/ing-ingbrobu.js';
import IngIngddeff from './banks/ing-ingddeff.js';
import IngPlIngbplpw from './banks/ing-pl-ingbplpw.js';
import AmericanExpressAesudef1 from './banks/american_express_aesudef1.js';
import BancsabadellBsabesbb from './banks/bancsabadell_bsabesbbb.js';
import BankinterBkbkesmm from './banks/bankinter_bkbkesmm.js';
import BankOfIrelandB365Bofiie2d from './banks/bank_of_ireland_b365_bofiie2d.js';
import BelfiusGkccbebb from './banks/belfius_gkccbebb.js';
import BerlinerSparkasseBeladebexxx from './banks/berliner_sparkasse_beladebexxx.js';
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 FortuneoFtnofrp1xxx from './banks/fortuneo_ftnofrp1xxx.js';
import HanseaticHstbdehh from './banks/hanseatic_hstbdehh.js';
import HypeHyeeit22 from './banks/hype_hyeeit22.js';
import IngIngbrobu from './banks/ing_ingbrobu.js';
import IngIngddeff from './banks/ing_ingddeff.js';
import IngPlIngbplpw from './banks/ing_pl_ingbplpw.js';
import IntegrationBank from './banks/integration-bank.js';
import IsyBankItbbitmm from './banks/isybank-itbbitmm.js';
import KBCkredbebb from './banks/kbc_kredbebb.js';
import MbankRetailBrexplpw from './banks/mbank-retail-brexplpw.js';
import NationwideNaiaGB21 from './banks/nationwide-naiagb21.js';
import IsyBankItbbitmm from './banks/isybank_itbbitmm.js';
import KbcKredbebb from './banks/kbc_kredbebb.js';
import MbankRetailBrexplpw from './banks/mbank_retail_brexplpw.js';
import NationwideNaiagb21 from './banks/nationwide_naiagb21.js';
import NbgEthngraaxxx from './banks/nbg_ethngraaxxx.js';
import NorwegianXxNorwnok1 from './banks/norwegian-xx-norwnok1.js';
import NorwegianXxNorwnok1 from './banks/norwegian_xx_norwnok1.js';
import RevolutRevolt21 from './banks/revolut_revolt21.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';
import SpkWormsAlzeyRiedMalade51wor from './banks/spk-worms-alzey-ried-malade51wor.js';
import SskDusseldorfDussdeddxxx from './banks/ssk-dusseldorf-dussdeddxxx.js';
import SwedbankHabaLV22 from './banks/swedbank-habalv22.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';
import SpkWormsAlzeyRiedMalade51wor from './banks/spk_worms_alzey_ried_malade51wor.js';
import SskDusseldorfDussdeddxxx from './banks/ssk_dusseldorf_dussdeddxxx.js';
import SwedbankHabalv22 from './banks/swedbank_habalv22.js';
import VirginNrnbgb22 from './banks/virgin_nrnbgb22.js';

export const banks = [
Expand All @@ -42,36 +42,36 @@ export const banks = [
AmericanExpressAesudef1,
BancsabadellBsabesbb,
BankinterBkbkesmm,
BankOfIrelandB365,
Belfius,
Berliner_Sparkasse_beladebexxx,
BankOfIrelandB365Bofiie2d,
BelfiusGkccbebb,
BerlinerSparkasseBeladebexxx,
BnpBeGebabebb,
CBCcregbebb,
DanskeBankDabNO22,
CbcCregbebb,
DanskebankDabno22,
EasybankBawaatww,
EntercardSwednokk,
Fortuneo,
HanseaticBank,
Hype_HYEEIT22,
FortuneoFtnofrp1xxx,
HanseaticHstbdehh,
HypeHyeeit22,
IngIngbrobu,
IngIngddeff,
IngPlIngbplpw,
IsyBankItbbitmm,
KBCkredbebb,
KbcKredbebb,
MbankRetailBrexplpw,
NationwideNaiaGB21,
NationwideNaiagb21,
NbgEthngraaxxx,
NorwegianXxNorwnok1,
RevolutRevolt21,
SEBKortBankAB,
SEBPrivat,
SebKortBankAb,
SebPrivat,
SandboxfinanceSfin0000,
SparNordSpNoDK22,
SpkKarlsruhekarsde66,
SparnordSpnodk22,
SpkKarlsruheKarsde66,
SpkMarburgBiedenkopfHeladef1mar,
SpkWormsAlzeyRiedMalade51wor,
SskDusseldorfDussdeddxxx,
SwedbankHabaLV22,
SwedbankHabalv22,
VirginNrnbgb22,
];

Expand Down
15 changes: 2 additions & 13 deletions src/app-gocardless/banks/abnamro_abnanl2a.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Fallback from './integration-bank.js';
import { printIban, amountToInteger } from '../utils.js';

import { amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
Expand All @@ -10,18 +11,6 @@ export default {

accessValidForDays: 180,

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',
};
},

normalizeTransaction(transaction, _booked) {
// There is no remittanceInformationUnstructured, so we'll make it
transaction.remittanceInformationUnstructured =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ export default {

normalizeAccount(account) {
return {
account_id: account.id,
institution: account.institution,
...Fallback.normalizeAccount(account),
// The `iban` field for these American Express cards is actually a masked
// version of the PAN. No IBAN is provided.
mask: account.iban.slice(-5),
iban: null,
name: [account.details, `(${account.iban.slice(-5)})`].join(' '),
official_name: account.details,
// The Actual account `type` field is legacy and is currently not used
// for anything, so we leave it as the default of `checking`.
type: 'checking',
};
},

Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/bank_of_ireland_b365_bofiie2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default {

institutionIds: ['BANK_OF_IRELAND_B365_BOFIIE2D'],

accessValidForDays: 180,

normalizeTransaction(transaction, booked) {
transaction.remittanceInformationUnstructured = fixupPayee(
transaction.remittanceInformationUnstructured,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Fallback from './integration-bank.js';

import { printIban } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
Expand All @@ -9,19 +8,7 @@ export default {

institutionIds: ['BANKINTER_BKBKESMM'],

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',
};
},
accessValidForDays: 180,

normalizeTransaction(transaction, _booked) {
transaction.remittanceInformationUnstructured =
Expand Down
16 changes: 2 additions & 14 deletions src/app-gocardless/banks/berliner_sparkasse_beladebexxx.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Fallback from './integration-bank.js';

import { printIban, amountToInteger } from '../utils.js';
import { amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
Expand All @@ -9,19 +9,7 @@ export default {

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',
};
},
accessValidForDays: 180,

/**
* Following the GoCardless documentation[0] we should prefer `bookingDate`
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/cbc_cregbebb.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default {

institutionIds: ['CBC_CREGBEBB'],

accessValidForDays: 180,

/**
* For negative amounts, the only payee information we have is returned in
* remittanceInformationUnstructured.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Fallback from './integration-bank.js';

import { printIban, amountToInteger } from '../utils.js';
import { amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
Expand All @@ -11,18 +11,6 @@ export default {

accessValidForDays: 180,

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.name,
type: 'checking',
};
},

normalizeTransaction(transaction, _booked) {
/**
* Danske Bank appends the EndToEndID: NOTPROVIDED to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import * as d from 'date-fns';
import {
amountToInteger,
printIban,
sortByBookingDateOrValueDate,
} from '../utils.js';

import Fallback from './integration-bank.js';

import { amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
...Fallback,

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
Expand All @@ -47,10 +34,6 @@ export default {
};
},

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

calculateStartingBalance(sortedTransactions = [], balances = []) {
return sortedTransactions.reduce((total, trans) => {
return total - amountToInteger(trans.transactionAmount.amount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {

institutionIds: ['FORTUNEO_FTNOFRP1XXX'],

accessValidForDays: 90,
accessValidForDays: 180,

normalizeTransaction(transaction, _booked) {
const date =
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/hype_hyeeit22.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {

institutionIds: ['HYPE_HYEEIT22'],

accessValidForDays: 90,
accessValidForDays: 180,

normalizeTransaction(transaction, _booked) {
/** Online card payments - identified by "crd" transaction code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Fallback from './integration-bank.js';

import { printIban, amountToInteger } from '../utils.js';
import { amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
Expand All @@ -11,18 +11,6 @@ export default {

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
institution: account.institution,
mask: account.iban.slice(-4),
iban: account.iban,
name: [account.product, printIban(account)].join(' '),
official_name: account.product,
type: 'checking',
};
},

normalizeTransaction(transaction, _booked) {
const remittanceInformationMatch = /remittanceinformation:(.*)$/.exec(
transaction.remittanceInformationUnstructured,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Fallback from './integration-bank.js';

import { printIban, amountToInteger } from '../utils.js';
import { amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
Expand All @@ -11,18 +11,6 @@ export default {

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
institution: account.institution,
mask: account.iban.slice(-4),
iban: account.iban,
name: [account.product, printIban(account)].join(' ').trim(),
official_name: account.product,
type: 'checking',
};
},

normalizeTransaction(transaction, _booked) {
return {
...transaction,
Expand Down
Loading
Loading