Skip to content

Commit

Permalink
Sample App v5 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-socure committed Oct 18, 2024
1 parent b4410d1 commit a59e01f
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 34 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Predictive DocV Android SDK v4
# Predictive DocV Android SDK v5

Learn how to integrate the Predictive Document Verification (DocV) Android SDK into your Android application.

Expand All @@ -8,10 +8,11 @@ Before getting started, check that your development environment meets the follow

- Android SDK Version 22 (OS Version 5.1) and later

The DocV Android SDK v4 is compiled with:
The DocV Android SDK v5 is compiled with:

- `compileSdkVersion 33`
- Java 11
- `compileSdkVersion 34`
- Java 17
- Kotlin 1.8.10

> Note: Auto Capture feature requires Android SDK Version 28 (OS Version 9.0) and later with at least 3 GB of RAM. If the device does not meet these requirements, only the manual capture feature will be available.
Expand Down
27 changes: 17 additions & 10 deletions sample-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ plugins {
}

android {
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.socure.docv.sdk.sample"
minSdk 22
targetSdk 33
targetSdk 34
versionCode 11
versionName "4.3.0"
versionName "5.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
Expand All @@ -38,10 +39,16 @@ dependencies {
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

def sdk_version = "4.3.1"
def sdk_version = "5.0.0"
implementation "com.socure.android:docv-capture:$sdk_version"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
def retrofit_version = "2.9.0"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

def lifecycle_version = "2.5.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"

def okhttp_version = "4.9.3"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
}
69 changes: 69 additions & 0 deletions sample-app/app/src/main/java/com/socure/docv/sdk/sample/Api.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.socure.docv.sdk.sample

import java.util.concurrent.TimeUnit
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.Body
import retrofit2.http.HeaderMap
import retrofit2.http.POST

private const val BASE_URL = "https://service.socure.com/"

fun transaction(): TransactionService {
return Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(OkHttpBuilder().getBuilder())
.build().create(TransactionService::class.java)
}

interface TransactionService {
@POST("api/5.0/documents/request")
suspend fun createTransaction(
@HeaderMap headers: Map<String, String>,
@Body request: TransactionRequest
): TransactionResponse
}

data class TransactionResponse(
val data: Data
) {

data class Data(
val eventId: String,
val authToken: String,
val docvTransactionToken: String,
val qrcode: String,
val url: String
)
}

data class TransactionRequest(
val config: TransactionConfig,
val previousReferenceId: String? = null
) {

data class TransactionConfig(
val useCaseKey: String,
val language: String = "en"
)
}

class OkHttpBuilder {
fun getBuilder(): OkHttpClient {
with(OkHttpClient.Builder()) {
readTimeout(120L, TimeUnit.SECONDS)
connectTimeout(120L, TimeUnit.SECONDS)
writeTimeout(120L, TimeUnit.SECONDS)

if (BuildConfig.DEBUG) {
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = HttpLoggingInterceptor.Level.HEADERS
addInterceptor(loggingInterceptor)
}
return build()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,39 @@ import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.startActivity
import androidx.lifecycle.lifecycleScope
import com.google.android.material.snackbar.Snackbar
import com.socure.docv.capturesdk.api.SocureDocVHelper
import com.socure.docv.capturesdk.api.SocureDocVContext
import com.socure.docv.capturesdk.api.SocureDocVError
import com.socure.docv.capturesdk.api.SocureSdk
import com.socure.docv.capturesdk.common.utils.ResultListener
import com.socure.docv.capturesdk.common.utils.ScanError
import com.socure.docv.capturesdk.common.utils.ScannedData
import com.socure.docv.capturesdk.common.utils.SocureDocVFailure
import com.socure.docv.capturesdk.common.utils.SocureDocVSuccess
import com.socure.docv.capturesdk.common.utils.SocureResult
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.Body
import retrofit2.http.HeaderMap
import retrofit2.http.POST

private const val TAG = "MainActivity"
private const val ID_PLUS_KEY = "YOUR_ID_PLUS_KEY"
private const val PUBLIC_KEY = "YOUR_PUBLIC_KEY"

class MainActivity : AppCompatActivity() {

Expand All @@ -36,35 +58,72 @@ class MainActivity : AppCompatActivity() {

// initiate Socure SDK
private fun launchSocureSdk() {
startForResult.launch(
SocureDocVHelper.getIntent(this, "YOUR_SOCURE_API_KEY", null)
)
lifecycleScope.launch(Dispatchers.IO) {
runCatching {
transaction()
.createTransaction(
createHeaderMap(),
TransactionRequest(
config = TransactionRequest.TransactionConfig(
useCaseKey = "socure_default"
),
)
)
}.onSuccess {
startForResult.launch(
SocureSdk.getIntent(
this@MainActivity,
SocureDocVContext(
it.data.docvTransactionToken,
PUBLIC_KEY,
false
)
)
)
}.onFailure {
withContext(Dispatchers.Main) {
Toast.makeText(
this@MainActivity,
"Failed to get transaction token",
Toast.LENGTH_SHORT
).show()
}
}
}
}

// handle response from Socure SDK
private var startForResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
result.data?.let {
SocureDocVHelper.getResult(it, object : ResultListener {
override fun onSuccess(scannedData: ScannedData) {
SocureSdk.getResult(it) { result ->
Log.d(TAG, "onResult called: $result")
if (result is SocureDocVSuccess) {
Toast.makeText(
this@MainActivity,
"Success -> Session ID: ${scannedData.sessionId}",
Toast.LENGTH_LONG
"onSuccess called: ${result.sessionToken}",
Toast.LENGTH_SHORT
).show()
}

override fun onError(scanError: ScanError) {
} else {
val error = result as? SocureDocVFailure
Toast.makeText(
this@MainActivity,
"Failure: ${scanError.statusCode} -> ${scanError.errorMessage}",
Toast.LENGTH_LONG
"onError called: ${error?.sessionToken}, ${error?.error}",
Toast.LENGTH_SHORT
).show()
}
})
}
}
}

private fun createHeaderMap(): Map<String, String> {
val headerMap = mutableMapOf<String, String>()
headerMap["Authorization"] = "SocureApiKey".plus(" ")
.plus(ID_PLUS_KEY)
headerMap["content-type"] = "application/json"
return headerMap
}

// is camera permission granted
private fun isCameraPermissionGranted() = ContextCompat.checkSelfPermission(
this,
Expand Down Expand Up @@ -94,5 +153,4 @@ class MainActivity : AppCompatActivity() {
.show()
}
}

}
}
4 changes: 2 additions & 2 deletions sample-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

task clean(type: Delete) {
delete rootProject.buildDir
}
}

0 comments on commit a59e01f

Please sign in to comment.