Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VITE_API_URL=https://demo-api.incodesmile.com/0
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.71.1.js
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.73.1.js
VITE_CONSENT_ID=

# HERE ONLY FOR DEMO PURPOSES, THE APIKEY AND THE FLOW_ID SHOULD NEVER BE IN THE FRONTEND.
VITE_FAKE_BACKEND_APIURL=https://demo-api.incodesmile.com
Expand Down
2 changes: 2 additions & 0 deletions fake_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const fakeBackendStart = async function() {
const url = `${apiurl}/omni/start`;
const params = {
configurationId: flowid,
// language: "pt-BR",
// language: "es-ES",
// language: "en-US",
// redirectionUrl: "https://example.com?custom_parameter=some+value",
// externalCustomerId: "the id of the customer in your system",
Expand Down
70 changes: 39 additions & 31 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,51 @@ import { fakeBackendStart, fakeBackendFinish } from './fake_backend'

let incode;
let incodeSession;
const container = document.getElementById("camera-container");
let showTutorialsFlag=true;
const cameraContainer = document.getElementById("camera-container");

function showError(e=null) {
container.innerHTML = "<h1>There was an error</h1>";
console.log(e.message)
const finishContainer = document.getElementById("finish-container");
if (e?.message) {
finishContainer.innerHTML = `<h1>Error: ${e.message}</h1>`;
} else {
finishContainer.innerHTML = "<h1>There was an error</h1>";
console.log(e);
}
}

function saveDeviceData() {
incode.sendGeolocation({ token: incodeSession.token });
incode.sendFingerprint({ token: incodeSession.token });
captureIdFrontSide();
getCombinedConsent();
}

function getCombinedConsent() {
const consentId = import.meta.env.VITE_CONSENT_ID;
incode.renderCombinedConsent(cameraContainer, {
onSuccess: captureIdFrontSide,
token: incodeSession,
consentId: consentId
});
}

function captureIdFrontSide() {
incode.renderCamera("front", container, {
incode.renderCamera("front", cameraContainer, {
onSuccess: captureIdBackSide,
onError: showError,
token: incodeSession,
numberOfTries: 3,
showTutorial: true
showTutorial: showTutorialsFlag
});
}

function captureIdBackSide(response) {
incode.renderCamera("back", container, {
incode.renderCamera("back", cameraContainer, {
onSuccess: processId,
onError: showError,
token: incodeSession,
numberOfTries: 3,
showTutorial: true
showTutorial: showTutorialsFlag
});
}

Expand All @@ -44,52 +59,45 @@ async function processId() {
}

function captureSelfie() {
incode.renderCamera("selfie", container, {
incode.renderCamera("selfie", cameraContainer, {
onSuccess: finishOnboarding,
onError: showError,
token: incodeSession,
numberOfTries: 3,
showTutorial: true
showTutorial: showTutorialsFlag
});
}

function finishOnboarding() {
// Finishing the session works along with the configuration in the flow
// webhooks and business rules are ran here.
fakeBackendFinish(incodeSession.token)
.then((response) => {
console.log(response);
const container = document.getElementById("finish-container");
container.innerHTML = "<h1>Onboarding Finished.</h1>";
})
.catch((error) => {
showError(error);
});
.then((response) => {
console.log(response);
const container = document.getElementById("finish-container");
container.innerHTML = "<h1>Onboarding Finished.</h1>";
})
.catch((e) => {
showError(e);
});
}

async function app() {
try {
const apiURL = import.meta.env.VITE_API_URL;
incode = window.OnBoarding.create({
apiURL: apiURL
apiURL: apiURL,
lang: "en"
});

// Create the single session
container.innerHTML = "<h1>Creating session...</h1>";
try {
incodeSession = await fakeBackendStart();
} catch(e) {
showError(e);
return;
}

cameraContainer.innerHTML = "<h1>Creating session...</h1>";
incodeSession = await fakeBackendStart();
// Empty the container and start the flow
container.innerHTML = "";
cameraContainer.innerHTML = "";
saveDeviceData();
} catch (e) {
console.dir(e);
container.innerHTML = "<h1>Something Went Wrong</h1>";
throw e;
showError(e);
}
}

Expand Down