Skip to content

Commit

Permalink
refactor gocardless payeeName
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd committed May 25, 2024
1 parent 10261e0 commit 37f1258
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 63 deletions.
2 changes: 0 additions & 2 deletions src/app-gocardless/banks/american-express-aesudef1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { amountToInteger, sortByBookingDateOrValueDate } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down Expand Up @@ -27,7 +26,6 @@ export default {
return {
...transaction,
date: transaction.bookingDate,
payeeName: formatPayeeName(transaction),
};
},

Expand Down
15 changes: 6 additions & 9 deletions src/app-gocardless/banks/bankinter-bkbkesmm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
amountToInteger,
sortByBookingDateOrValueDate,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

const SORTED_BALANCE_TYPE_LIST = [
'closingBooked',
Expand Down Expand Up @@ -34,16 +33,14 @@ export default {
},

normalizeTransaction(transaction, _booked) {
transaction.debtorName = transaction.debtorName?.replaceAll(';', ' ');
transaction.creditorName = transaction.creditorName?.replaceAll(';', ' ');
transaction.remittanceInformationUnstructured =
transaction.remittanceInformationUnstructured
.replaceAll(/\/Txt\/(\w\|)?/gi, '')
.replaceAll(';', ' ');

return {
...transaction,
payeeName: formatPayeeName(transaction),
debtorName: transaction.debtorName?.replaceAll(';', ' '),
creditorName: transaction.creditorName?.replaceAll(';', ' '),
remittanceInformationUnstructured:
transaction.remittanceInformationUnstructured
.replaceAll(/\/Txt\/(\w\|)?/gi, '')
.replaceAll(';', ' '),
date: transaction.bookingDate || transaction.valueDate,
};
},
Expand Down
2 changes: 0 additions & 2 deletions src/app-gocardless/banks/belfius_gkccbebb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Fallback from './integration-bank.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand All @@ -19,7 +18,6 @@ export default {
...transaction,
transactionId: transaction.internalTransactionId,
date: transaction.bookingDate || transaction.valueDate,
payeeName: formatPayeeName(transaction),
};
},

Expand Down
2 changes: 0 additions & 2 deletions src/app-gocardless/banks/bnp-be-gebabebb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
amountToInteger,
printIban,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

const SORTED_BALANCE_TYPE_LIST = [
'closingBooked',
Expand Down Expand Up @@ -97,7 +96,6 @@ export default {
...transaction,
creditorName: creditorName,
date: transaction.valueDate || transaction.bookingDate,
payeeName: formatPayeeName(transaction),
};
},

Expand Down
2 changes: 0 additions & 2 deletions src/app-gocardless/banks/danskebank-dabno22.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
amountToInteger,
sortByBookingDateOrValueDate,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down Expand Up @@ -44,7 +43,6 @@ export default {
return {
...transaction,
date: transaction.bookingDate,
payeeName: formatPayeeName(transaction),
};
},

