Skip to content

Commit 0a5aac1

Browse files
author
Sylvio Menubarbe
committed
feat(ais-connect) Add country field in ais-froms
1 parent 8e8ffd8 commit 0a5aac1

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

ais-connect.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dotenv.config({ path: path.join(__dirname, '.env') });
1212

1313
require('dotenv').config();
1414

15+
1516
// Create the fintecture client instance
1617
let client = new FintectureClient({ app_id: process.env.APP_ID, app_secret: process.env.APP_SECRET, private_key: process.env.APP_PRIV_KEY, env: process.env.FINTECTURE_ENV });
1718

@@ -22,29 +23,35 @@ let customerId;
2223

2324
// initial screen
2425
app.get("/", async (_req, res) => {
25-
res.render("index", {});
26+
res.render('index', {
27+
country: 'fr'
28+
});
2629
});
2730

2831

2932
// Redirect to connect
30-
app.get("/connect", async (req, res) => {
33+
app.get("/connect", async (req, res, next) => {
3134
const psuType = req.query.psu_type || 'all';
3235
const country = req.query.country || 'fr';
3336

34-
let config = {
37+
const config = {
3538
redirect_uri: process.env.APP_REDIRECT_URI,
3639
state: "bob",
3740
psu_type: psuType,
3841
country: country
39-
}
40-
41-
const connect = await client.getAisConnect(null, config)
42+
};
4243

43-
res.writeHead(
44-
301,
45-
{ Location: connect.url }
46-
);
47-
res.end();
44+
try {
45+
const connect = await client.getAisConnect(null, config);
46+
47+
res.writeHead(
48+
301,
49+
{ Location: connect.url }
50+
);
51+
res.end();
52+
} catch(err) {
53+
next(err);
54+
}
4855
});
4956

5057
app.get("/error_page", async (req, res) => {

views/ais-connect/index.ejs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
<html>
22
<body>
33
<form name="form1" method="GET" action="/connect">
4+
<div class="form-group">
5+
<label for="country">Country</label>
6+
<input type="text" name="country" value="<%= country %>">
7+
</div>
48
<input type="hidden" name="psu_type" value="all" />
59
<button type="submit">Connect ALL</button>
610
</form>
711
<form name="form1" method="GET" action="/connect">
12+
<div class="form-group">
13+
<label for="country">Country</label>
14+
<input type="text" name="country" value="<%= country %>">
15+
</div>
816
<input type="hidden" name="psu_type" value="retail" />
917
<button type="submit">Connect RETAIL</button>
1018
</form>
1119
<form name="form1" method="GET" action="/connect">
20+
<div class="form-group">
21+
<label for="country">Country</label>
22+
<input type="text" name="country" value="<%= country %>">
23+
</div>
1224
<input type="hidden" name="psu_type" value="corporate" />
1325
<button type="submit">Connect CORPO</button>
1426
</form>

0 commit comments

Comments
 (0)