HTML + Javascript
Steps to integrate the Web SDK into HTML and JavaScript vanilla application.
.png?alt=media&token=737a5f8d-a2b8-4a9e-93dc-8b6a9aed2649)
To install the Preventor Web SDK, add the following to your project’s:
- 1.Add
pvt-button
tag in your HTML.
<pvt-button></pvt-button>
2. Add
https://unpkg.com/@preventor/button
as a script.<script type="module" src="https://unpkg.com/@preventor/button"></script>
3. A complete
HTML
file should look similar to the example below.<!DOCTYPE html>
<html lang="en">
<body>
<pvt-button></pvt-button>
<script type="module" src="https://unpkg.com/@preventor/button"></script>
</body>
</html>
You have successfully installed the Preventor Web SDK!
To initialize the SDK, you must provide the configuration in the "initialize" method, this method is available after the "loaded" event.
See the coding example below:
const pvtButton = document.querySelector('pvt-button');
pvtButton.addEventListener('loaded', () => {
pvtButton.initialize(YOUR_CONFIGURATION);
});
You have successfully initialize the Preventor SDK!
The flow type defines the biometric process so you must select a flow type.
const pvtButton = document.querySelector('pvt-button');
pvtButton.addEventListener('loaded', () => {
const config = {
// 1. SET THE FLOW TYPE
flowType: 'YOUR_FLOW_TYPE'
};
pvtButton.initialize(config);
});
You must assign the flow type code. If it is blank, it will take the flow type by default.
You must set all credentials values to correctly consume our services.
const pvtButton = document.querySelector('pvt-button');
pvtButton.addEventListener('loaded', () => {
const config = {
flowType: 'YOUR_FLOW_TYPE',
// 2. SET THE CREDENTIALS
credentials: {
apiKey: 'YOUR_API_KEY',
clientSecret: 'YOUR_CLIENT_SECRET',
tenant: 'YOUR_TENANT',
banknu: 'YOUR_BANKNU',
env: 'YOUR_ENV'
}
};
pvtButton.initialize(config);
});
The Cifcode is the unique customer profile code.
If the Cifcode is empty, a unique code is assigned.
const pvtButton = document.querySelector('pvt-button');
pvtButton.addEventListener('loaded', () => {
const config = {
flowType: 'YOUR_FLOW_TYPE',
credentials: {
apiKey: 'YOUR_API_KEY',
clientSecret: 'YOUR_CLIENT_SECRET',
tenant: 'YOUR_TENANT',
banknu: 'YOUR_BANKNU',
env: 'YOUR_ENV'
},
// 3. SET THE CIF CODE
currentUserInfo: {
cifCode: 'YOUR_CIFCODE'
},
};
pvtButton.initialize(config);
});
The deskVerificationEnabled set the "Let's get your verified" page as a first step.
const pvtButton = document.querySelector('pvt-button');
pvtButton.addEventListener('loaded', () => {
const config = {
flowType: 'YOUR_FLOW_TYPE',
credentials: {
apiKey: 'YOUR_API_KEY',
clientSecret: 'YOUR_CLIENT_SECRET',
tenant: 'YOUR_TENANT',
banknu: 'YOUR_BANKNU',
env: 'YOUR_ENV'
},
currentUserInfo: {
cifCode: 'YOUR_CIFCODE'
},
// 4. SET DESK VERIFICATION ENABLED
deskVerificationEnabled: false
};
pvtButton.initialize(config);
});
It is an object that allows you to pass some callbacks to handle events of Preventor SDK.
const pvtButton = document.querySelector('pvt-button');
pvtButton.addEventListener('loaded', () => {
const config = {
flowType: 'YOUR_FLOW_TYPE',
credentials: {
apiKey: 'YOUR_API_KEY',
clientSecret: 'YOUR_CLIENT_SECRET',
tenant: 'YOUR_TENANT',
banknu: 'YOUR_BANKNU',
env: 'YOUR_ENV'
},
currentUserInfo: {
cifCode: 'YOUR_CIFCODE'
},
deskVerificationEnabled: false,
// 5. SET EVENTS LISTENER
events: {
onStart: () => console.log('onStart'),
onSubmitted: () => console.log('onSubmitted'),
onFinish: () => console.log('onFinish'),
onError: code => console.log('onError', code),
}
};
pvtButton.initialize(config);
});
To find out if a user has completed the verification process, canceled it or there was an error. To do this, you can implement the following callback methods:
Method | Description |
---|---|
onStart | This callback method is triggered once a user starts the verification flow. |
onSubmitted | Method that is being called once verification data is submitted to Preventor. |
onFinish | Method that is being called once a user clicks the "Finish" button. |
onError | This callback method fires when a user canceled the verification flow, the verification ended with an error, or the user performed an incorrect process. You can use this to find out the reason for the error. Error codes: CANCELLED_BY_USER BIOMETRIC_AUTHENTICATION_FAILED BAD_STEP_BY_USER MISSING_PARAMETERS |
Last modified 1yr ago