Expand Down
5 changes: 1 addition & 4 deletions src/app-gocardless/banks/ing-ingddeff.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { printIban, amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down Expand Up @@ -27,12 +26,10 @@ export default {
? remittanceInformationMatch[1]
: transaction.remittanceInformationUnstructured;

transaction.remittanceInformationUnstructured = remittanceInformation;

return {
...transaction,
remittanceInformationUnstructured: remittanceInformation,
date: transaction.bookingDate || transaction.valueDate,
payeeName: formatPayeeName(transaction),
};
},

Expand Down
2 changes: 0 additions & 2 deletions src/app-gocardless/banks/ing-pl-ingbplpw.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { printIban, amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand All @@ -23,7 +22,6 @@ export default {
return {
...transaction,
date: transaction.bookingDate || transaction.valueDate,
payeeName: formatPayeeName(transaction),
};
},

Expand Down
4 changes: 0 additions & 4 deletions src/app-gocardless/banks/integration-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
amountToInteger,
printIban,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

const SORTED_BALANCE_TYPE_LIST = [
'closingBooked',
Expand Down Expand Up @@ -52,18 +51,15 @@ export default {
transaction.bookingDateTime ||
transaction.valueDate ||
transaction.valueDateTime;

// If we couldn't find a valid date field we filter out this transaction
// and hope that we will import it again once the bank has processed the
// transaction further.
if (!date) {
return null;
}

return {
...transaction,
date: d.format(d.parseISO(date), 'yyyy-MM-dd'),
payeeName: formatPayeeName(transaction),
};
},

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

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand All @@ -23,7 +22,6 @@ export default {
return {
...transaction,
date: transaction.bookingDate || transaction.valueDate,
payeeName: formatPayeeName(transaction),
};
},

Expand Down
4 changes: 0 additions & 4 deletions src/app-gocardless/banks/norwegian-xx-norwnok1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
amountToInteger,
sortByBookingDateOrValueDate,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down Expand Up @@ -35,7 +34,6 @@ export default {
return {
...transaction,
date: transaction.bookingDate,
payeeName: formatPayeeName(transaction),
};
}

Expand All @@ -55,7 +53,6 @@ export default {
return {
...transaction,
date: transaction.valueDate,
payeeName: formatPayeeName(transaction),
};
}

Expand All @@ -68,7 +65,6 @@ export default {
return {
...transaction,
date: matches[1],
payeeName: formatPayeeName(transaction),
};
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/app-gocardless/banks/sandboxfinance-sfin0000.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
amountToInteger,
sortByBookingDateOrValueDate,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down Expand Up @@ -35,7 +34,6 @@ export default {
return {
...transaction,
date: transaction.bookingDate || transaction.valueDate,
payeeName: formatPayeeName(transaction),
};
},

Expand Down
7 changes: 2 additions & 5 deletions src/app-gocardless/banks/seb-kort-bank-ab.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
amountToInteger,
sortByBookingDateOrValueDate,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand All @@ -27,13 +26,11 @@ export default {
* Sign of transaction amount needs to be flipped for SEB credit cards
*/
normalizeTransaction(transaction, _booked) {
// Creditor name is stored in additionInformation for SEB
transaction.creditorName = transaction.additionalInformation;

return {
...transaction,
// Creditor name is stored in additionInformation for SEB
creditorName: transaction.additionalInformation,
date: transaction.valueDate,
payeeName: formatPayeeName(transaction),
transactionAmount: {
// Flip transaction amount sign
amount: (-parseFloat(transaction.transactionAmount.amount)).toString(),
Expand Down
9 changes: 2 additions & 7 deletions src/app-gocardless/banks/seb-privat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
amountToInteger,
printIban,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down Expand Up @@ -32,21 +31,17 @@ export default {
transaction.bookingDateTime ||
transaction.valueDate ||
transaction.valueDateTime;

// If we couldn't find a valid date field we filter out this transaction
// and hope that we will import it again once the bank has processed the
// transaction further.
if (!date) {
return null;
}

// Creditor name is stored in additionInformation for SEB
transaction.creditorName = transaction.additionalInformation;

return {
...transaction,
// Creditor name is stored in additionInformation for SEB
creditorName: transaction.additionalInformation,
date: d.format(d.parseISO(date), 'yyyy-MM-dd'),
payeeName: formatPayeeName(transaction),
};
},

Expand Down
6 changes: 1 addition & 5 deletions src/app-gocardless/banks/sparnord-spnodk22.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
amountToInteger,
printIban,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

const SORTED_BALANCE_TYPE_LIST = [
'closingBooked',
Expand Down Expand Up @@ -43,13 +42,10 @@ export default {
* Banks on the BEC backend only give information regarding the transaction in additionalInformation
*/
normalizeTransaction(transaction, _booked) {
transaction.remittanceInformationUnstructured =
transaction.additionalInformation;

return {
...transaction,
date: transaction.bookingDate,
payeeName: formatPayeeName(transaction),
remittanceInformationUnstructured: transaction.additionalInformation,
};
},

Expand Down
9 changes: 3 additions & 6 deletions src/app-gocardless/banks/spk-karlsruhe-karsde66.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
amountToInteger,
sortByBookingDateOrValueDate,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
Expand Down Expand Up @@ -62,18 +61,16 @@ export default {
remittanceInformationUnstructured +=
' ' + transaction.additionalInformation;

transaction.remittanceInformationUnstructured =
remittanceInformationUnstructured;

transaction.creditorName =
const usefulCreditorName =
transaction.ultimateCreditor ||
transaction.creditorName ||
transaction.debtorName;

return {
...transaction,
creditorName: usefulCreditorName,
remittanceInformationUnstructured: remittanceInformationUnstructured,
date: transaction.bookingDate || transaction.valueDate,
payeeName: formatPayeeName(transaction),
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
amountToInteger,
sortByBookingDateOrValueDate,
} from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';
import d from 'date-fns';

const SORTED_BALANCE_TYPE_LIST = [
Expand Down Expand Up @@ -63,13 +62,10 @@ export default {
transaction.remittanceInformationStructuredArray?.join(' ');
}

transaction.remittanceInformationUnstructured =
remittanceInformationUnstructured;

return {
...transaction,
date: d.format(d.parseISO(date), 'yyyy-MM-dd'),
payeeName: formatPayeeName(transaction),
remittanceInformationUnstructured: remittanceInformationUnstructured,
};
},

Expand Down
11 changes: 11 additions & 0 deletions src/app-gocardless/services/gocardless-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as nordigenNode from 'nordigen-node';
import * as uuid from 'uuid';
import jwt from 'jws';
import { SecretName, secretsService } from '../../services/secrets-service.js';
import { formatPayeeName } from '../../util/payee-name.js';

const GoCardlessClient = nordigenNode.default;

Expand Down Expand Up @@ -211,6 +212,16 @@ export const goCardlessService = {
goCardlessService.getBalances(accountId),
]);

transactions.transactions.booked = transactions.transactions?.booked?.map(t => ({

Check failure on line 215 in src/app-gocardless/services/gocardless-service.js

View workflow job for this annotation

GitHub Actions / lint

Replace `t` with `⏎······(t)`
...t,

Check failure on line 216 in src/app-gocardless/services/gocardless-service.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
payeeName: formatPayeeName(t),

Check failure on line 217 in src/app-gocardless/services/gocardless-service.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
}));

Check failure on line 218 in src/app-gocardless/services/gocardless-service.js

View workflow job for this annotation

GitHub Actions / lint

Replace `})` with `··}),⏎····`

transactions.transactions.pending = transactions.transactions?.pending?.map(t => ({

Check failure on line 220 in src/app-gocardless/services/gocardless-service.js

View workflow job for this annotation

GitHub Actions / lint

Replace `t` with `⏎······(t)`
...t,

Check failure on line 221 in src/app-gocardless/services/gocardless-service.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
payeeName: formatPayeeName(t),

Check failure on line 222 in src/app-gocardless/services/gocardless-service.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
}));

Check failure on line 223 in src/app-gocardless/services/gocardless-service.js

View workflow job for this annotation

GitHub Actions / lint

Replace `})` with `··}),⏎····`

const bank = BankFactory(institution_id);
const sortedBookedTransactions = bank.sortTransactions(
transactions.transactions?.booked,
Expand Down

0 comments on commit 37f1258

Please sign in to comment.