Using UniApp IDWise SDK
Overview
The IDWise Uni Plugin is a native plugin for uni-app that integrates the IDWise SDK, providing identity verification and document scanning capabilities for iOS applications. The plugin supports automatic journey mode for seamless identity verification workflows.
Usage
Step 1: Import the Plugin
In your Vue page or component, load the native plugin in the onLoad lifecycle hook:
export default {
data() {
return {
IDWise: null,
sdkInitialized: false,
journeyId: ''
};
},
onLoad() {
// Load the native plugin
this.IDWise = uni.requireNativePlugin('idwise-uni-plugin');
}
}Step 2: Initialize the SDK
Before starting a journey, initialize the SDK with your client key:
The IDWise plugin supports three theme modes:
system_default- Automatically adapts to system themelight- Light themedark- Dark theme
methods: {
initializeSDK() {
const initOptions = {
clientKey: 'YOUR_CLIENT_KEY',
theme: 'system_default' // or 'light' or 'dark'
};
this.IDWise.initialize(initOptions, (result) => {
if (result.success) {
this.sdkInitialized = true;
console.log('SDK initialized successfully');
} else {
console.error('SDK initialization failed:', result.error);
// Handle error
const errorMessage = result.error?.message || 'Initialization failed';
uni.showToast({
title: errorMessage,
icon: 'error'
});
}
});
}
}Step 3: Start a Journey
After successful initialization, start a verification journey:
methods: {
startVerification() {
const journeyOptions = {
flowId: 'YOUR_FLOW_ID',
referenceNumber: 'OPTIONAL_REFERENCE_NUMBER', // Optional
locale: 'en', // Optional, defaults to 'en'
applicantDetails: { // Optional
firstName: 'John',
lastName: 'Doe'
}
};
this.IDWise.startJourney(journeyOptions, (journeyResult) => {
this.handleJourneyEvent(journeyResult);
});
},
handleJourneyEvent(event) {
switch (event.event) {
case 'onJourneyStarted':
this.journeyId = event.data.journeyId;
console.log('Journey started:', this.journeyId);
uni.showToast({
title: 'Journey Started',
icon: 'success'
});
break;
case 'onJourneyCompleted':
console.log('Journey completed:', event.data);
const isSuccessful = event.data.isSuccessful;
uni.showToast({
title: isSuccessful ? 'Verification Successful' : 'Verification Failed',
icon: isSuccessful ? 'success' : 'error'
});
break;
case 'onJourneyCancelled':
console.log('Journey cancelled:', event.data);
const reason = event.data.cancellationReason;
uni.showToast({
title: 'Journey Cancelled',
icon: 'none'
});
break;
case 'onJourneyBlocked':
console.log('Journey blocked:', event.data);
uni.showToast({
title: 'Journey Blocked',
icon: 'error'
});
break;
case 'onError':
console.error('Journey error:', event.data);
const errorMsg = event.data.message || 'An error occurred';
uni.showToast({
title: errorMsg,
icon: 'error'
});
break;
}
}
}Step 4: Resume a Journey (Optional)
If you need to resume a previously started journey:
You need to initialize IDWise SDK before resuming a journey
methods: {
resumeVerification() {
if (!this.journeyId) {
uni.showToast({
title: 'No journey to resume',
icon: 'none'
});
return;
}
const resumeOptions = {
flowId: 'YOUR_FLOW_ID',
journeyId: this.journeyId,
locale: 'en' // Optional
};
this.IDWise.resumeJourney(resumeOptions, (journeyResult) => {
if (journeyResult.event === 'onJourneyResumed') {
console.log('Journey resumed successfully');
uni.showToast({
title: 'Journey Resumed',
icon: 'success'
});
}
this.handleJourneyEvent(journeyResult);
});
}
}Step 5: Check Device Blocked Status
You can check if the device is blocked from verification:
methods: {
checkDeviceStatus() {
const isBlocked = this.IDWise.isDeviceBlocked();
console.log('Device blocked status:', isBlocked);
uni.showToast({
title: isBlocked ? 'Device is Blocked' : 'Device is Active',
icon: isBlocked ? 'none' : 'success'
});
return isBlocked;
}
}API Reference
Methods
initialize(options, callback)
initialize(options, callback)Initializes the IDWise SDK.
Parameters:
options(Object)clientKey(String, required): Your IDWise client keytheme(String, optional): Theme mode -'system_default','light', or'dark'. Default:'system_default'
Callback Response:
{
success: true/false,
error: {
code: "ERROR_CODE",
message: "Error message",
requestId: "request_id"
}
}startJourney(options, callback)
startJourney(options, callback)Starts a new verification journey.
Parameters:
options(Object)flowId(String, required): Your flow ID from IDWise dashboardreferenceNumber(String, optional): Custom reference number for trackinglocale(String, optional): Locale code (e.g., 'en', 'ar'). Default:'en'applicantDetails(Object, optional): Additional applicant informationfirstName(String, optional)lastName(String, optional)- Any other key-value pairs
Callback Events: See Events and Callbacks
resumeJourney(options, callback)
resumeJourney(options, callback)Resumes an existing journey.
Parameters:
options(Object)flowId(String, required): Your flow IDjourneyId(String, required): Journey ID fromonJourneyStartedeventlocale(String, optional): Locale code. Default:'en'
Callback Events: See Events and Callbacks
isDeviceBlocked()
isDeviceBlocked()Checks if the current device is blocked.
Returns: Boolean
true: Device is blockedfalse: Device is not blocked
Events and Callbacks
Journey Events
onJourneyStarted
onJourneyStartedFired when a journey starts successfully.
{
event: 'onJourneyStarted',
data: {
journeyId: 'journey_123456'
}
}onJourneyResumed
onJourneyResumedFired when a journey is resumed successfully.
{
event: 'onJourneyResumed',
data: {
journeyId: 'journey_123456'
}
}onJourneyCompleted
onJourneyCompletedFired when a journey completes (successfully or with failure).
{
event: 'onJourneyCompleted',
data: {
journeyId: 'journey_123456',
isSuccessful: true/false
}
}onJourneyCancelled
onJourneyCancelledFired when a journey is cancelled.
{
event: 'onJourneyCancelled',
data: {
journeyId: 'journey_123456',
cancellationReason: 'user_cancelled' // or 'token_expired'
}
}onJourneyBlocked
onJourneyBlockedFired when a journey is blocked due to security or compliance reasons.
{
event: 'onJourneyBlocked',
data: {
journeyId: 'journey_123456',
blockedTransaction: {
canRetry: true/false,
blockReasonMessage: 'Reason for blocking',
allBlockReasons: [
{ blockReasonCode: 'CODE_1' },
{ blockReasonCode: 'CODE_2' }
]
}
}
}onError
onErrorFired when an error occurs during the journey.
{
event: 'onError',
data: {
code: 'ERROR_CODE',
message: 'Error message',
requestId: 'request_id'
}
}Sample Code
You can find an example code for using IDWise SDK inside uni-app.
IDWise UniApp Sample
Updated about 9 hours ago
