Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 4441caa

Browse files
committed
update instructions on GoCardless handlers
1 parent 232b2ff commit 4441caa

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/app-gocardless/README.md

+34-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ If the default bank integration does not work for you, you can integrate a new b
1010

1111
This will trigger the process of fetching the data from the bank and will log the data in the backend. Use this data to fill the logic of the bank class.
1212

13-
4. Create new a bank class based on `app-gocardless/banks/sandboxfinance-sfin0000.js`.
13+
4. Create new a bank class based on an existing example in `app-gocardless/banks`.
1414

15-
Name of the file and class should be created based on the ID of the integrated institution, found in step 1.
15+
Name of the file and class should follow the existing patterns and be created based on the ID of the integrated institution, found in step 1.
1616

1717
5. Fill the logic of `normalizeAccount`, `normalizeTransaction`, `sortTransactions`, and `calculateStartingBalance` functions.
1818
You do not need to fill every function, only those which are necessary for the integration to work.
@@ -69,7 +69,7 @@ If the default bank integration does not work for you, you can integrate a new b
6969
- `sortTransactions` function:
7070
7171
```log
72-
Available (first 10) transactions properties for new integration of institution in sortTransactions function
72+
Available (first 10) transactions properties for new integration of institution in sortTransactions function
7373
{
7474
top10SortedTransactions: '[
7575
{
@@ -162,3 +162,34 @@ If the default bank integration does not work for you, you can integrate a new b
162162
6. Add new bank integration to `BankFactory` class in file `actual-server/app-gocardless/bank-factory.js`
163163
164164
7. Remember to add tests for new bank integration in
165+
166+
## normalizeTransaction
167+
This is the most commonly used override as it allows you to change the data that is returned to the client.
168+
169+
Please follow the following patterns when implementing a custom normalizeTransaction method:
170+
1. If you need to edit the values of transaction fields (excluding the transaction amount) do not mutate the original transaction object. Instead, create a shallow copy and make your changes there.
171+
2. End the function by returning the result of calling the fallback normalizeTransaction method from integration-bank.js
172+
173+
E.g.
174+
```js
175+
import Fallback from './integration-bank.js';
176+
177+
export default {
178+
...
179+
180+
normalizeTransaction(transaction, booked) {
181+
// create a shallow copy of the transaction object
182+
const editedTrans = { ...transaction };
183+
184+
// make any changes required to the copy
185+
editedTrans.remittanceInformationUnstructured = transaction.remittanceInformationStructured;
186+
187+
// call the fallback method, passing in your edited transaction as the 3rd parameter
188+
// this will calculate the date, payee name and notes fields based on your changes
189+
// but leave the original fields available for mapping in the UI
190+
return Fallback.normalizeTransaction(transaction, booked, editedTrans);
191+
}
192+
193+
...
194+
}
195+
```

0 commit comments

Comments
 (0)