Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ rename nordigen to gocardless #231

Merged
merged 2 commits into from
Jul 24, 2023
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
6 changes: 3 additions & 3 deletions src/app-nordigen/README.md → src/app-gocardless/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Find in [doc](https://docs.google.com/spreadsheets/d/1ogpzydzotOltbssrc3IQ8rhBLlIZbQgm5QCiiNJrkyA/edit#gid=489769432) what is id of bank which you want to integrate

Add the `institution_id` and your name to list of possible options in the frontend
project `actual/packages/loot-design/src/components/modals/NordigenExternalMsg.js`
project `actual` in file `GoCardlessExternalMsg.js`

```jsx
<Strong>Choose your banks:</Strong>
Expand All @@ -23,7 +23,7 @@ Create new linked account selecting the institution which you added recently.
In the server logs you can find all required information to create class for
your bank.

Create new a bank class based on `app-nordigen/banks/sandboxfinance-sfin0000.js`. Name of the file and class should be
Create new a bank class based on `app-gocardless/banks/sandboxfinance-sfin0000.js`. Name of the file and class should be
created based on the ID of the integrated institution.

Fill the logic of `normalizeAccount`, `sortTransactions`, and `calculateStartingBalance` functions.
Expand Down Expand Up @@ -56,6 +56,6 @@ Available (first 10) transactions properties for new integration of institution
}
```

Add new bank integration to `BankFactory` class in file `actual-server/app-nordigen/bank-factory.js`
Add new bank integration to `BankFactory` class in file `actual-server/app-gocardless/bank-factory.js`

Remember to add tests for new bank integration in
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import express from 'express';
import path from 'path';
import { inspect } from 'util';

import { nordigenService } from './services/nordigen-service.js';
import { goCardlessService } from './services/gocardless-service.js';
import {
RequisitionNotLinked,
AccountNotLinedToRequisition,
GenericNordigenError,
GenericGoCardlessError,
} from './errors.js';
import { handleError } from './util/handle-error.js';
import { sha256String } from '../util/hash.js';
import validateUser from '../util/validate-user.js';

const app = express();
app.get('/link', function (req, res) {
res.sendFile('link.html', { root: path.resolve('./src/app-nordigen') });
res.sendFile('link.html', { root: path.resolve('./src/app-gocardless') });
});

export { app as handlers };
Expand All @@ -32,7 +32,7 @@ app.post('/status', async (req, res) => {
res.send({
status: 'ok',
data: {
configured: nordigenService.isConfigured(),
configured: goCardlessService.isConfigured(),
},
});
});
Expand All @@ -43,7 +43,7 @@ app.post(
const { accessValidForDays, institutionId } = req.body;
const { origin } = req.headers;

const { link, requisitionId } = await nordigenService.createRequisition({
const { link, requisitionId } = await goCardlessService.createRequisition({
accessValidForDays,
institutionId,
host: origin,
Expand All @@ -66,7 +66,7 @@ app.post(

try {
const { requisition, accounts } =
await nordigenService.getRequisitionWithAccounts(requisitionId);
await goCardlessService.getRequisitionWithAccounts(requisitionId);

res.send({
status: 'ok',
Expand Down Expand Up @@ -99,8 +99,8 @@ app.post(
handleError(async (req, res) => {
let { country, showDemo = false } = req.body;

await nordigenService.setToken();
const data = await nordigenService.getInstitutions(country);
await goCardlessService.setToken();
const data = await goCardlessService.getInstitutions(country);

res.send({
status: 'ok',
Expand All @@ -122,7 +122,7 @@ app.post(
handleError(async (req, res) => {
let { requisitionId } = req.body;

const data = await nordigenService.deleteRequisition(requisitionId);
const data = await goCardlessService.deleteRequisition(requisitionId);
if (data.summary === 'Requisition deleted') {
res.send({
status: 'ok',
Expand Down Expand Up @@ -152,7 +152,7 @@ app.post(
institutionId,
startingBalance,
transactions: { booked, pending, all },
} = await nordigenService.getTransactionsWithBalance(
} = await goCardlessService.getTransactionsWithBalance(
requisitionId,
accountId,
startDate,
Expand Down Expand Up @@ -195,7 +195,7 @@ app.post(
reason: 'Account not linked with this requisition',
});
break;
case error instanceof GenericNordigenError:
case error instanceof GenericGoCardlessError:
console.log('Something went wrong', inspect(error, { depth: null }));
sendErrorResponse({
error_type: 'SYNC_ERROR',
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
DetailedAccountWithInstitution,
NormalizedAccountDetails,
} from '../nordigen.types.js';
import { Transaction, Balance } from '../nordigen-node.types.js';
} from '../gocardless.types.js';
import { Transaction, Balance } from '../gocardless-node.types.js';

export interface IBank {
institutionId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mockTransactionAmount } from '../../services/tests/fixtures.js';

describe('IngPlIngbplpw', () => {
describe('#normalizeAccount', () => {
/** @type {import('../../nordigen.types.js').DetailedAccountWithInstitution} */
/** @type {import('../../gocardless.types.js').DetailedAccountWithInstitution} */
const accountRaw = {
resourceId: 'PL00000000000000000987654321',
iban: 'PL00000000000000000987654321',
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('IngPlIngbplpw', () => {

describe('#countStartingBalance', () => {
it('should calculate the starting balance correctly', () => {
/** @type {import('../../nordigen-node.types.js').Transaction[]} */
/** @type {import('../../gocardless-node.types.js').Transaction[]} */
const sortedTransactions = [
{
transactionAmount: { amount: '-100.00', currency: 'USD' },
Expand All @@ -162,7 +162,7 @@ describe('IngPlIngbplpw', () => {
},
];

/** @type {import('../../nordigen-node.types.js').Balance[]} */
/** @type {import('../../gocardless-node.types.js').Balance[]} */
const balances = [
{
balanceType: 'interimBooked',
Expand All @@ -185,7 +185,7 @@ describe('IngPlIngbplpw', () => {
it('returns the same balance amount when no transactions', () => {
const transactions = [];

/** @type {import('../../nordigen-node.types.js').Balance[]} */
/** @type {import('../../gocardless-node.types.js').Balance[]} */
const balances = [
{
balanceType: 'interimBooked',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('IntegrationBank', () => {
});

describe('calculateStartingBalance', () => {
/** @type {import('../../nordigen-node.types.js').Transaction[]} */
/** @type {import('../../gocardless-node.types.js').Transaction[]} */
const transactions = [
{
bookingDate: '2022-01-01',
Expand All @@ -122,7 +122,7 @@ describe('IntegrationBank', () => {
},
];

/** @type {import('../../nordigen-node.types.js').Balance[]} */
/** @type {import('../../gocardless-node.types.js').Balance[]} */
const balances = [
{
balanceAmount: { amount: '1000.00', currency: 'EUR' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import MbankRetailBrexplpw from '../mbank-retail-brexplpw.js';

describe('MbankRetailBrexplpw', () => {
describe('#normalizeAccount', () => {
/** @type {import('../../nordigen.types.js').DetailedAccountWithInstitution} */
/** @type {import('../../gocardless.types.js').DetailedAccountWithInstitution} */
const accountRaw = {
iban: 'PL00000000000000000987654321',
currency: 'PLN',
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('MbankRetailBrexplpw', () => {
});

describe('#countStartingBalance', () => {
/** @type {import('../../nordigen-node.types.js').Balance[]} */
/** @type {import('../../gocardless-node.types.js').Balance[]} */
const balances = [
{
balanceAmount: { amount: '1000.00', currency: 'PLN' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mockTransactionAmount } from '../../services/tests/fixtures.js';

describe('SandboxfinanceSfin0000', () => {
describe('#normalizeAccount', () => {
/** @type {import('../../nordigen.types.js').DetailedAccountWithInstitution} */
/** @type {import('../../gocardless.types.js').DetailedAccountWithInstitution} */
const accountRaw = {
resourceId: '01F3NS5ASCNMVCTEJDT0G215YE',
iban: 'GL0865354374424724',
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('SandboxfinanceSfin0000', () => {
});

describe('#countStartingBalance', () => {
/** @type {import('../../nordigen-node.types.js').Balance[]} */
/** @type {import('../../gocardless-node.types.js').Balance[]} */
const balances = [
{
balanceAmount: { amount: '1000.00', currency: 'PLN' },
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('SandboxfinanceSfin0000', () => {
});

it('returns the balance minus the available transactions', () => {
/** @type {import('../../nordigen-node.types.js').Transaction[]} */
/** @type {import('../../gocardless-node.types.js').Transaction[]} */
const transactions = [
{
transactionAmount: { amount: '200.00', currency: 'PLN' },
Expand Down
22 changes: 11 additions & 11 deletions src/app-nordigen/errors.js → src/app-gocardless/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,45 @@ export class AccountNotLinedToRequisition extends Error {
}
}

export class GenericNordigenError extends Error {
export class GenericGoCardlessError extends Error {
constructor(data = {}) {
super('Nordigen returned error');
super('GoCardless returned error');
this.details = data;
}
}

export class NordigenClientError extends Error {
export class GoCardlessClientError extends Error {
constructor(message, details) {
super(message);
this.details = details;
}
}

export class InvalidInputDataError extends NordigenClientError {
export class InvalidInputDataError extends GoCardlessClientError {
constructor(response) {
super('Invalid provided parameters', response);
}
}

export class InvalidNordigenTokenError extends NordigenClientError {
export class InvalidGoCardlessTokenError extends GoCardlessClientError {
constructor(response) {
super('Token is invalid or expired', response);
}
}

export class AccessDeniedError extends NordigenClientError {
export class AccessDeniedError extends GoCardlessClientError {
constructor(response) {
super('IP address access denied', response);
}
}

export class NotFoundError extends NordigenClientError {
export class NotFoundError extends GoCardlessClientError {
constructor(response) {
super('Resource not found', response);
}
}

export class ResourceSuspended extends NordigenClientError {
export class ResourceSuspended extends GoCardlessClientError {
constructor(response) {
super(
'Resource was suspended due to numerous errors that occurred while accessing it',
Expand All @@ -62,7 +62,7 @@ export class ResourceSuspended extends NordigenClientError {
}
}

export class RateLimitError extends NordigenClientError {
export class RateLimitError extends GoCardlessClientError {
constructor(response) {
super(
'Daily request limit set by the Institution has been exceeded',
Expand All @@ -71,13 +71,13 @@ export class RateLimitError extends NordigenClientError {
}
}

export class UnknownError extends NordigenClientError {
export class UnknownError extends GoCardlessClientError {
constructor(response) {
super('Request to Institution returned an error', response);
}
}

export class ServiceError extends NordigenClientError {
export class ServiceError extends GoCardlessClientError {
constructor(response) {
super('Institution service unavailable', response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export type Requisition = {
};

/**
* Object representing Nordigen account details
* Object representing GoCardless account details
* Account details will be returned in Berlin Group PSD2 format.
*/
export type NordigenAccountDetails = {
export type GoCardlessAccountDetails = {
/**
* Resource id of the account
*/
Expand Down Expand Up @@ -174,31 +174,31 @@ export type NordigenAccountDetails = {
};

/**
* Representation of the Nordigen account metadata
* Representation of the GoCardless account metadata
*/
export type NordigenAccountMetadata = {
export type GoCardlessAccountMetadata = {
/**
* ID of the Nordigen account metadata
* ID of the GoCardless account metadata
*/
id: string;
/**
* Date when the Nordigen account metadata was created
* Date when the GoCardless account metadata was created
*/
created: string;
/**
* Date of the last access to the Nordigen account metadata
* Date of the last access to the GoCardless account metadata
*/
last_accessed: string;
/**
* IBAN of the Nordigen account metadata
* IBAN of the GoCardless account metadata
*/
iban: string;
/**
* ID of the institution associated with the Nordigen account metadata
* ID of the institution associated with the GoCardless account metadata
*/
institution_id: string;
/**
* Status of the Nordigen account
* Status of the GoCardless account
* DISCOVERED: User has successfully authenticated and account is discovered
* PROCESSING: Account is being processed by the Institution
* ERROR: An error was encountered when processing account
Expand All @@ -214,7 +214,7 @@ export type NordigenAccountMetadata = {
| 'READY'
| 'SUSPENDED';
/**
* Name of the owner of the Nordigen account metadata
* Name of the owner of the GoCardless account metadata
*/
owner_name: string;
};
Expand Down Expand Up @@ -406,7 +406,7 @@ export type Transaction = {
entryReference?: string;

/**
* Transaction identifier given by Nordigen
* Transaction identifier given by GoCardless
*/
internalTransactionId?: string;

Expand Down
Loading
Loading