Woodshop
Search…
Display Dwolla funding sources
This example shows you how to create a smart collection to list the funding sources 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.
Funding Sources have the onlyForRelationships enabled: it means that these 2 collections are only accessible via the Dwolla customer relationships.
1
// forest/dwolla-funding-sources.js
2
const { collection } = require('forest-express-sequelize');
3
4
collection('dwollaFundingSources', {
5
onlyForRelationships: true,
6
actions: [],
7
fields: [
8
{
9
field: 'id',
10
type: 'String',
11
},
12
{
13
field: 'status',
14
type: 'Enum',
15
enums: ['unverified', 'verified']
16
},
17
{
18
field: 'type',
19
type: 'Enum',
20
enums: ['bank', 'balance']
21
},
22
{
23
field: 'bankAccountType',
24
type: 'Enum',
25
enums: ['checking', 'savings', 'general-ledger', 'loan']
26
},
27
{
28
field: 'name',
29
type: 'String',
30
},
31
{
32
field: 'balance',
33
type: 'Json',
34
},
35
{
36
field: 'balanceReadable',
37
type: 'String',
38
get: (fundingSource) =>{
39
if (!fundingSource.balance) return null;
40
var formatter = new Intl.NumberFormat('en-US', {
41
style: 'currency',
42
currency: fundingSource.balance.currency,
43
});
44
return formatter.format(fundingSource.balance.value);
45
}
46
},
47
{
48
field: 'removed',
49
type: 'Boolean',
50
},
51
{
52
field: 'channels',
53
type: ['String'],
54
},
55
{
56
field: 'bankName',
57
type: 'String',
58
},
59
{
60
field: 'fingerprint',
61
type: 'String',
62
},
63
{
64
field: 'created', //created_at
65
type: 'Date',
66
},
67
],
68
segments: [],
69
});
Copied!

2. Implement the route

This route use the Dwolla service described in another section.
1
// routes/funding-sources.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 = 'dwollaFundingSources';
9
10
const router = express.Router();
11
const permissionMiddlewareCreator = new PermissionMiddlewareCreator(`${MODEL_NAME}`);
12
13
// Get a FundingSource
14
router.get(`/${MODEL_NAME}/:recordId`, permissionMiddlewareCreator.details(), (request, response, next) => {
15
const recordId = request.params.recordId;
16
dwollaService.getFundingSource(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;
Copied!
Last modified 9mo ago