-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·356 lines (292 loc) · 11.5 KB
/
app.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
$(function() {
// Current language
var language = $('html').attr('lang');
// Start state
var currStep = 'START';
// Default document title
var pageTitle = 'FinTech';
// Default page title and subtitle
var currStepText = '';
var currStepSubText = '';
// Progressbar from 0 to 100
var progress = 25;
// Dynamic page elements
var $languageSwitcher = $('[data-elm="languageSwitcher"]');
var $startCta = $('[data-elm="startCta"]');
var $iframeWrapper = $('[data-elm="iframe"]');
var $iframe = $('iframe', $iframeWrapper);
var $successWrapper = $('[data-elm="success"]');
var $loginId = $('[data-elm="loginId"]');
var $intro = $('[data-elm="intro"]');
var $step = $('[data-elm="step"]');
var $stepTitle = $('[data-elm="stepTitle"]');
var $stepSubTitle = $('[data-elm="stepSubTitle"]');
var $progressBar = $('[data-elm="progressBar"]');
var $progressBarSteps = $('[data-elm="progressBarSteps"]');
var $bankNotFound = $('[data-elm="bankNotFound"]');
function initApp() {
// Remove iFrame header
// Need to add an option in FC
// customizeIframe();
// Bind to click
handleClickEvents();
// Bind to iFrame events
handleIframeEvents();
// Bind to language switcher events
handleLanguageEvents();
// Init state
handleState({step: currStep});
};
function handleState(state) {
currStep = state.step;
// Debugg
// console.log('Current step: ', state);
// if (currStep == 'START') {
// // Stuff
// }
// Hide bank not found message
if (!$iframeWrapper.hasClass('d-none')) {
$bankNotFound.addClass('d-none');
}
if (currStep == 'COMPONENT_LOAD_INSTITUTION_SELECTOR') {
// Update step text
currStepText = i18n[language].institutionSelector;
currStepSubText = i18n[language].subInstitutionSelector;
// Hide language switcher since changing the language will refresh the iFrame and loose the flow
$languageSwitcher.removeClass('d-none');
// Update the progressbar
progress = 33;
$progressBarSteps.find('li').removeClass('active');
$progressBarSteps.find('li:nth-child(1)').addClass('active');
// Show bank not found message
if (!$iframeWrapper.hasClass('d-none')) {
$bankNotFound.removeClass('d-none');
}
}
if (currStep == 'INSTITUTION_SELECTED') {
// Show the steps title and progressbar
$step.removeClass('d-none');
// Hide the intro texts
$intro.addClass('d-none');
}
if (currStep == 'COMPONENT_LOAD_CREDENTIAL') {
// Update step text
currStepText = i18n[language].credential;
currStepSubText = i18n[language].subCredential;
// Hide language switcher since changing the language will refresh the iFrame and loose the flow
$languageSwitcher.addClass('d-none');
// Update the progressbar
progress = 50;
$progressBarSteps.find('li').removeClass('active');
$progressBarSteps.find('li:nth-child(2)').addClass('active');
}
if (currStep == 'SUBMIT_CREDENTIAL') {
// Update step text
currStepText = i18n[language].loading;
currStepSubText = i18n[language].subLoading;
// Update the progressbar
progress = 60;
}
if (currStep == 'COMPONENT_LOAD_MFA') {
// Update step text
currStepText = i18n[language].mfa;
currStepSubText = i18n[language].subMfa;
// Update the progressbar
progress = 70;
}
if (currStep == 'SUBMIT_MFA') {
// Update step text
currStepText = i18n[language].loading;
currStepSubText = i18n[language].subLoading;
// Update the progressbar
progress = 80;
}
if (currStep == 'COMPONENT_LOAD_ACCOUNT_SELECTION') {
console.log(currStep);
// Update step text
currStepText = i18n[language].accountSelector;
currStepSubText = i18n[language].subAccountSelector;
// Update the progressbar
progress = 90;
$progressBarSteps.find('li').removeClass('active');
$progressBarSteps.find('li:nth-child(3)').addClass('active');
}
if (currStep == 'ACCOUNT_SELECTED') {
// Update step text
currStepText = i18n[language].accountSelected;
currStepSubText = i18n[language].subAccountSelected;
}
if (currStep == 'REDIRECT') {
// Update step text
currStepText = i18n[language].success;
currStepSubText = i18n[language].subSuccess;
// Hide the iFrame
$iframeWrapper.addClass('d-none');
// Show the success layout
$successWrapper.removeClass('d-none');
// Display the loginId
if (window.location.href.indexOf('&showLoginId=true')) {
$loginId.text('Login ID = ' +getParameterByName('loginId', state.url));
}
console.log('loginId', getParameterByName('loginId', state.url));
// Hide the steps title and progressbar
$step.addClass('d-none');
// Update the progressbar
progress = 100;
}
// Update the document title so it matches the current iFrame step
$(document).prop('title', pageTitle + ' - ' + currStepText);
// Update the page title and subtitle
$stepTitle.text(currStepText);
$stepSubTitle.text(currStepSubText);
// Update the progressbar
$progressBar.find('.progress-bar').css({ width: progress + '%' });
}
function handleClickEvents() {
$startCta.on('click', function(event) {
// Prevent default behavior
event.preventDefault();
// Hide start button
$(this).addClass('d-none');
// Show iFrame
$iframeWrapper.removeClass('d-none');
// Show the no bank text
$bankNotFound.removeClass('d-none');
// Show the steps title and progressbar
$step.removeClass('d-none');
// Hide the intro texts
$intro.addClass('d-none');
});
}
function handleIframeEvents() {
// Listen to events comming from flinks's iFrame
window.addEventListener('message', function(e) {
// Make sure the event comes from us ex.: https://fintech-iframe.private.fin.ag/
if (1 /* CHANGE ME BEFORE GOING TO PROD */) { //~event.origin.indexOf('https://fintech-iframe.private.fin.ag/')
if (e.data.step) {
// Customize the app based on the iFrame state
handleState(e.data);
}
}
});
}
// Handle language switcher
function handleLanguageEvents() {
// Bootstrap dropdown event
// $languageSwitcher.on('show.bs.dropdown', function(event) {
// });
$('[data-i18n="otherLang"]').on('click', function(event) {
// Set the new language on the html tag
var newLanguage = $(this).text().toLowerCase();
$('html').attr('lang', newLanguage);
// Update the current language
language = newLanguage;
// Translate all texts with the targeted language
translateTexts(newLanguage);
// Get the current iFrame src
var newUrl = $iframe.attr('src');
// Update iFrame src language parameter
// This forces the iFrame to reload.
// The iFrame state won't be saved
$iframe.attr('src', updateQueryStringParameter(newUrl, 'language', newLanguage));
});
};
// Translate all texts
function translateTexts(newLanguage) {
// Loop through all translatable texts
$.each($('[data-i18n]'), function(index, elm) {
// Get the key
var key = $(elm).attr('data-i18n');
// Get the text associated with that key
var newText = i18n[newLanguage][key];
// Set the new translated text to the element
$(elm).text(newText);
});
}
// Helper function
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
} else {
return uri + separator + key + "=" + value;
}
}
// Helper function
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
// English and french texts
var i18n = {
en: {
title: "FinTech",
subtitle: "Service driven commerce",
subsubtitle: "Real-Time Bank Account Validation",
text: "FinTech' Real-Time Bank Account Validation solution allows you to securely validate your bank account, in real-time. Click to get started.",
startCta: "Start",
lang: "EN",
otherLang: "FR",
institutionSelector: "Step 1: Bank selection",
subInstitutionSelector: "Please select your bank",
credential: "Step 2: Bank login",
subCredential: "Please accept the terms and enter your bank account credentials",
loading: "Loading",
subLoading: "We are processing your request",
mfa: "Step 2: Bank security",
subMfa: "Please answer the security questions",
accountSelector: "Step 3: Account selection",
subAccountSelector: "Please select the account you want to validate",
accountSelected: "The account has been linked successfully",
subAccountSelected: "Thank you",
success: "You have successfully validated your bank account",
subSuccess: "Your FinTech representative will contact you shortly. Thank you for choosing FinTech",
secure: "Real-Time Bank Account Validation",
subSecure: "For Merchant Services From FinTech",
progressStep1: "1. Select your bank",
progressStep2: "2. Login",
progressStep3: "3. Select account",
bankNotFound: "If you don't see your bank listed please contact your FinTech representative"
},
fr: {
title: "FinTech",
subtitle: "Service axé sur le commerce",
subsubtitle: "Validation bancaire instantannée",
text: "La solution de validation de compte bancaire en temps réel de FinTech vous permet de valider votre compte bancaire en toute sécurité, en temps réel. Cliquez pour commencer.",
startCta: "Débuter",
lang: "FR",
otherLang: "EN",
institutionSelector: "Étape 1 - Selection d'une banque",
subInstitutionSelector: "Veuillez choisir votre banque",
credential: "Étape 2 - Authentification",
subCredential: "Veuillez accépter les termes et saisir votre identifiant de compte bancaire",
loading: "Chargement",
subLoading: "Nous traitons votre demande",
mfa: "Étape 2 - Sécurité",
subMfa: "S'il vous plaît répondre aux questions de sécurité",
accountSelector: "Étape 3 - Veuillez choisir un compte",
subAccountSelector: "Veuillez sélectionner le compte que vous souhaitez valider",
accountSelected: "Le compte à bien été associé",
subAccountSelected: "Merci",
success: "Vous avez validé votre compte bancaire avec succès",
subSuccess: "Votre représentant FinTech vous contactera sous peu. Merci d'avoir choisi FinTech",
secure: "Validation de compte bancaire en temps réel",
subSecure: "Pour les services marchands de FinTech",
progressStep1: "1. Choisir une banque",
progressStep2: "2. Authentification",
progressStep3: "3. Choisir un compte",
bankNotFound: "Si votre banque ne figure pas dans la liste, veuillez contacter votre représentant FinTech."
}
};
// Start the app
initApp();
});