Woodshop
Search…
Display Dwolla transfers
This example shows you how to create a smart collection to list the transfers of your Dwolla account.

1. Define the smart collection

Filterable fields are flagged using isFilterable: true. You will need to enable this option using the collection settings in the Layout Editor.
Transfers have the onlyForRelationships enabled: it means that these 2 collections are only accessible via the Dwolla customer relationships.
1
// forest/dwolla-transfers.js
2
const { collection } = require('forest-express-sequelize');
3
4
collection('dwollaTransfers', {
5
onlyForRelationships: true,
6
isSearchable: true,
7
actions: [],
8
fields: [
9
{
10
field: 'id',
11
type: 'String',
12
isSortable: true,
13
},
14
{
15
field: 'status',
16
type: 'Enum',
17
enums: ['processed', 'pending', 'cancelled', 'failed'],
18
isFilterable: true,
19
},
20
{
21
field: 'amount',
22
type: 'Json',
23
},
24
{
25
field: 'amountReadable',
26
type: 'String',
27
get: (transfer) =>{
28
if (!transfer.amount) return null;
29
var formatter = new Intl.NumberFormat('en-US', {
30
style: 'currency',
31
currency: transfer.amount.currency,
32
// These options are needed to round to whole numbers if that's what you want.
33
//minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
34
//maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
35
});
36
return formatter.format(transfer.amount.value);
37
}
38
},
39
{
40
field: 'metadata',
41
type: 'Json',
42
},
43
{
44
field: 'clearing',
45
type: 'Json',
46
},
47
{
48
field: 'clearing',
49
type: 'Json',
50
},
51
{
52
field: 'achDetails',
53
type: 'Json',
54
},
55
{
56
field: 'correlationId',
57
type: 'String',
58
isFilterable: true,
59
},
60
{
61
field: 'individualAchId',
62
type: 'String',
63
},
64
{
65
field: 'bankName',
66
type: 'String',
67
},
68
{
69
field: 'fingerprint',
70
type: 'String',
71
},
72
{
73
field: 'created', //created_at
74
type: 'Date',
75
},
76
],
77
segments: [],
78
});
79
Copied!

2. Implement the route

This route use the Dwolla service described in another section.
1
// routes/transfers.js
2
const express = require('express');
3
const { PermissionMiddlewareCreator, RecordSerializer } = require('forest-express-sequelize');
4
5
const DwollaService = require('../services/dwolla-service');
6
let dwollaService = new DwollaService(process.env.DWOLLA_APP_KEY, process.env.DWOLLA_APP_SECRET, process.env.DWOLLA_ENVIRONMENT);
7
8
const MODEL_NAME = 'dwollaTransfers';
9
10
const router = express.Router();
11
const permissionMiddlewareCreator = new PermissionMiddlewareCreator(`${MODEL_NAME}`);
12
13
// Get a Transfer
14
router.get(`/${MODEL_NAME}/:recordId`, permissionMiddlewareCreator.details(), (request, response, next) => {
15
const recordId = request.params.recordId;
16
dwollaService.getTransfer(recordId)
17
.then(async record => {
18
const recordSerializer = new RecordSerializer({ name: MODEL_NAME });
19
const recordSerialized = await recordSerializer.serialize(record);
20
response.send(recordSerialized);
21
})
22
.catch(next);
23
24
});
25
26
module.exports = router;
27
Copied!
Last modified 9mo ago