Skip to content

Commit

Permalink
Allow setting accessValidForDays and maxHistoricalDays per bank (#334)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Get the max allowed maxHistoricalDays value from the GoCardless API

Signed-off-by: Johannes Löthberg <[email protected]>

* 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 <[email protected]>

---------

Signed-off-by: Johannes Löthberg <[email protected]>
  • Loading branch information
kyrias authored Apr 14, 2024
1 parent a5a5f30 commit ae0faf4
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"express-response-size": "^0.0.3",
"jws": "^4.0.0",
"migrate": "^2.0.1",
"nordigen-node": "^1.3.0",
"nordigen-node": "^1.4.0",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions src/app-gocardless/app-gocardless.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ app.post('/status', async (req, res) => {
app.post(
'/create-web-token',
handleError(async (req, res) => {
const { accessValidForDays, institutionId } = req.body;
const { institutionId } = req.body;
const { origin } = req.headers;

const { link, requisitionId } = await goCardlessService.createRequisition({
accessValidForDays,
institutionId,
host: origin,
});
Expand Down
22 changes: 11 additions & 11 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import AmericanExpressAesudef1 from './banks/american-express-aesudef1.js';
import Belfius from './banks/belfius_gkccbebb.js';
import BnpBeGebabebb from './banks/bnp-be-gebabebb.js';
import DanskeBankDabNO22 from './banks/danskebank-dabno22.js';
import IngIngddeff from './banks/ing-ingddeff.js';
import IngPlIngbplpw from './banks/ing-pl-ingbplpw.js';
import IntegrationBank from './banks/integration-bank.js';
import MbankRetailBrexplpw from './banks/mbank-retail-brexplpw.js';
import NorwegianXxNorwnok1 from './banks/norwegian-xx-norwnok1.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 BnpBeGebabebb from './banks/bnp-be-gebabebb.js';
import DanskeBankDabNO22 from './banks/danskebank-dabno22.js';
import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
import Belfius from './banks/belfius_gkccbebb.js';
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
import SEBPrivat from './banks/seb-privat.js';
import SEBKortBankAB from './banks/seb-kort-bank-ab.js';

const banks = [
AmericanExpressAesudef1,
Belfius,
BnpBeGebabebb,
DanskeBankDabNO22,
IngIngddeff,
IngPlIngbplpw,
MbankRetailBrexplpw,
SandboxfinanceSfin0000,
NorwegianXxNorwnok1,
BnpBeGebabebb,
DanskeBankDabNO22,
SEBKortBankAB,
SEBPrivat,
SandboxfinanceSfin0000,
SparNordSpNoDK22,
Belfius,
SpkMarburgBiedenkopfHeladef1mar,
SEBPrivat,
SEBKortBankAB,
];

export default (institutionId) =>
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/american-express-aesudef1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { amountToInteger, sortByBookingDateOrValueDate } from '../utils.js';
export default {
institutionIds: ['AMERICAN_EXPRESS_AESUDEF1'],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
3 changes: 3 additions & 0 deletions src/app-gocardless/banks/bank.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Transaction, Balance } from '../gocardless-node.types.js';

export interface IBank {
institutionIds: string[];

accessValidForDays: number;

/**
* Returns normalized object with required data for the frontend
*/
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/belfius_gkccbebb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Fallback from './integration-bank.js';
export default {
institutionIds: ['BELFIUS_GKCCBEBB'],

accessValidForDays: 180,

normalizeAccount(account) {
return Fallback.normalizeAccount(account);
},
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/bnp-be-gebabebb.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default {
'BNP_BE_GEBABEBB',
],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/danskebank-dabno22.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
export default {
institutionIds: ['DANSKEBANK_DABANO22'],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/ing-ingddeff.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { printIban, amountToInteger } from '../utils.js';
export default {
institutionIds: ['ING_INGDDEFF'],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/ing-pl-ingbplpw.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { printIban, amountToInteger } from '../utils.js';
export default {
institutionIds: ['ING_PL_INGBPLPW'],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
8 changes: 8 additions & 0 deletions src/app-gocardless/banks/integration-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ const SORTED_BALANCE_TYPE_LIST = [
/** @type {import('./bank.interface.js').IBank} */
export default {
institutionIds: ['IntegrationBank'],

// EEA need to allow at least 180 days now but this doesn't apply to UK
// banks, and it's possible that there are EEA banks which still don't follow
// the new requirements. See:
// - https://nordigen.zendesk.com/hc/en-gb/articles/13239212055581-EEA-180-day-access
// - https://nordigen.zendesk.com/hc/en-gb/articles/6760902653085-Extended-history-and-continuous-access-edge-cases
accessValidForDays: 90,

normalizeAccount(account) {
console.log(
'Available account properties for new institution integration',
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/mbank-retail-brexplpw.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { printIban, amountToInteger } from '../utils.js';
export default {
institutionIds: ['MBANK_RETAIL_BREXPLPW'],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/norwegian-xx-norwnok1.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default {
'NORWEGIAN_FI_NORWNOK1',
],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/sandboxfinance-sfin0000.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
export default {
institutionIds: ['SANDBOXFINANCE_SFIN0000'],

accessValidForDays: 90,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/banks/seb-kort-bank-ab.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
export default {
institutionIds: ['SEB_KORT_AB_SE_SKHSFI21'],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
12 changes: 3 additions & 9 deletions src/app-gocardless/banks/seb-privat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import {
/** @type {import('./bank.interface.js').IBank} */
export default {
institutionIds: ['SEB_ESSESESS_PRIVATE'],
normalizeAccount(account) {
console.log(
'Available account properties for new institution integration',
{ account: JSON.stringify(account) },
);

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
institution: account.institution,
Expand Down Expand Up @@ -48,10 +46,6 @@ export default {
},

sortTransactions(transactions = []) {
console.log(
'Available (first 10) transactions properties for new integration of institution in sortTransactions function',
{ top10Transactions: JSON.stringify(transactions.slice(0, 10)) },
);
return sortByBookingDateOrValueDate(transactions);
},

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

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const SORTED_BALANCE_TYPE_LIST = [
export default {
institutionIds: ['SPK_MARBURG_BIEDENKOPF_HELADEF1MAR'],

accessValidForDays: 180,

normalizeAccount(account) {
return {
account_id: account.id,
Expand Down
1 change: 0 additions & 1 deletion src/app-gocardless/gocardless.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export type GetTransactionsResponse = {

export type CreateRequisitionParams = {
institutionId: string;
accessValidForDays: number;

/**
* Host of your frontend app - on this host you will be redirected after linking with bank
Expand Down
9 changes: 6 additions & 3 deletions src/app-gocardless/services/gocardless-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,18 @@ export const goCardlessService = {
* @throws {ServiceError}
* @returns {Promise<{requisitionId, link}>}
*/
createRequisition: async ({ institutionId, accessValidForDays, host }) => {
createRequisition: async ({ institutionId, host }) => {
await goCardlessService.setToken();

const institution = await goCardlessService.getInstitution(institutionId);
const bank = BankFactory(institutionId);

const response = await client.initSession({
redirectUrl: host + '/gocardless/link',
institutionId,
referenceId: uuid.v4(),
accessValidForDays,
maxHistoricalDays: 90,
accessValidForDays: bank.accessValidForDays,
maxHistoricalDays: institution.transaction_total_days,
userLanguage: 'en',
ssn: null,
redirectImmediate: false,
Expand Down
2 changes: 2 additions & 0 deletions src/app-gocardless/services/tests/gocardless-service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ describe('goCardlessService', () => {

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

createRequisitionSpy.mockResolvedValue(mockCreateRequisition);

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

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

createRequisitionSpy.mockResolvedValue(mockUnknownError);

Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/334.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [kyrias]
---

Add support for setting the access validity time per GoCardless bank integration and get the max historical days from the API
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ __metadata:
jest: "npm:^29.3.1"
jws: "npm:^4.0.0"
migrate: "npm:^2.0.1"
nordigen-node: "npm:^1.3.0"
nordigen-node: "npm:^1.4.0"
prettier: "npm:^2.8.3"
supertest: "npm:^6.3.1"
typescript: "npm:^4.9.5"
Expand Down Expand Up @@ -4856,13 +4856,13 @@ __metadata:
languageName: node
linkType: hard

"nordigen-node@npm:^1.3.0":
version: 1.3.0
resolution: "nordigen-node@npm:1.3.0"
"nordigen-node@npm:^1.4.0":
version: 1.4.0
resolution: "nordigen-node@npm:1.4.0"
dependencies:
axios: "npm:^1.2.1"
dotenv: "npm:^10.0.0"
checksum: 033771af257ecf8e36a375b07e10246b08d23b647ef2db737b6efe52a1bcd68f04c88c2aff6790d4cbcd00da0148550247624142a6eea7444d370b2e65f08fc8
checksum: a04ec90480e4e65b2169d909ac9ea3044f764d59283162420d287a6b229808754dc78c758637724d63c87aa77f2237bc47543f521b0b4057ed3980d6db137e1a
languageName: node
linkType: hard

Expand Down

0 comments on commit ae0faf4

Please sign in to comment.