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

Add custom handler for the German bank Rheinhessen Sparkasse to the GoCardless app #454

Merged
merged 12 commits into from
Sep 26, 2024
Merged
2 changes: 2 additions & 0 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js';
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
import SpkWormsAlzeyRiedMalade51wor from './banks/spk-worms-alzey-ried-malade51wor.js';
matt-fidd marked this conversation as resolved.
Show resolved Hide resolved
import VirginNrnbgb22 from './banks/virgin_nrnbgb22.js';
import NbgEthngraaxxx from './banks/nbg_ethngraaxxx.js';

Expand Down Expand Up @@ -51,6 +52,7 @@ export const banks = [
SparNordSpNoDK22,
SpkKarlsruhekarsde66,
SpkMarburgBiedenkopfHeladef1mar,
SpkWormsAlzeyRiedMalade51wor,
VirginNrnbgb22,
NbgEthngraaxxx,
];
Expand Down
52 changes: 52 additions & 0 deletions src/app-gocardless/banks/spk-worms-alzey-ried-malade51wor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Fallback from './integration-bank.js';

import { printIban, amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unused imports to improve code cleanliness

The static analysis tool correctly identified that printIban and amountToInteger are imported but not used in this file. To keep the code clean and prevent potential confusion, it's recommended to remove unused imports.

Apply this diff to remove the unused imports:

 import Fallback from './integration-bank.js';

-import { printIban, amountToInteger } from '../utils.js';
 import { formatPayeeName } from '../../util/payee-name.js';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import Fallback from './integration-bank.js';
import { printIban, amountToInteger } from '../utils.js';
import { formatPayeeName } from '../../util/payee-name.js';
import Fallback from './integration-bank.js';
import { formatPayeeName } from '../../util/payee-name.js';
🧰 Tools
GitHub Check: lint

[failure] 3-3:
'printIban' is defined but never used


[failure] 3-3:
'amountToInteger' is defined but never used


/** @type {import('./bank.interface.js').IBank} */
export default {
...Fallback,

institutionIds: ['SPK_WORMS_ALZEY_RIED_MALADE51WOR'],

accessValidForDays: 90,

normalizeAccount(account) {
return {
account_id: account.id,
institution: account.institution,
mask: account.iban.slice(-4),
matt-fidd marked this conversation as resolved.
Show resolved Hide resolved
iban: account.iban,
name: [account.name, printIban(account)].join(' '),
official_name: account.product,
type: 'checking',
};
},

normalizeTransaction(transaction, _booked) {
const date = transaction.bookingDate || transaction.valueDate;
if (!date) {
return null;
}

transaction.remittanceInformationUnstructured =
transaction.remittanceInformationUnstructured ??
transaction.remittanceInformationStructured ??
transaction.remittanceInformationStructuredArray?.join(' ');
matt-fidd marked this conversation as resolved.
Show resolved Hide resolved
return {
...transaction,
payeeName: formatPayeeName(transaction),
date: transaction.bookingDate || transaction.valueDate,
};
},
Comment on lines +13 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Refactor to avoid mutating the transaction object

The normalizeTransaction function is mostly well-implemented, but there's an issue with directly mutating the transaction object. This was correctly identified in a previous review comment. Let's address this to improve the function's immutability.

Apply this diff to refactor the function:

 normalizeTransaction(transaction, _booked) {
   const date = transaction.bookingDate || transaction.valueDate;
   if (!date) {
     return null;
   }

-  transaction.remittanceInformationUnstructured =
-    transaction.remittanceInformationUnstructured ??
-    transaction.remittanceInformationStructured ??
-    transaction.remittanceInformationStructuredArray?.join(' ');
   return {
     ...transaction,
+    remittanceInformationUnstructured:
+      transaction.remittanceInformationUnstructured ??
+      transaction.remittanceInformationStructured ??
+      transaction.remittanceInformationStructuredArray?.join(' '),
     payeeName: formatPayeeName(transaction),
     date: transaction.bookingDate || transaction.valueDate,
   };
 },

This change ensures that we're not modifying the original transaction object, which aligns better with immutability principles and prevents potential side effects.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
normalizeTransaction(transaction, _booked) {
const date = transaction.bookingDate || transaction.valueDate;
if (!date) {
return null;
}
transaction.remittanceInformationUnstructured =
transaction.remittanceInformationUnstructured ??
transaction.remittanceInformationStructured ??
transaction.remittanceInformationStructuredArray?.join(' ');
return {
...transaction,
payeeName: formatPayeeName(transaction),
date: transaction.bookingDate || transaction.valueDate,
};
},
normalizeTransaction(transaction, _booked) {
const date = transaction.bookingDate || transaction.valueDate;
if (!date) {
return null;
}
return {
...transaction,
remittanceInformationUnstructured:
transaction.remittanceInformationUnstructured ??
transaction.remittanceInformationStructured ??
transaction.remittanceInformationStructuredArray?.join(' '),
payeeName: formatPayeeName(transaction),
date: transaction.bookingDate || transaction.valueDate,
};
},


calculateStartingBalance(sortedTransactions = [], balances = []) {
const currentBalance = balances.find(
(balance) => 'interimAvailable' === balance.balanceType,
);

return sortedTransactions.reduce((total, trans) => {
return total - amountToInteger(trans.transactionAmount.amount);
}, amountToInteger(currentBalance.balanceAmount.amount));
},
matt-fidd marked this conversation as resolved.
Show resolved Hide resolved
};
6 changes: 6 additions & 0 deletions upcoming-release-notes/454.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [DirgoSalga]
---

Add integration of Rheinhessen Sparkasse (`SPK_WORMS_ALZEY_RIED_MALADE51WOR`) to the GoCardless app