mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-09 03:32:54 -05:00
Refactor GoCardless bank code to avoid duplication (#362)
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { amountToInteger, sortByBookingDateOrValueDate } from '../utils.js';
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import { amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['AMERICAN_EXPRESS_AESUDEF1'],
|
||||
|
||||
accessValidForDays: 180,
|
||||
@@ -29,10 +33,6 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return sortByBookingDateOrValueDate(transactions);
|
||||
},
|
||||
|
||||
/**
|
||||
* For AMERICAN_EXPRESS_AESUDEF1 we don't know what balance was
|
||||
* after each transaction so we have to calculate it by getting
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
import {
|
||||
printIban,
|
||||
amountToInteger,
|
||||
sortByBookingDateOrValueDate,
|
||||
} from '../utils.js';
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
const SORTED_BALANCE_TYPE_LIST = [
|
||||
'closingBooked',
|
||||
'expected',
|
||||
'forwardAvailable',
|
||||
'interimAvailable',
|
||||
'interimBooked',
|
||||
'nonInvoiced',
|
||||
'openingBooked',
|
||||
];
|
||||
import { printIban } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['BANKINTER_BKBKESMM'],
|
||||
|
||||
accessValidForDays: 90,
|
||||
@@ -44,21 +34,4 @@ export default {
|
||||
date: transaction.bookingDate || transaction.valueDate,
|
||||
};
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return sortByBookingDateOrValueDate(transactions);
|
||||
},
|
||||
|
||||
calculateStartingBalance(sortedTransactions = [], balances = []) {
|
||||
const currentBalance = balances
|
||||
.filter((item) => SORTED_BALANCE_TYPE_LIST.includes(item.balanceType))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
SORTED_BALANCE_TYPE_LIST.indexOf(a.balanceType) -
|
||||
SORTED_BALANCE_TYPE_LIST.indexOf(b.balanceType),
|
||||
)[0];
|
||||
return sortedTransactions.reduce((total, trans) => {
|
||||
return total - amountToInteger(trans.transactionAmount.amount);
|
||||
}, amountToInteger(currentBalance?.balanceAmount?.amount || 0));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,14 +2,12 @@ import Fallback from './integration-bank.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['BELFIUS_GKCCBEBB'],
|
||||
|
||||
accessValidForDays: 180,
|
||||
|
||||
normalizeAccount(account) {
|
||||
return Fallback.normalizeAccount(account);
|
||||
},
|
||||
|
||||
// The problem is that we have transaction with duplicated transaction ids.
|
||||
// This is not expected and the nordigen api has a work-around for some backs
|
||||
// They will set an internalTransactionId which is unique
|
||||
@@ -20,12 +18,4 @@ export default {
|
||||
date: transaction.bookingDate || transaction.valueDate,
|
||||
};
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return Fallback.sortTransactions(transactions);
|
||||
},
|
||||
|
||||
calculateStartingBalance(sortedTransactions = [], balances = []) {
|
||||
return Fallback.calculateStartingBalance(sortedTransactions, balances);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
import {
|
||||
sortByBookingDateOrValueDate,
|
||||
amountToInteger,
|
||||
printIban,
|
||||
} from '../utils.js';
|
||||
|
||||
const SORTED_BALANCE_TYPE_LIST = [
|
||||
'closingBooked',
|
||||
'expected',
|
||||
'forwardAvailable',
|
||||
'interimAvailable',
|
||||
'interimBooked',
|
||||
'nonInvoiced',
|
||||
'openingBooked',
|
||||
];
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: [
|
||||
'FINTRO_BE_GEBABEBB',
|
||||
'HELLO_BE_GEBABEBB',
|
||||
@@ -24,20 +12,6 @@ export default {
|
||||
|
||||
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',
|
||||
};
|
||||
},
|
||||
|
||||
/** BNP_BE_GEBABEBB provides a lot of useful information via the 'additionalField'
|
||||
* There does not seem to be a specification of this field, but the following information is contained in its subfields:
|
||||
* - for pending transactions: the 'atmPosName'
|
||||
@@ -98,21 +72,4 @@ export default {
|
||||
date: transaction.valueDate || transaction.bookingDate,
|
||||
};
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return sortByBookingDateOrValueDate(transactions);
|
||||
},
|
||||
|
||||
calculateStartingBalance(sortedTransactions = [], balances = []) {
|
||||
const currentBalance = balances
|
||||
.filter((item) => SORTED_BALANCE_TYPE_LIST.includes(item.balanceType))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
SORTED_BALANCE_TYPE_LIST.indexOf(a.balanceType) -
|
||||
SORTED_BALANCE_TYPE_LIST.indexOf(b.balanceType),
|
||||
)[0];
|
||||
return sortedTransactions.reduce((total, trans) => {
|
||||
return total - amountToInteger(trans.transactionAmount.amount);
|
||||
}, amountToInteger(currentBalance?.balanceAmount?.amount || 0));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
printIban,
|
||||
amountToInteger,
|
||||
sortByBookingDateOrValueDate,
|
||||
} from '../utils.js';
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import { printIban, amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['DANSKEBANK_DABANO22'],
|
||||
|
||||
accessValidForDays: 180,
|
||||
@@ -46,10 +46,6 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return sortByBookingDateOrValueDate(transactions);
|
||||
},
|
||||
|
||||
calculateStartingBalance(sortedTransactions = [], balances = []) {
|
||||
const currentBalance = balances.find(
|
||||
(balance) => balance.balanceType === 'interimAvailable',
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import { printIban, amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['ING_INGDDEFF'],
|
||||
|
||||
accessValidForDays: 180,
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import { printIban, amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['ING_PL_INGBPLPW'],
|
||||
|
||||
accessValidForDays: 180,
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import { printIban, amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['MBANK_RETAIL_BREXPLPW'],
|
||||
|
||||
accessValidForDays: 180,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
printIban,
|
||||
amountToInteger,
|
||||
sortByBookingDateOrValueDate,
|
||||
} from '../utils.js';
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import { printIban, amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: [
|
||||
'NORWEGIAN_NO_NORWNOK1',
|
||||
'NORWEGIAN_SE_NORWNOK1',
|
||||
@@ -72,10 +72,6 @@ export default {
|
||||
return null;
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return sortByBookingDateOrValueDate(transactions);
|
||||
},
|
||||
|
||||
/**
|
||||
* For NORWEGIAN_XX_NORWNOK1 we don't know what balance was
|
||||
* after each transaction so we have to calculate it by getting
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
printIban,
|
||||
amountToInteger,
|
||||
sortByBookingDateOrValueDate,
|
||||
} from '../utils.js';
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import { printIban, amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['SANDBOXFINANCE_SFIN0000'],
|
||||
|
||||
accessValidForDays: 90,
|
||||
@@ -37,10 +37,6 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
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
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
printIban,
|
||||
amountToInteger,
|
||||
sortByBookingDateOrValueDate,
|
||||
} from '../utils.js';
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import { printIban, amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['SEB_KORT_AB_NO_SKHSFI21', 'SEB_KORT_AB_SE_SKHSFI21'],
|
||||
|
||||
accessValidForDays: 180,
|
||||
@@ -39,10 +39,6 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return sortByBookingDateOrValueDate(transactions);
|
||||
},
|
||||
|
||||
/**
|
||||
* For SEB_KORT_AB_NO_SKHSFI21 and SEB_KORT_AB_SE_SKHSFI21 we don't know what balance was
|
||||
* after each transaction so we have to calculate it by getting
|
||||
|
||||
@@ -1,30 +1,16 @@
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import * as d from 'date-fns';
|
||||
import {
|
||||
sortByBookingDateOrValueDate,
|
||||
amountToInteger,
|
||||
printIban,
|
||||
} from '../utils.js';
|
||||
import { amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['SEB_ESSESESS_PRIVATE'],
|
||||
|
||||
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) {
|
||||
const date =
|
||||
transaction.bookingDate ||
|
||||
@@ -45,10 +31,6 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return sortByBookingDateOrValueDate(transactions);
|
||||
},
|
||||
|
||||
calculateStartingBalance(sortedTransactions = [], balances = []) {
|
||||
const currentBalance = balances.find(
|
||||
(balance) => 'interimBooked' === balance.balanceType,
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
import {
|
||||
sortByBookingDateOrValueDate,
|
||||
amountToInteger,
|
||||
printIban,
|
||||
} from '../utils.js';
|
||||
|
||||
const SORTED_BALANCE_TYPE_LIST = [
|
||||
'closingBooked',
|
||||
'expected',
|
||||
'forwardAvailable',
|
||||
'interimAvailable',
|
||||
'interimBooked',
|
||||
'nonInvoiced',
|
||||
'openingBooked',
|
||||
];
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: [
|
||||
'SPARNORD_SPNODK22',
|
||||
'LAGERNES_BANK_LAPNDKK1',
|
||||
@@ -24,20 +12,6 @@ export default {
|
||||
|
||||
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',
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Banks on the BEC backend only give information regarding the transaction in additionalInformation
|
||||
*/
|
||||
@@ -48,21 +22,4 @@ export default {
|
||||
remittanceInformationUnstructured: transaction.additionalInformation,
|
||||
};
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return sortByBookingDateOrValueDate(transactions);
|
||||
},
|
||||
|
||||
calculateStartingBalance(sortedTransactions = [], balances = []) {
|
||||
const currentBalance = balances
|
||||
.filter((item) => SORTED_BALANCE_TYPE_LIST.includes(item.balanceType))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
SORTED_BALANCE_TYPE_LIST.indexOf(a.balanceType) -
|
||||
SORTED_BALANCE_TYPE_LIST.indexOf(b.balanceType),
|
||||
)[0];
|
||||
return sortedTransactions.reduce((total, trans) => {
|
||||
return total - amountToInteger(trans.transactionAmount.amount);
|
||||
}, amountToInteger(currentBalance?.balanceAmount?.amount || 0));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
printIban,
|
||||
amountToInteger,
|
||||
sortByBookingDateOrValueDate,
|
||||
} from '../utils.js';
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
import { printIban, amountToInteger } from '../utils.js';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['SPK_KARLSRUHE_KARSDE66XXX'],
|
||||
|
||||
accessValidForDays: 90,
|
||||
@@ -74,10 +74,6 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
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
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
import {
|
||||
printIban,
|
||||
amountToInteger,
|
||||
sortByBookingDateOrValueDate,
|
||||
} from '../utils.js';
|
||||
import d from 'date-fns';
|
||||
import Fallback from './integration-bank.js';
|
||||
|
||||
const SORTED_BALANCE_TYPE_LIST = [
|
||||
'closingBooked',
|
||||
'expected',
|
||||
'forwardAvailable',
|
||||
'interimAvailable',
|
||||
'interimBooked',
|
||||
'nonInvoiced',
|
||||
'openingBooked',
|
||||
];
|
||||
import { printIban } from '../utils.js';
|
||||
import d from 'date-fns';
|
||||
|
||||
/** @type {import('./bank.interface.js').IBank} */
|
||||
export default {
|
||||
...Fallback,
|
||||
|
||||
institutionIds: ['SPK_MARBURG_BIEDENKOPF_HELADEF1MAR'],
|
||||
|
||||
accessValidForDays: 180,
|
||||
@@ -68,22 +58,4 @@ export default {
|
||||
remittanceInformationUnstructured: remittanceInformationUnstructured,
|
||||
};
|
||||
},
|
||||
|
||||
sortTransactions(transactions = []) {
|
||||
return sortByBookingDateOrValueDate(transactions);
|
||||
},
|
||||
|
||||
calculateStartingBalance(sortedTransactions = [], balances = []) {
|
||||
const currentBalance = balances
|
||||
.filter((item) => SORTED_BALANCE_TYPE_LIST.includes(item.balanceType))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
SORTED_BALANCE_TYPE_LIST.indexOf(a.balanceType) -
|
||||
SORTED_BALANCE_TYPE_LIST.indexOf(b.balanceType),
|
||||
)[0];
|
||||
|
||||
return sortedTransactions.reduce((total, trans) => {
|
||||
return total - amountToInteger(trans.transactionAmount.amount);
|
||||
}, amountToInteger(currentBalance?.balanceAmount?.amount || 0));
|
||||
},
|
||||
};
|
||||
|
||||
6
upcoming-release-notes/362.md
Normal file
6
upcoming-release-notes/362.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Maintenance
|
||||
authors: [psybers]
|
||||
---
|
||||
|
||||
Refactor GoCardless bank code to avoid duplication.
|
||||
Reference in New Issue
Block a user