Skip to main content

Initialization

info

The SDK requires initialization with your client ID and configuration options before use.

Basic implementation

await VeryfiLens.init("YOUR_CLIENT_ID", {
lensFlavor: "document", // Type of document to scan
docValidation: true, // Enable document validation
blurModal: true, // Show blur detection modal
isDocumentModal: true, // Show document detection modal
torchButton: true, // Show torch/flash toggle button
exitButton: true, // Show exit button
});
info

You can find more information about configuration options in the Configuration section.

Flavor specific implementation

    await VeryfiLens.init("YOUR_CLIENT_ID", {
lensFlavor: "document",
blurModal: true,
isDocumentModal: true,
exitButton: true,
});

Event Handlers

Set up event handlers to manage the document processing workflow:

// Success handler - called when document is successfully processed
VeryfiLens.onSuccess((result) => {
console.log("Document processed successfully:", result);
});

// Failure handler - called when an error occurs
VeryfiLens.onFailure((error) => {
console.error("Processing failed:", error);
});

// Update handler - called for status updates during processing
VeryfiLens.onUpdate((status) => {
console.log("Processing status:", status.status);
});

Starting the Camera

Start the document scanning process with the showCamera method:

// Basic camera start
VeryfiLens.showCamera();
// With image setter callback
VeryfiLens.showCamera((image) => {
console.log("Captured image:", image);
// image is base64 encoded
});

Example Implementation

import VeryfiLens from 'veryfi-lens-wasm';

async function startDocumentScanning() {
try {
// Initialize SDK
await VeryfiLens.init("YOUR_CLIENT_ID", {
lensFlavor: "document",
blurModal: true,
isDocumentModal: true,
torchButton: true,
exitButton: true,
onCloseRedirectUrl: "/", // Optional: URL to redirect after closing
onClose: () => {
console.log("Scanner closed");
},
submitHandler: (image) => {
console.log("Document submitted:", image);
}
});

// Set up event handlers
VeryfiLens.onSuccess((result) => {
console.log("Success:", result);
});

VeryfiLens.onFailure((error) => {
console.error("Error:", error);
});

VeryfiLens.onUpdate((status) => {
console.log("Status update:", status);
});

// Start camera with image handler
VeryfiLens.showCamera((image) => {
console.log("Image captured");
// Handle the captured image
});

} catch (error) {
console.error("Failed to initialize Veryfi Lens:", error);
}
}