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

Commit ae0faf4

Browse files
authored
Allow setting accessValidForDays and maxHistoricalDays per bank (#334)
* Allow setting accessValidForDays per bank This also stops taking `accessValidForDays` from the client since it's hardcoded there anyway and it's simpler to just have these per-bank values in one place. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> * Get the max allowed maxHistoricalDays value from the GoCardless API Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> * Upgrade nordigen-node to 1.4.0 Contrary to the claims in the nordigen-node changelog 1.3.0 did *not* fix the missing support for passing in accessValidForDays, so we have to upgrade to 1.4.0 to actually get the fix. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --------- Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
1 parent a5a5f30 commit ae0faf4

23 files changed

+70
-32
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"express-response-size": "^0.0.3",
3030
"jws": "^4.0.0",
3131
"migrate": "^2.0.1",
32-
"nordigen-node": "^1.3.0",
32+
"nordigen-node": "^1.4.0",
3333
"uuid": "^9.0.0"
3434
},
3535
"devDependencies": {

src/app-gocardless/app-gocardless.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ app.post('/status', async (req, res) => {
4040
app.post(
4141
'/create-web-token',
4242
handleError(async (req, res) => {
43-
const { accessValidForDays, institutionId } = req.body;
43+
const { institutionId } = req.body;
4444
const { origin } = req.headers;
4545

4646
const { link, requisitionId } = await goCardlessService.createRequisition({
47-
accessValidForDays,
4847
institutionId,
4948
host: origin,
5049
});

src/app-gocardless/bank-factory.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import AmericanExpressAesudef1 from './banks/american-express-aesudef1.js';
2+
import Belfius from './banks/belfius_gkccbebb.js';
3+
import BnpBeGebabebb from './banks/bnp-be-gebabebb.js';
4+
import DanskeBankDabNO22 from './banks/danskebank-dabno22.js';
25
import IngIngddeff from './banks/ing-ingddeff.js';
36
import IngPlIngbplpw from './banks/ing-pl-ingbplpw.js';
47
import IntegrationBank from './banks/integration-bank.js';
58
import MbankRetailBrexplpw from './banks/mbank-retail-brexplpw.js';
69
import NorwegianXxNorwnok1 from './banks/norwegian-xx-norwnok1.js';
10+
import SEBKortBankAB from './banks/seb-kort-bank-ab.js';
11+
import SEBPrivat from './banks/seb-privat.js';
712
import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
8-
import BnpBeGebabebb from './banks/bnp-be-gebabebb.js';
9-
import DanskeBankDabNO22 from './banks/danskebank-dabno22.js';
1013
import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
11-
import Belfius from './banks/belfius_gkccbebb.js';
1214
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
13-
import SEBPrivat from './banks/seb-privat.js';
14-
import SEBKortBankAB from './banks/seb-kort-bank-ab.js';
1515

1616
const banks = [
1717
AmericanExpressAesudef1,
18+
Belfius,
19+
BnpBeGebabebb,
20+
DanskeBankDabNO22,
1821
IngIngddeff,
1922
IngPlIngbplpw,
2023
MbankRetailBrexplpw,
21-
SandboxfinanceSfin0000,
2224
NorwegianXxNorwnok1,
23-
BnpBeGebabebb,
24-
DanskeBankDabNO22,
25+
SEBKortBankAB,
26+
SEBPrivat,
27+
SandboxfinanceSfin0000,
2528
SparNordSpNoDK22,
26-
Belfius,
2729
SpkMarburgBiedenkopfHeladef1mar,
28-
SEBPrivat,
29-
SEBKortBankAB,
3030
];
3131

3232
export default (institutionId) =>

src/app-gocardless/banks/american-express-aesudef1.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { amountToInteger, sortByBookingDateOrValueDate } from '../utils.js';
44
export default {
55
institutionIds: ['AMERICAN_EXPRESS_AESUDEF1'],
66

7+
accessValidForDays: 180,
8+
79
normalizeAccount(account) {
810
return {
911
account_id: account.id,

src/app-gocardless/banks/bank.interface.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { Transaction, Balance } from '../gocardless-node.types.js';
66

77
export interface IBank {
88
institutionIds: string[];
9+
10+
accessValidForDays: number;
11+
912
/**
1013
* Returns normalized object with required data for the frontend
1114
*/

src/app-gocardless/banks/belfius_gkccbebb.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Fallback from './integration-bank.js';
44
export default {
55
institutionIds: ['BELFIUS_GKCCBEBB'],
66

7+
accessValidForDays: 180,
8+
79
normalizeAccount(account) {
810
return Fallback.normalizeAccount(account);
911
},

src/app-gocardless/banks/bnp-be-gebabebb.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export default {
2222
'BNP_BE_GEBABEBB',
2323
],
2424

25+
accessValidForDays: 180,
26+
2527
normalizeAccount(account) {
2628
return {
2729
account_id: account.id,

src/app-gocardless/banks/danskebank-dabno22.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
export default {
99
institutionIds: ['DANSKEBANK_DABANO22'],
1010

11+
accessValidForDays: 180,
12+
1113
normalizeAccount(account) {
1214
return {
1315
account_id: account.id,

src/app-gocardless/banks/ing-ingddeff.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { printIban, amountToInteger } from '../utils.js';
44
export default {
55
institutionIds: ['ING_INGDDEFF'],
66

7+
accessValidForDays: 180,
8+
79
normalizeAccount(account) {
810
return {
911
account_id: account.id,

src/app-gocardless/banks/ing-pl-ingbplpw.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { printIban, amountToInteger } from '../utils.js';
44
export default {
55
institutionIds: ['ING_PL_INGBPLPW'],
66

7+
accessValidForDays: 180,
8+
79
normalizeAccount(account) {
810
return {
911
account_id: account.id,

src/app-gocardless/banks/integration-bank.js

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ const SORTED_BALANCE_TYPE_LIST = [
1818
/** @type {import('./bank.interface.js').IBank} */
1919
export default {
2020
institutionIds: ['IntegrationBank'],
21+
22+
// EEA need to allow at least 180 days now but this doesn't apply to UK
23+
// banks, and it's possible that there are EEA banks which still don't follow
24+
// the new requirements. See:
25+
// - https://nordigen.zendesk.com/hc/en-gb/articles/13239212055581-EEA-180-day-access
26+
// - https://nordigen.zendesk.com/hc/en-gb/articles/6760902653085-Extended-history-and-continuous-access-edge-cases
27+
accessValidForDays: 90,
28+
2129
normalizeAccount(account) {
2230
console.log(
2331
'Available account properties for new institution integration',

src/app-gocardless/banks/mbank-retail-brexplpw.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { printIban, amountToInteger } from '../utils.js';
44
export default {
55
institutionIds: ['MBANK_RETAIL_BREXPLPW'],
66

7+
accessValidForDays: 180,
8+
79
normalizeAccount(account) {
810
return {
911
account_id: account.id,

src/app-gocardless/banks/norwegian-xx-norwnok1.js

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export default {
1515
'NORWEGIAN_FI_NORWNOK1',
1616
],
1717

18+
accessValidForDays: 180,
19+
1820
normalizeAccount(account) {
1921
return {
2022
account_id: account.id,

src/app-gocardless/banks/sandboxfinance-sfin0000.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
export default {
99
institutionIds: ['SANDBOXFINANCE_SFIN0000'],
1010

11+
accessValidForDays: 90,
12+
1113
normalizeAccount(account) {
1214
return {
1315
account_id: account.id,

src/app-gocardless/banks/seb-kort-bank-ab.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
export default {
99
institutionIds: ['SEB_KORT_AB_SE_SKHSFI21'],
1010

11+
accessValidForDays: 180,
12+
1113
normalizeAccount(account) {
1214
return {
1315
account_id: account.id,

src/app-gocardless/banks/seb-privat.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import {
88
/** @type {import('./bank.interface.js').IBank} */
99
export default {
1010
institutionIds: ['SEB_ESSESESS_PRIVATE'],
11-
normalizeAccount(account) {
12-
console.log(
13-
'Available account properties for new institution integration',
14-
{ account: JSON.stringify(account) },
15-
);
1611

12+
accessValidForDays: 180,
13+
14+
normalizeAccount(account) {
1715
return {
1816
account_id: account.id,
1917
institution: account.institution,
@@ -48,10 +46,6 @@ export default {
4846
},
4947

5048
sortTransactions(transactions = []) {
51-
console.log(
52-
'Available (first 10) transactions properties for new integration of institution in sortTransactions function',
53-
{ top10Transactions: JSON.stringify(transactions.slice(0, 10)) },
54-
);
5549
return sortByBookingDateOrValueDate(transactions);
5650
},
5751

src/app-gocardless/banks/sparnord-spnodk22.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export default {
2222
'ANDELSKASSEN_FALLESKASSEN_FAELDKK1',
2323
],
2424

25+
accessValidForDays: 180,
26+
2527
normalizeAccount(account) {
2628
return {
2729
account_id: account.id,

src/app-gocardless/banks/spk-marburg-biedenkopf-heladef1mar.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const SORTED_BALANCE_TYPE_LIST = [
1919
export default {
2020
institutionIds: ['SPK_MARBURG_BIEDENKOPF_HELADEF1MAR'],
2121

22+
accessValidForDays: 180,
23+
2224
normalizeAccount(account) {
2325
return {
2426
account_id: account.id,

src/app-gocardless/gocardless.types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export type GetTransactionsResponse = {
8181

8282
export type CreateRequisitionParams = {
8383
institutionId: string;
84-
accessValidForDays: number;
8584

8685
/**
8786
* Host of your frontend app - on this host you will be redirected after linking with bank

src/app-gocardless/services/gocardless-service.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,18 @@ export const goCardlessService = {
257257
* @throws {ServiceError}
258258
* @returns {Promise<{requisitionId, link}>}
259259
*/
260-
createRequisition: async ({ institutionId, accessValidForDays, host }) => {
260+
createRequisition: async ({ institutionId, host }) => {
261261
await goCardlessService.setToken();
262262

263+
const institution = await goCardlessService.getInstitution(institutionId);
264+
const bank = BankFactory(institutionId);
265+
263266
const response = await client.initSession({
264267
redirectUrl: host + '/gocardless/link',
265268
institutionId,
266269
referenceId: uuid.v4(),
267-
accessValidForDays,
268-
maxHistoricalDays: 90,
270+
accessValidForDays: bank.accessValidForDays,
271+
maxHistoricalDays: institution.transaction_total_days,
269272
userLanguage: 'en',
270273
ssn: null,
271274
redirectImmediate: false,

src/app-gocardless/services/tests/gocardless-service.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ describe('goCardlessService', () => {
242242

243243
it('calls goCardlessClient and delete requisition', async () => {
244244
setTokenSpy.mockResolvedValue();
245+
getInstitutionSpy.mockResolvedValue(mockInstitution);
245246

246247
createRequisitionSpy.mockResolvedValue(mockCreateRequisition);
247248

@@ -255,6 +256,7 @@ describe('goCardlessService', () => {
255256

256257
it('handle error if status_code present in the response', async () => {
257258
setTokenSpy.mockResolvedValue();
259+
getInstitutionSpy.mockResolvedValue(mockInstitution);
258260

259261
createRequisitionSpy.mockResolvedValue(mockUnknownError);
260262

upcoming-release-notes/334.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: Enhancements
3+
authors: [kyrias]
4+
---
5+
6+
Add support for setting the access validity time per GoCardless bank integration and get the max historical days from the API

yarn.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ __metadata:
16391639
jest: "npm:^29.3.1"
16401640
jws: "npm:^4.0.0"
16411641
migrate: "npm:^2.0.1"
1642-
nordigen-node: "npm:^1.3.0"
1642+
nordigen-node: "npm:^1.4.0"
16431643
prettier: "npm:^2.8.3"
16441644
supertest: "npm:^6.3.1"
16451645
typescript: "npm:^4.9.5"
@@ -4856,13 +4856,13 @@ __metadata:
48564856
languageName: node
48574857
linkType: hard
48584858

4859-
"nordigen-node@npm:^1.3.0":
4860-
version: 1.3.0
4861-
resolution: "nordigen-node@npm:1.3.0"
4859+
"nordigen-node@npm:^1.4.0":
4860+
version: 1.4.0
4861+
resolution: "nordigen-node@npm:1.4.0"
48624862
dependencies:
48634863
axios: "npm:^1.2.1"
48644864
dotenv: "npm:^10.0.0"
4865-
checksum: 033771af257ecf8e36a375b07e10246b08d23b647ef2db737b6efe52a1bcd68f04c88c2aff6790d4cbcd00da0148550247624142a6eea7444d370b2e65f08fc8
4865+
checksum: a04ec90480e4e65b2169d909ac9ea3044f764d59283162420d287a6b229808754dc78c758637724d63c87aa77f2237bc47543f521b0b4057ed3980d6db137e1a
48664866
languageName: node
48674867
linkType: hard
48684868

0 commit comments

Comments
 (0)