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 18 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
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
@@ -1,6 +1,6 @@
package com.smileidentity.flutter

import FlutterActionResult

Check failure on line 3 in android/src/main/kotlin/com/smileidentity/flutter/Mapper.kt

View workflow job for this annotation

GitHub Actions / Android

Imports must be ordered in lexicographic order without any empty lines in-between with "java", "javax", "kotlin" and aliases in the end
import FlutterActions
import FlutterAntifraud
import FlutterAuthenticationRequest
Expand All @@ -27,6 +27,7 @@
import FlutterImageType
import FlutterJobStatusRequest
import FlutterJobType
import FlutterJobTypeV2
import FlutterPartnerParams
import FlutterPrepUploadRequest
import FlutterPrepUploadResponse
Expand All @@ -35,6 +36,8 @@
import FlutterServicesResponse
import FlutterSmartSelfieJobResult
import FlutterSmartSelfieJobStatusResponse
import FlutterSmartSelfieResponse
import FlutterSmartSelfieStatus
import FlutterSuspectUser
import FlutterUploadImageInfo
import FlutterUploadRequest
Expand Down Expand Up @@ -81,6 +84,9 @@
import com.smileidentity.models.UploadRequest
import com.smileidentity.models.ValidDocument
import com.smileidentity.models.ValidDocumentsResponse
import com.smileidentity.models.v2.JobType as JobTypeV2
import com.smileidentity.models.v2.SmartSelfieResponse
import com.smileidentity.models.v2.SmartSelfieStatus
import java.io.File

/**
Expand Down Expand Up @@ -122,6 +128,17 @@
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 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
@@ -1,6 +1,6 @@
package com.smileidentity.flutter

import android.content.Context

Check failure on line 3 in android/src/main/kotlin/com/smileidentity/flutter/SmileIDDocumentVerification.kt

View workflow job for this annotation

GitHub Actions / Android

Imports must be ordered in lexicographic order without any empty lines in-between with "java", "javax", "kotlin" and aliases in the end
import androidx.compose.runtime.Composable
import com.smileidentity.SmileID
import com.smileidentity.compose.DocumentVerification
Expand All @@ -11,8 +11,8 @@
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory
import kotlinx.collections.immutable.toImmutableMap
import java.io.File
import kotlinx.collections.immutable.toImmutableMap

internal class SmileIDDocumentVerification private constructor(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.smileidentity.flutter

import FlutterAuthenticationRequest

Check failure on line 3 in android/src/main/kotlin/com/smileidentity/flutter/SmileIDPlugin.kt

View workflow job for this annotation

GitHub Actions / Android

Imports must be ordered in lexicographic order without any empty lines in-between with "java", "javax", "kotlin" and aliases in the end
import FlutterAuthenticationResponse
import FlutterBiometricKycJobStatusResponse
import FlutterDocumentVerificationJobStatusResponse
Expand All @@ -15,19 +15,26 @@
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
import com.smileidentity.networking.pollSmartSelfieJobStatus
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import java.io.File
import java.net.URL
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -36,9 +43,6 @@
import kotlinx.coroutines.flow.single
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.net.URL
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

class SmileIDPlugin : FlutterPlugin, SmileIDApi, ActivityAware {
private var activity: Activity? = null
Expand Down Expand Up @@ -162,6 +166,74 @@
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
Loading