Step by step guide
Import the library
Include the library as a regular script tag on your page:
<html>
<head>
+ <script src="https://storage.googleapis.com/westudents-public/scripts/verify-sdk.js"></script>
</head>
<body>
...
</body>
</html>
Add content to page
<html>
<head>
<script src="https://storage.googleapis.com/westudents-public/scripts/verify-sdk.js"></script>
</head>
<body>
+ <div>
+ <div>
+ <h2>VERIFY STUDENT IDENTITY</h2>
+ <div>
+ <p id="user">User ID: </p>
+ <p id="result"></p>
+ </div>
+ </div>
+ </div>
</body>
</html>
Initialize the SDK
You can now initialize the SDK, with the apiKey (click here to require one) and an userExternalId. You can also disable Login with WeStudents app and Login with electronic register methods.
<html>
<head>
<script src="https://storage.googleapis.com/westudents-public/scripts/verify-sdk.js"></script>
</head>
<body>
+ <script>
+ function verify() {
+ StudentVerificationSDK.init({
+ apiKey: 'YOUR-API-KEY',
+ userExternalId: 'USER-ID',
+ options: {
+ // optional configs
+ wsLoginEnabled: true,
+ electronicRegisterEnabled: false
+ }
+ })
+ }
+ </script>
<div>
<div>
<h2>VERIFY STUDENT IDENTITY</h2>
<div>
<p id="user">User ID: </p>
<p id="result"></p>
</div>
</div>
+ <button onClick="verify()">Verify</button>
</div>
</body>
</html>
Handling callback
To handle verification response, you have to define onCompleted callback function, it will be execute after verification flow ends and returns:
userId: The user identifier specified or autogenerated.verified: Boolean value for verification status.status: Status of the latest request done.
<html>
<head>
<script src="https://storage.googleapis.com/westudents-public/scripts/verify-sdk.js"></script>
</head>
<body>
<script>
function verify() {
StudentVerificationSDK.init({
apiKey: 'YOUR-API-KEY',
userExternalId: 'USER-ID',
options: {
// optional configs
wsLoginEnabled: true,
electronicRegisterEnabled: false
}
+ onCompleted: ({ userId, verified, status }) => {
+ document.getElementById('user').innerHTML = `User ID: ${userId}`
+ if (verified) {
+ document.getElementById('result').style.color = "green"
+ document.getElementById('result').innerHTML = `VERIFICATO CON SUCCESSO`
+ } else {
+ if (status == 'PENDING') {
+ document.getElementById('result').style.color = "#eb9c00"
+ document.getElementById('result').innerHTML = `VERIFICA IN CORSO`
+ } else if (status == 'REJECTED') {
+ document.getElementById('result').style.color = "red"
+ document.getElementById('result').innerHTML = `VERIFICA FALLITA`
+ }
+ }
+ }
})
}
</script>
<div>
<div>
<h2>VERIFY STUDENT IDENTITY</h2>
<div>
<p id="user">User ID: </p>
<p id="result"></p>
</div>
</div>
<button onClick="verify()">Verify</button>
</div>
</body>
</html>
You can find a complete example on github.