-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·69 lines (59 loc) · 2.76 KB
/
app.py
File metadata and controls
executable file
·69 lines (59 loc) · 2.76 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
62
63
64
65
66
67
68
69
from flask import Flask, render_template, request
from dotenv import load_dotenv
import os
import utils
app = Flask(__name__)
load_dotenv()
"""
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
"""
nova_public_id = os.getenv('nova_public_id')
nova_env = os.getenv('nova_env')
nova_product_id = os.getenv('nova_product_id')
"""
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
"""
@app.route('/')
def application_loan():
"""
Pass our Nova configs to the template so the widget can render
We can also pass a string of data to `user_args` of NovaConnect, and this string will be returned in our webhook
Example user_args: unique identifiers from your system, unique nonces for security
"""
nova_user_args = 'borrow_loan_id_12345'
return render_template('loan_application.html',
nova_public_id = nova_public_id,
nova_env = nova_env,
nova_product_id = nova_product_id,
nova_user_args = nova_user_args)
# Here is a sample internal dashboard, where your loan officer might view applicant profiles
@app.route('/dashboard')
def dashboard():
# Pass the Nova Credit Passport data, if we've received it, to the dashboard view
return render_template('dashboard.html', **utils.received_report_data)
"""
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
"""
@app.route('/nova', methods=['POST'])
def nova():
request_json = request.get_json()
status = request_json['status']
public_token = request_json['publicToken']
user_args = request_json['userArgs']
app.logger.info('Received a callback to our webhook! Navigate your web browser to /dashboard to see the results');
if status == 'SUCCESS':
utils.handle_nova_webhook(public_token, user_args)
else:
"""
Handle unsuccessful statuses here, such as applicant NOT_FOUND and NOT_AUTHENTICATED
For example, you might finalize your loan decision
"""
app.logger.error('Report status %s received for Nova public token %s', status, public_token);
return status