Skip to content

Commit

Permalink
simplefin should use formatPayeeName
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd committed May 25, 2024
1 parent be12a83 commit e016876
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/american-express-aesudef1.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {

Check failure on line 1 in src/app-gocardless/banks/american-express-aesudef1.js

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎··amountToInteger,⏎··sortByBookingDateOrValueDate,⏎` with `·amountToInteger,·sortByBookingDateOrValueDate·`
amountToInteger,
sortByBookingDateOrValueDate,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/belfius_gkccbebb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Fallback from './integration-bank.js';
import { formatPayeeName } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/bnp-be-gebabebb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
sortByBookingDateOrValueDate,
amountToInteger,
printIban,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

const SORTED_BALANCE_TYPE_LIST = [
'closingBooked',
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/danskebank-dabno22.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
printIban,
amountToInteger,
sortByBookingDateOrValueDate,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
3 changes: 2 additions & 1 deletion src/app-gocardless/banks/ing-ingddeff.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { printIban, amountToInteger, formatPayeeName } from '../utils.js';
import { printIban, amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
3 changes: 2 additions & 1 deletion src/app-gocardless/banks/ing-pl-ingbplpw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { printIban, amountToInteger, formatPayeeName } from '../utils.js';
import { printIban, amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/integration-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
sortByBookingDateOrValueDate,
amountToInteger,
printIban,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

const SORTED_BALANCE_TYPE_LIST = [
'closingBooked',
Expand Down
3 changes: 2 additions & 1 deletion src/app-gocardless/banks/mbank-retail-brexplpw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { printIban, amountToInteger, formatPayeeName } from '../utils.js';
import { printIban, amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/norwegian-xx-norwnok1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
printIban,
amountToInteger,
sortByBookingDateOrValueDate,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/sandboxfinance-sfin0000.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
printIban,
amountToInteger,
sortByBookingDateOrValueDate,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/seb-kort-bank-ab.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
printIban,
amountToInteger,
sortByBookingDateOrValueDate,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/seb-privat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
sortByBookingDateOrValueDate,
amountToInteger,
printIban,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/sparnord-spnodk22.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
sortByBookingDateOrValueDate,
amountToInteger,
printIban,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

const SORTED_BALANCE_TYPE_LIST = [
'closingBooked',
Expand Down
2 changes: 1 addition & 1 deletion src/app-gocardless/banks/spk-karlsruhe-karsde66.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
printIban,
amountToInteger,
sortByBookingDateOrValueDate,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
printIban,
amountToInteger,
sortByBookingDateOrValueDate,
formatPayeeName,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';
import d from 'date-fns';

const SORTED_BALANCE_TYPE_LIST = [
Expand Down
43 changes: 0 additions & 43 deletions src/app-gocardless/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { title } from './util/title/index.js';

function formatPayeeIban(iban) {
return '(' + iban.slice(0, 4) + ' XXX ' + iban.slice(-4) + ')';
}

export const printIban = (account) => {
if (account.iban) {
return '(XXX ' + account.iban.slice(-4) + ')';
Expand All @@ -20,40 +14,3 @@ export const sortByBookingDateOrValueDate = (transactions = []) =>
);

export const amountToInteger = (n) => Math.round(n * 100);

export const formatPayeeName = (trans) => {
const nameParts = [];

// get the correct name and account fields for the transaction amount
let name;
let account;
if (trans.amount > 0 || Object.is(Number(trans.amount), 0)) {
name = trans.debtorName;
account = trans.debtorAccount;
} else {
name = trans.creditorName;
account = trans.creditorAccount;
}

// use the correct fields for the amount if it was found
// if not, use whatever we can find
name =
name ||
trans.debtorName ||
trans.creditorName ||
trans.remittanceInformationUnstructured ||
(trans.remittanceInformationUnstructuredArray || []).join(', ') ||
trans.additionalInformation;

account = account || trans.debtorAccount || trans.creditorAccount;

if (name) {
nameParts.push(title(name));
}

if (account && account.iban) {
nameParts.push(formatPayeeIban(account.iban));
}

return nameParts.join(' ');
};
4 changes: 2 additions & 2 deletions src/app-simplefin/app-simplefin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express from 'express';
import { inspect } from 'util';
import https from 'https';
import { SecretName, secretsService } from '../services/secrets-service.js';
import { formatPayeeName } from '../util/payee-name.js';

const app = express();
export { app as handlers };
Expand Down Expand Up @@ -109,8 +110,7 @@ app.post('/transactions', async (req, res) => {
.split('T')[0];

newTrans.date = new Date(dateToUse * 1000).toISOString().split('T')[0];
newTrans.payeeName = trans.payee;
//newTrans.debtorAccount = don't have compared to GoCardless
newTrans.payeeName = formatPayeeName(trans);
newTrans.remittanceInformationUnstructured = trans.description;
newTrans.transactionAmount = { amount: trans.amount, currency: 'USD' };
newTrans.transactionId = trans.id;
Expand Down
42 changes: 42 additions & 0 deletions src/util/payee-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { title } from './title/index.js';

function formatPayeeIban(iban) {
return '(' + iban.slice(0, 4) + ' XXX ' + iban.slice(-4) + ')';
}

export const formatPayeeName = (trans) => {
const nameParts = [];

// get the correct name and account fields for the transaction amount
let name;
let account;
if (trans.amount > 0 || Object.is(Number(trans.amount), 0)) {
name = trans.debtorName;
account = trans.debtorAccount;
} else {
name = trans.creditorName;
account = trans.creditorAccount;
}

// use the correct fields for the amount if it was found
// if not, use whatever we can find
name =
name ||
trans.debtorName ||
trans.creditorName ||
trans.remittanceInformationUnstructured ||
(trans.remittanceInformationUnstructuredArray || []).join(', ') ||
trans.additionalInformation;

account = account || trans.debtorAccount || trans.creditorAccount;

if (name) {
nameParts.push(title(name));
}

if (account && account.iban) {
nameParts.push(formatPayeeIban(account.iban));
}

return nameParts.join(' ');
};
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e016876

Please sign in to comment.