Skip to content

Add JT2 and JT4 Endpoints on Flutter #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d2698c6
added smart selfie models
jumaallan May 14, 2024
811bc49
setting up android JT4 setup
jumaallan May 14, 2024
bff1f47
added jt4 endpoints on android
jumaallan May 14, 2024
b44c09c
updated pigeon shared code
jumaallan May 23, 2024
32a8ef9
added android platform code
jumaallan May 23, 2024
8235df0
updated dart platform interface
jumaallan May 23, 2024
2970ad1
iOS platform interface setup
jumaallan May 23, 2024
91c920b
Merge branch 'main' into feat/add-jt4-endpoints
jumaallan May 24, 2024
9372528
Update Mapper.swift
jumaallan May 24, 2024
ecc182e
updated ios platform code
jumaallan May 24, 2024
6c8b7d6
Update SmileIDPlugin.kt
jumaallan May 24, 2024
2e142a9
pass image path on JT4 jobs
jumaallan May 29, 2024
024fe17
Merge branch 'main' into feat/add-jt4-endpoints
jumaallan May 29, 2024
2eca24b
Merge branch 'main' into feat/add-jt4-endpoints
jumaallan Jun 4, 2024
f87f054
updated pigeon and ktlint
jumaallan Jun 4, 2024
bc96a2a
revert back ktlint update
jumaallan Jun 4, 2024
50aa40f
cleanup unused import
jumaallan Jun 4, 2024
a5af30b
lint android code
jumaallan Jun 4, 2024
47309e7
updated CHANGELOG.md
jumaallan Jun 6, 2024
35ba131
Merge branch 'main' into feat/add-jt4-endpoints
jumaallan Jun 11, 2024
023f9e0
updated import ordering
jumaallan Jun 11, 2024
1cabbc1
updated ktlint
jumaallan Jun 11, 2024
fc45b8f
updated ktlint
jumaallan Jun 11, 2024
95530b6
fixed ktlint warnings
jumaallan Jun 11, 2024
978a013
test ktlint fix
jumaallan Jun 11, 2024
cd63334
updated ktlint config
jumaallan Jun 11, 2024
079bef4
bump up ktlint version
jumaallan Jun 11, 2024
88c5741
revert back ktlint version
jumaallan Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
max_line_length=100

[{*.kt,*.kts}]
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
ij_kotlin_allow_trailing_comma_on_call_site=true
ij_kotlin_allow_trailing_comma=true
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Document verification
* Enhanced document verification
* Added an Offline Mode, enabled by calling `SmileID.setAllowOfflineMode(true)`. If a job is attempted while the device is offline, and offline mode has been enabled, the UI will complete successfully and the job can be submitted at a later time by calling `SmileID.submitJob(jobId)`
* Improved SmartSelfie Enrollment and Authentication times by moving to a synchronous API endpoint

## 10.0.12

Expand Down
37 changes: 37 additions & 0 deletions android/src/main/kotlin/com/smileidentity/flutter/Mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import FlutterImageLinks
import FlutterImageType
import FlutterJobStatusRequest
import FlutterJobType
import FlutterJobTypeV2
import FlutterPartnerParams
import FlutterPrepUploadRequest
import FlutterPrepUploadResponse
Expand All @@ -35,6 +36,8 @@ import FlutterProductsConfigResponse
import FlutterServicesResponse
import FlutterSmartSelfieJobResult
import FlutterSmartSelfieJobStatusResponse
import FlutterSmartSelfieResponse
import FlutterSmartSelfieStatus
import FlutterSuspectUser
import FlutterUploadImageInfo
import FlutterUploadRequest
Expand Down Expand Up @@ -81,7 +84,10 @@ import com.smileidentity.models.UploadImageInfo
import com.smileidentity.models.UploadRequest
import com.smileidentity.models.ValidDocument
import com.smileidentity.models.ValidDocumentsResponse
import com.smileidentity.models.v2.SmartSelfieResponse
import com.smileidentity.models.v2.SmartSelfieStatus
import java.io.File
import com.smileidentity.models.v2.JobType as JobTypeV2

