-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroutes.js
More file actions
62 lines (56 loc) · 2.59 KB
/
routes.js
File metadata and controls
62 lines (56 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const express = require('express');
const utils = require('./utils');
const router = express.Router();
/**
* IMPORTANT! Your credentials should NOT be left unencrypted in your production integration
* We recommend placing them in a hidden environment variable / file.
* The variable file here is left unencrypted for demonstration purposes only
*/
const {
novaPublicId,
novaEnv,
novaProductId,
} = process.env;
module.exports = () => {
/**
* Here is a sample loan application that has the NovaConnect widget added.
* NovaConnect is a preconfigured modal pop up that gets attached with a single line of Javascript
* More details: https://www.novacredit.com/quickstart-guide#clientside
*/
router.get('/', (req, res) => {
/**
* Pass our Nova configs to the template so the widget can render
* We can also pass a string of data to `userArgs` of NovaConnect, and this string will be returned in our webhook
* Example userArgs: unique identifiers from your system, unique nonces for security
*/
const novaUserArgs = 'borrow_loan_id_12345';
return res.render('loan_application', { novaPublicId, novaEnv, novaProductId, novaUserArgs });
});
/**
* Here is a sample internal dashboard, where your loan officer might view applicant profiles
*/
router.get('/dashboard', (req, res) => {
// Pass the Nova Credit Passport data, if we've received it, to the dashboard view
return res.render('dashboard', { receivedReportData: utils.retrievePassportData() });
});
/**
* Route to handle Nova callback webhook, which you should specify on the dashboard as "https://your_domain_here.com/nova"
* This route is POST'd to after an applicant completes NovaConnect, and we have updated the status of their NovaCredit Passport
* When running this locally, you'll need a tunnel service like ngrok to expose your localhost: https://ngrok.com/
* See our docs for a list of potential responses: https://docs.neednova.com/#error-codes-amp-responses
*/
return router.post('/nova', (req, res) => {
const { publicToken, status, userArgs } = req.body;
console.log('Received a callback to our webhook! Navigate your web browser to /dashboard to see the results');
res.status(200).send(); // Respond immediately to let Nova know we received the webhook
if (status === 'SUCCESS') {
utils.handleNovaWebhook(publicToken, userArgs, status);
} else {
/**
* Handle unsuccessful statuses here, such as applicant NOT_FOUND and NOT_AUTHENTICATED
* For example, you might finalize your loan decision
*/
console.log(`Report status ${status} received for Nova public token ${publicToken}`);
}
});
};