Skip to content

Commit

Permalink
Updated Android Veriff SDK to 3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Nov 7, 2020
1 parent c522826 commit 8dc60bb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 100 deletions.
162 changes: 65 additions & 97 deletions src/android/VeriffCordovaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,121 +4,89 @@

import android.content.Intent;
import android.util.Log;

import androidx.annotation.Nullable;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONException;
import org.json.JSONArray;
import org.json.JSONObject;

// Veriff imports
import mobi.lab.veriff.data.Veriff;
import mobi.lab.veriff.data.VeriffConstants;

import com.veriff.VeriffResult;
import com.veriff.VeriffSdk;

public class VeriffCordovaPlugin extends CordovaPlugin {
public class VeriffCordovaPlugin extends CordovaPlugin {

// Actions
private static final String LAUNCH_ACTION = "launchVeriffSDK";
// Actions
private static final String LAUNCH_ACTION = "launchVeriffSDK";

private static final int REQUEST_CODE = 800;
private static final String SESSION_URL = "https://alchemy.veriff.com";
private static CallbackContext callbackContextApp;

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
this.callbackContextApp = callbackContext;
if(action.equals(LAUNCH_ACTION)){
if(args.isNull(0)){
this.callbackContextApp.error("Error: Session token is required");
return false;
}
String sessionToken = args.getString(0);
this.launchVeriffSDK(sessionToken);
return true;
}
private static final int REQUEST_CODE = 800;
private static CallbackContext callbackContextApp;

this.callbackContextApp.error("Method not implemented");
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
this.callbackContextApp = callbackContext;
if (action.equals(LAUNCH_ACTION)) {
if (args.isNull(0)) {
this.callbackContextApp.error("Error: Session token is required");
return false;
}
String sessionUrl = args.getString(0);
this.launchVeriffSDK(sessionUrl);
return true;
}

private void launchVeriffSDK(String sessionToken){
cordova.setActivityResultCallback(this);
Veriff.Builder veriffSDK = new Veriff.Builder(SESSION_URL, sessionToken);
veriffSDK.launch(cordova.getActivity(),REQUEST_CODE);
}
this.callbackContextApp.error("Method not implemented");
return false;
}

private void launchVeriffSDK(String sessionUrl) {
cordova.setActivityResultCallback(this);
Intent intent = VeriffSdk.createLaunchIntent(cordova.getActivity(), sessionUrl);
cordova.startActivityForResult(this, intent, REQUEST_CODE);
}

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_CODE && data != null) {
int statusCode = data.getIntExtra(VeriffConstants.INTENT_EXTRA_STATUS, Integer.MIN_VALUE);
String sessionToken = data.getStringExtra(VeriffConstants.INTENT_EXTRA_SESSION_URL);
this.handleResult(statusCode, sessionToken); //see below to know how to handle result
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_CODE && data != null) {
VeriffResult result = VeriffResult.fromResultIntent(data);
if (result != null) {
try {
handleResult(result);
} catch (JSONException e) {
this.callbackContextApp.error(e.getStackTrace().toString());
}
super.onActivityResult(requestCode, resultCode, data);
}
}
super.onActivityResult(requestCode, resultCode, data);
}

public void handleResult(int statusCode, String sessionToken){
String text = "VeriffSDK Result: ";
switch(statusCode) {
case VeriffConstants.STATUS_USER_FINISHED:
// User finished the session, there might be other callbacks coming after this one. (for example if the images are still being uploaded in the background)
text += "User finished the session";
break;
case VeriffConstants.STATUS_ERROR_NO_IDENTIFICATION_METHODS_AVAILABLE:
// No identifications methods available
text += "No identifications methods available";
break;
case VeriffConstants.STATUS_ERROR_SETUP:
// Issue with the provided vendor data
text += "Issue with the provided vendor data";
break;
case VeriffConstants.STATUS_ERROR_UNKNOWN:
// Unknown error occurred.
text += "Unknown error occurred";
break;
case VeriffConstants.STATUS_ERROR_NETWORK:
// Network is unavailable.
text += "Network is unavailable";
break;
case VeriffConstants.STATUS_USER_CANCELED:
// User cancelled the session.
text += "User cancelled the session";
break;
case VeriffConstants.STATUS_UNABLE_TO_ACCESS_CAMERA:
// Failed to access device's camera. (either access denied or there are no usable cameras)
text += "Failed to access device's camera";
break;
case VeriffConstants.STATUS_UNABLE_TO_START_CAMERA:
// Failed to start the device's camera.
text += "Failed to start the device's camera";
break;
case VeriffConstants.STATUS_UNABLE_TO_RECORD_AUDIO:
// Failed to access device's microphone.
text += "Failed to access device's microphone";
break;
case VeriffConstants.STATUS_SUBMITTED:
// Photos are successfully uploaded.
text += "Photos are successfully uploaded";
break;
case VeriffConstants.STATUS_ERROR_SESSION:
// Invalid sessionToken is passed to the Veriff SDK.
text += "Invalid sessionToken is passed to the Veriff SDK";
break;
case VeriffConstants.STATUS_DONE:
// Session is completed from clients perspective.
text += "Session is completed from clients perspective";
break;
case VeriffConstants.STATUS_ERROR_UNSUPPORTED_SDK_VERSION:
// This version of Veriff SDK is deprecated.
text = "This version of Veriff SDK is deprecated";
break;
default:
text = "Unknown result state";
break;
}
Log.d("Handle VeriffSDK result", text);
this.callbackContextApp.success(text);
public void handleResult(VeriffResult result) throws JSONException {
JSONObject resultJson = new JSONObject();
VeriffResult.Status status = result.getStatus();
resultJson.put("status", status.toString());
Log.d("Handle VeriffSDK result", status.toString());
switch (status) {
case CANCELED:
// User canceled the session.
resultJson.put("message", "User canceled the verification process");
break;
case ERROR:
// An error occurred during the flow, Veriff has already shown UI, no need to display
// a separate error message here
resultJson.put("message", result.getError());
break;
case DONE:
// Session is completed from clients perspective.
resultJson.put("message", "Session is completed from clients perspective");
break;
default:
resultJson.put("message", "Unknown result state");
break;
}
this.callbackContextApp.success(resultJson);
}

}
}
2 changes: 1 addition & 1 deletion src/android/build-extras.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allprojects {
}

dependencies {
implementation 'com.veriff:veriff-library:2.10.0'
implementation 'com.veriff:veriff-library:3.6.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'

Expand Down
4 changes: 2 additions & 2 deletions www/VeriffCordovaPlugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line import/no-unresolved
const exec = require('cordova/exec');

const TOKEN_ERROR = 'Session token is required';
const URL_ERROR = 'Session URL is required';

const PLUGIN_NAME = 'VeriffCordovaPlugin';

Expand All @@ -22,7 +22,7 @@ function start(sessionToken) {
[sessionToken],
);
} else {
reject(new Error(TOKEN_ERROR));
reject(new Error(URL_ERROR));
}
});
}
Expand Down

0 comments on commit 8dc60bb

Please sign in to comment.