Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhar-socure authored Dec 29, 2022
1 parent 5d2537d commit 84d5cfc
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Predictive DocV SDK v2 for React Native

# Version: 2.2.0 - Release Date : Dec 2022
# Version: 2.3.0 - Release Date : Dec 2022

The Predictive Document Verification (DocV) SDK v2 for React Native is a React Native bridge that allows you to use the DocV SDK for Android and iOS in your React Native application. This guide covers the integration within React, as well as React Native implementation on iOS and Android.

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ repositories {
}

dependencies {
api 'com.github.socure-inc:android-sdk:2.2.2'
api 'com.github.socure-inc:android-sdk:2.3.0'
api 'com.facebook.react:react-native:0.68.+'
api 'com.facebook.infer.annotation:infer-annotation:0.11.2'
api 'javax.inject:javax.inject:1'
Expand Down
43 changes: 43 additions & 0 deletions android/src/main/java/com/rnsocuresdk/ConsentModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.rnsocuresdk

import android.content.Intent
import android.util.Log
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.WritableMap
import com.rnsocuresdk.scanner.GET_CONSENT_CODE
import com.rnsocuresdk.scanner.ScannerModule
import com.socure.idplus.scanner.consent.ConsentActivity
import com.socure.idplus.util.KEY_MESSAGE
import com.socure.idplus.util.KEY_SESSION_ID
import com.socure.idplus.util.KEY_SESSION_TOKEN

class ConsentModule(private val context: ReactApplicationContext): ScannerModule(context) {

override val scanRequestCode: Int
get() = GET_CONSENT_CODE

override fun buildScannerIntent(): Intent = Intent(context, ConsentActivity::class.java)

override fun getNormalImageResponse(promise: Promise) {
promise.reject(Throwable("Not implemented"))
}

override fun onSuccess(requestCode: Int, data: Intent?) {
Log.d("[SOCURE]", "onSuccess")

val consentResponse: WritableMap = Arguments.createMap()
consentResponse.putString("type", "CONSENT")
consentResponse.putString("message", data?.getStringExtra(KEY_MESSAGE))
consentResponse.putString("sessionId", data?.getStringExtra(KEY_SESSION_ID))
consentResponse.putString("sessionToken", data?.getStringExtra(KEY_SESSION_TOKEN))

Log.d("[SOCURE]", consentResponse.toString())
promise?.resolve(consentResponse)
}

override fun onError(requestCode: Int, message: String) {
promise?.reject(Throwable(message))
}
}
8 changes: 7 additions & 1 deletion android/src/main/java/com/rnsocuresdk/RnSocureSdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import com.rnsocuresdk.scanner.LicenseScannerModule
import com.rnsocuresdk.scanner.PassportScannerModule
import com.rnsocuresdk.scanner.SelfieScannerModule
import com.socure.idplus.SDKAppDataPublic
import com.socure.idplus.util.Constants

@ExperimentalStdlibApi
class RnSocureSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
private val licenseModule: LicenseScannerModule = LicenseScannerModule(reactContext)
private val passportModule: PassportScannerModule = PassportScannerModule(reactContext)
private val selfieModule: SelfieScannerModule = SelfieScannerModule(reactContext)
private val uploadDocument: InformationUploadModule = InformationUploadModule(reactContext)
private val consentModule: ConsentModule = ConsentModule(reactContext)

override fun getName(): String {
return "RnSocureSdk"
Expand Down Expand Up @@ -55,6 +55,12 @@ class RnSocureSdkModule(reactContext: ReactApplicationContext) : ReactContextBas
fun setSocureSdkKey(publicKey: String) {
SDKAppDataPublic.setSocureSdkKey(publicKey)
}

@ReactMethod
fun showConsent(promise: Promise) {
consentModule.startScanner(promise, currentActivity)
}

/*
@ReactMethod
fun uploadSelfie(selfiePath: String, documentType: Int, promise: Promise) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.facebook.react.bridge.WritableMap
import com.socure.idplus.SDKAppDataPublic
import com.socure.idplus.model.BarcodeData
import com.socure.idplus.model.MrzData
import com.socure.idplus.util.KEY_SESSION_ID
import com.socure.idplus.util.KEY_SESSION_TOKEN

import com.socure.idplus.scanner.license.LicenseScannerActivity
import java.lang.Exception
Expand All @@ -23,7 +25,8 @@ class LicenseScannerModule(private val context: ReactApplicationContext): Scanne

override fun buildScannerIntent(): Intent = Intent(context, LicenseScannerActivity::class.java)

override fun onSuccess(requestCode: Int) {
override fun onSuccess(requestCode: Int, data: Intent?) {
Log.d("[SOCURE]", "onSuccess")
val licenseResult = SDKAppDataPublic.successfulScanningResult
val response: WritableMap = Arguments.createMap()
val mapper = LicenseResultMapper()
Expand All @@ -41,6 +44,11 @@ class LicenseScannerModule(private val context: ReactApplicationContext): Scanne
}

response.putString("type", licenseResult?.documentType?.name ?: "UNKWON")

response.putString("sessionId", data?.getStringExtra(KEY_SESSION_ID))
response.putString("sessionToken", data?.getStringExtra(KEY_SESSION_TOKEN))

Log.d("[SOCURE]", response.toString())
promise?.resolve(response)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.socure.idplus.model.BarcodeData
import com.socure.idplus.model.MrzData
import com.socure.idplus.scanner.passport.PassportScannerActivity
import java.lang.Exception
import com.socure.idplus.util.KEY_SESSION_ID
import com.socure.idplus.util.KEY_SESSION_TOKEN

@ExperimentalStdlibApi
class PassportScannerModule(private val context: ReactApplicationContext): ScannerModule(context) {
Expand All @@ -21,7 +23,8 @@ class PassportScannerModule(private val context: ReactApplicationContext): Scann

override fun buildScannerIntent(): Intent = Intent(context, PassportScannerActivity::class.java)

override fun onSuccess(requestCode: Int) {
override fun onSuccess(requestCode: Int, data: Intent?) {
Log.d("[SOCURE]", "onSuccess")
val passportResult = SDKAppDataPublic.successfulScanningResult
val response: WritableMap = Arguments.createMap()
val mapper = PassportResultMapper()
Expand All @@ -40,6 +43,10 @@ class PassportScannerModule(private val context: ReactApplicationContext): Scann

response.putString("type", passportResult?.documentType?.name ?: "UNKWON")

response.putString("sessionId", data?.getStringExtra(KEY_SESSION_ID))
response.putString("sessionToken", data?.getStringExtra(KEY_SESSION_TOKEN))

Log.d("[SOCURE]", response.toString())
promise?.resolve(response)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import com.facebook.react.bridge.ReactApplicationContext
const val SCAN_PASSPORT_CODE = 200
const val SCAN_LICENSE_CODE = 300
const val SCAN_SELFIE_CODE = 400
const val GET_CONSENT_CODE = 500

interface ScanModuleResult {

fun onSuccess(requestCode: Int)
fun onSuccess(requestCode: Int, data: Intent?)
fun onError(requestCode: Int, message: String)
}

Expand Down Expand Up @@ -59,7 +60,7 @@ abstract class ScannerModule(private val context: ReactApplicationContext): Base
data?.getStringExtra("error")?.let {
onError(requestCode, it)
} ?: run {
onSuccess(requestCode)
onSuccess(requestCode, data)
}
}
Activity.RESULT_CANCELED -> onError(requestCode, "DOC_SCAN_CANCELLED")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.WritableMap
import com.socure.idplus.SDKAppDataPublic
import com.socure.idplus.scanner.selfie.SelfieActivity
import com.socure.idplus.util.KEY_SESSION_ID
import com.socure.idplus.util.KEY_SESSION_TOKEN

class SelfieScannerModule(private val context: ReactApplicationContext): ScannerModule(context) {

Expand All @@ -17,14 +19,17 @@ class SelfieScannerModule(private val context: ReactApplicationContext): Scanner

override fun buildScannerIntent(): Intent = Intent(context, SelfieActivity::class.java)

override fun onSuccess(requestCode: Int) {
override fun onSuccess(requestCode: Int, data: Intent?) {
Log.d("[SOCURE]", "onSuccess")
val selfieResult = SDKAppDataPublic.selfieScanResult
val selfieResponse: WritableMap = Arguments.createMap()

selfieResponse.putString("type", "SELFIE")
selfieResponse.putString("image", Base64.encodeToString(selfieResult?.imageData, Base64.DEFAULT) ?: "")

selfieResponse.putString("sessionId", data?.getStringExtra(KEY_SESSION_ID))
selfieResponse.putString("sessionToken", data?.getStringExtra(KEY_SESSION_TOKEN))

Log.d("[SOCURE]", selfieResponse.toString())
promise?.resolve(selfieResponse)
}
Expand Down
1 change: 1 addition & 0 deletions ios/RnSocureSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ @interface RCT_EXTERN_MODULE(RnSocureSdk, NSObject)
RCT_EXTERN_METHOD(captureSelfie: (RCTPromiseResolveBlock *)resolve rejecter: (RCTPromiseRejectBlock *)reject)
RCT_EXTERN_METHOD(scanLicense: (RCTPromiseResolveBlock *)resolve rejecter: (RCTPromiseRejectBlock *)reject)
RCT_EXTERN_METHOD(scanPassport: (RCTPromiseResolveBlock *)resolve rejecter: (RCTPromiseRejectBlock *)reject)
RCT_EXTERN_METHOD(showConsent: (RCTPromiseResolveBlock *)resolve rejecter: (RCTPromiseRejectBlock *)reject)
RCT_EXTERN_METHOD(
uploadLicenseAndSelfie: (NSString)selfieUrl
front: (NSString)front
Expand Down
50 changes: 47 additions & 3 deletions ios/RnSocureSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ class RnSocureSdk: NSObject, RCTBridgeModule {

var docScanResolve: RCTPromiseResolveBlock?
var docScanReject: RCTPromiseRejectBlock?
var consentResolve: RCTPromiseResolveBlock?
var consentReject: RCTPromiseRejectBlock?

var usingPassport:Bool = false
var scanType:DocumentType = .license
var referenceViewController: UIViewController?

var scanInfoResult: [String:Any] = [:]

let keySessionId = "sessionId"
let keySessionToken = "sessionToken"

static func moduleName() -> String! {
return "RnSocureSdk"
Expand Down Expand Up @@ -120,7 +125,22 @@ class RnSocureSdk: NSObject, RCTBridgeModule {

self.scanDocument(type: .passport, resolve: resolve, reject: reject)
}


@objc(showConsent:rejecter:)
func showConsent(
_ resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock
) {
self.consentResolve = resolve
self.consentReject = reject
DispatchQueue.main.async {
let vc = ConsentHelperViewController(ConsentCallback: self)
vc.modalPresentationStyle = .fullScreen
self.referenceViewController = vc
let root = RCTPresentedViewController()
root?.present(vc, animated: true, completion: nil)
}
}

func scanDocument(
type: DocumentType,
Expand Down Expand Up @@ -262,7 +282,9 @@ class RnSocureSdk: NSObject, RCTBridgeModule {
resolve([
"frontImage": frontImageData.base64EncodedString(options: .lineLength64Characters),
"backImage": backImageData.base64EncodedString(options: .lineLength64Characters),
"type": "normal_license_image"
"type": "normal_license_image",
keySessionId: licenseFrontResult?.sessionId ?? "",
keySessionToken: licenseFrontResult?.sessionToken ?? ""
])
} else {
reject("IMAGE_NOT_FOUND", "Error getting image data", nil)
Expand All @@ -282,7 +304,9 @@ class RnSocureSdk: NSObject, RCTBridgeModule {
if let passportData = self.dataFromUrl(url: passportUrl) {
resolve([
"frontImage": passportData.base64EncodedString(options: .lineLength64Characters),
"type": "normal_passport_image"
"type": "normal_passport_image",
keySessionId: licenseFrontResult?.sessionId ?? "",
keySessionToken: licenseFrontResult?.sessionToken ?? ""
])
} else {
reject("IMAGE_NOT_FOUND", "Error getting image data", nil)
Expand Down Expand Up @@ -394,10 +418,13 @@ extension RnSocureSdk:ImageCallback {
self.referenceViewController = nil
self.docScanReject?("DOC_SCAN_CANCELLED", "DOC_SCAN_CANCELLED", nil)
self.selfieCaptureReject?("SELFIE_SCAN_CANCELLED", "SELFIE_SCAN_CANCELLED", nil)
self.consentReject?("CONSENT_CANCELLED", "CONSENT_CANCELLED", nil)
self.docScanReject = nil
self.docScanResolve = nil
self.selfieCaptureReject = nil
self.selfieCaptureResolve = nil
self.consentResolve = nil
self.consentReject = nil
})
}

Expand Down Expand Up @@ -443,6 +470,23 @@ extension RnSocureSdk:ImageCallback {
func onError(errorType: SocureSDKErrorType, errorMessage: String) {
self.docScanReject?("DOC_SCAN_ERROR", errorMessage, nil)
self.selfieCaptureReject?("SELFIE_SCAN_ERROR", errorMessage, nil)
self.consentReject?("CONSENT_ERROR", errorMessage, nil)
self.referenceViewController?.dismiss(animated: true, completion: nil)
}
}

extension RnSocureSdk: ConsentCallback {
func consentResult(consentResult: SocureSdk.ConsentResult) {
let dict: [String: String] = [keySessionId: consentResult.sessionId, "message": consentResult.message, keySessionToken: consentResult.sessionToken]
consentResolve?(dict)
consentReject = nil
if consentResult.message.lowercased() == "consent already given" {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { [ refVC = self.referenceViewController] in
refVC?.dismiss(animated: true)
})
self.referenceViewController = nil
return
}
referenceViewController?.dismiss(animated: true, completion: nil)
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rn-socure-sdk",
"version": "2.2.2",
"version": "2.3.0",
"description": "Access Socure scanners",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const Socure = {
captureSelfie: () => {
return RnSocureSdk.captureSelfie();
},
showConsent: () => {
return RnSocureSdk.showConsent();
},
uploadScannedInfo: () => {
return RnSocureSdk.uploadScannedInfo();
},
Expand Down

0 comments on commit 84d5cfc

Please sign in to comment.