/**
* Pigeon does not allow non nullable types in this example here
Expand Down Expand Up @@ -122,6 +128,17 @@ fun JobType.toResponse() = when (this) {
else -> TODO("Not yet implemented")
}

fun FlutterJobTypeV2.toRequest() = when (this) {
FlutterJobTypeV2.SMARTSELFIEAUTHENTICATION -> JobTypeV2.SmartSelfieAuthentication
FlutterJobTypeV2.SMARTSELFIEENROLLMENT -> JobTypeV2.SmartSelfieEnrollment
}

fun JobTypeV2.toResponse() = when (this) {
JobTypeV2.SmartSelfieAuthentication -> FlutterJobTypeV2.SMARTSELFIEAUTHENTICATION
JobTypeV2.SmartSelfieEnrollment -> FlutterJobTypeV2.SMARTSELFIEENROLLMENT
else -> TODO("Not yet implemented")
}

fun FlutterAuthenticationRequest.toRequest() = AuthenticationRequest(
jobType = jobType.toRequest(),
country = country,
Expand Down Expand Up @@ -330,6 +347,26 @@ fun SmartSelfieJobResult.toResponse(): Any = when (this) {
)
}

fun SmartSelfieStatus.toResponse() = when (this) {
SmartSelfieStatus.Approved -> FlutterSmartSelfieStatus.APPROVED
SmartSelfieStatus.Pending -> FlutterSmartSelfieStatus.PENDING
SmartSelfieStatus.Rejected -> FlutterSmartSelfieStatus.REJECTED
SmartSelfieStatus.Unknown -> FlutterSmartSelfieStatus.UNKNOWN
}

fun SmartSelfieResponse.toResponse() = FlutterSmartSelfieResponse(
code = code,
createdAt = createdAt,
jobId = jobId,
jobType = jobType.toResponse(),
message = message,
partnerId = partnerId,
partnerParams = convertNonNullMapToNullable(partnerParams),
status = status.toResponse(),
updatedAt = updatedAt,
userId = userId,
)

fun DocumentVerificationJobStatusResponse.toResponse() =
FlutterDocumentVerificationJobStatusResponse(
timestamp = timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import FlutterProductsConfigRequest
import FlutterProductsConfigResponse
import FlutterServicesResponse
import FlutterSmartSelfieJobStatusResponse
import FlutterSmartSelfieResponse
import FlutterUploadRequest
import FlutterValidDocumentsResponse
import SmileIDApi
import android.app.Activity
import android.content.Context
import com.smileidentity.SmileID
import com.smileidentity.SmileIDOptIn
import com.smileidentity.networking.asFormDataPart
import com.smileidentity.networking.pollBiometricKycJobStatus
import com.smileidentity.networking.pollDocumentVerificationJobStatus
import com.smileidentity.networking.pollEnhancedDocumentVerificationJobStatus
Expand All @@ -36,6 +39,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.single
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import java.net.URL
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
Expand Down Expand Up @@ -162,6 +166,74 @@ class SmileIDPlugin : FlutterPlugin, SmileIDApi, ActivityAware {
callback = callback,
)

@OptIn(SmileIDOptIn::class)
override fun doSmartSelfieEnrollment(
signature: String,
timestamp: String,
selfieImage: String,
livenessImages: List<String>,
userId: String,
partnerParams: Map<String?, String?>?,
callbackUrl: String?,
sandboxResult: Long?,
allowNewEnroll: Boolean?,
callback: (Result<FlutterSmartSelfieResponse>) -> Unit,
) = launch(
work = {
SmileID.api.doSmartSelfieEnrollment(
userId = userId,
selfieImage = File(selfieImage).asFormDataPart(
partName = "selfie_image",
mediaType = "image/jpeg",
),
livenessImages = livenessImages.map {
File(selfieImage).asFormDataPart(
partName = "liveness_images",
mediaType = "image/jpeg",
)
},
partnerParams = convertNullableMapToNonNull(partnerParams),
callbackUrl = callbackUrl,
sandboxResult = sandboxResult?.toInt(),
allowNewEnroll = allowNewEnroll,
).toResponse()
},
callback = callback,
)

@OptIn(SmileIDOptIn::class)
override fun doSmartSelfieAuthentication(
signature: String,
timestamp: String,
selfieImage: String,
livenessImages: List<String>,
userId: String,
partnerParams: Map<String?, String?>?,
callbackUrl: String?,
sandboxResult: Long?,
callback: (Result<FlutterSmartSelfieResponse>) -> Unit,
) = launch(
work = {
SmileID.api.doSmartSelfieAuthentication(
userId = userId,
selfieImage = File(selfieImage).asFormDataPart(
partName = "selfie_image",
mediaType = "image/jpeg",
),
livenessImages = livenessImages.map {
File(selfieImage).asFormDataPart(
partName = "liveness_images",
mediaType = "image/jpeg",
)
},
partnerParams = convertNullableMapToNonNull(partnerParams),
callbackUrl = callbackUrl,
sandboxResult = sandboxResult?.toInt(),
).toResponse()
},
callback = callback,
)

override fun getDocumentVerificationJobStatus(
request: FlutterJobStatusRequest,
callback: (Result<FlutterDocumentVerificationJobStatusResponse>) -> Unit,
Expand Down
Loading