Skip to content

Commit

Permalink
Pass extras and Biometric KYC sandbox photo (#250)
Browse files Browse the repository at this point in the history
* added passing extras and photo param

* updated CHANGELOG.md

* updated code docs

* fixed failing test

* remove photo key and rename extras to partnerParams
  • Loading branch information
jumaallan authored Nov 14, 2023
1 parent 4c18abb commit 2030f76
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 10.0.0-beta13 (unreleased)

### Added
- Added `extras` as optional params on all job types
- Added `idAuthorityBypassPhoto` on Sandbox BiometricKYC jobs
- Added `allowAgentMode` option on Document Verification and Enhanced Document Verification

### Fixed
Expand Down
17 changes: 17 additions & 0 deletions lib/src/main/java/com/smileidentity/compose/SmileIDExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import com.smileidentity.util.randomUserId
import com.smileidentity.viewmodel.document.DocumentVerificationViewModel
import com.smileidentity.viewmodel.document.EnhancedDocumentVerificationViewModel
import com.smileidentity.viewmodel.viewModelFactory
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import java.io.File
import java.net.URL

Expand All @@ -49,6 +51,7 @@ import java.net.URL
* @param showAttribution Whether to show the Smile ID attribution or not on the Instructions screen
* @param showInstructions Whether to deactivate capture screen's instructions for
* SmartSelfie.
* @param partnerParams Custom values specific to partners
* @param colorScheme The color scheme to use for the UI. This is passed in so that we show a Smile
* ID branded UI by default, but allow the user to override it if they want.
* @param typography The typography to use for the UI. This is passed in so that we show a Smile ID
Expand All @@ -63,6 +66,7 @@ fun SmileID.SmartSelfieEnrollment(
allowAgentMode: Boolean = false,
showAttribution: Boolean = true,
showInstructions: Boolean = true,
partnerParams: ImmutableMap<String, String> = persistentMapOf(),
colorScheme: ColorScheme = SmileID.colorScheme,
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<SmartSelfieResult> = {},
Expand All @@ -76,6 +80,7 @@ fun SmileID.SmartSelfieEnrollment(
allowAgentMode = allowAgentMode,
showAttribution = showAttribution,
showInstructions = showInstructions,
partnerParams = partnerParams,
onResult = onResult,
)
}
Expand All @@ -96,6 +101,7 @@ fun SmileID.SmartSelfieEnrollment(
* displayed allowing toggling between the back camera and front camera. If not allowed, only the
* front camera will be used.
* @param showAttribution Whether to show the Smile ID attribution or not on the Instructions screen
* @param partnerParams Custom values specific to partners
* @param colorScheme The color scheme to use for the UI. This is passed in so that we show a Smile
* ID branded UI by default, but allow the user to override it if they want.
* @param typography The typography to use for the UI. This is passed in so that we show a Smile ID
Expand All @@ -109,6 +115,7 @@ fun SmileID.SmartSelfieAuthentication(
jobId: String = rememberSaveable { randomJobId() },
allowAgentMode: Boolean = false,
showAttribution: Boolean = true,
partnerParams: ImmutableMap<String, String> = persistentMapOf(),
colorScheme: ColorScheme = SmileID.colorScheme,
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<SmartSelfieResult> = {},
Expand All @@ -121,6 +128,7 @@ fun SmileID.SmartSelfieAuthentication(
isEnroll = false,
allowAgentMode = allowAgentMode,
showAttribution = showAttribution,
partnerParams = partnerParams,
onResult = onResult,
)
}
Expand Down Expand Up @@ -153,6 +161,7 @@ fun SmileID.SmartSelfieAuthentication(
* @param allowGalleryUpload Whether to allow the user to upload images from their gallery or not
* @param showInstructions Whether to deactivate capture screen's instructions for Document
* Verification (NB! If instructions are disabled, gallery upload won't be possible)
* @param partnerParams Custom values specific to partners
* @param colorScheme The color scheme to use for the UI. This is passed in so that we show a Smile
* ID branded UI by default, but allow the user to override it if they want.
* @param typography The typography to use for the UI. This is passed in so that we show a Smile ID
Expand All @@ -173,6 +182,7 @@ fun SmileID.DocumentVerification(
allowAgentMode: Boolean = false,
allowGalleryUpload: Boolean = false,
showInstructions: Boolean = true,
partnerParams: ImmutableMap<String, String> = persistentMapOf(),
colorScheme: ColorScheme = SmileID.colorScheme,
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<DocumentVerificationResult> = {},
Expand All @@ -199,6 +209,7 @@ fun SmileID.DocumentVerification(
documentType = documentType,
captureBothSides = captureBothSides,
selfieFile = bypassSelfieCaptureWithFile,
partnerParams = partnerParams,
)
},
),
Expand Down Expand Up @@ -232,6 +243,7 @@ fun SmileID.DocumentVerification(
* @param allowGalleryUpload Whether to allow the user to upload images from their gallery or not
* @param showInstructions Whether to deactivate capture screen's instructions for Document
* Verification (NB! If instructions are disabled, gallery upload won't be possible)
* @param partnerParams Custom values specific to partners
* @param colorScheme The color scheme to use for the UI. This is passed in so that we show a Smile
* ID branded UI by default, but allow the user to override it if they want.
* @param typography The typography to use for the UI. This is passed in so that we show a Smile ID
Expand All @@ -251,6 +263,7 @@ fun SmileID.EnhancedDocumentVerificationScreen(
allowAgentMode: Boolean = false,
allowGalleryUpload: Boolean = false,
showInstructions: Boolean = true,
partnerParams: ImmutableMap<String, String> = persistentMapOf(),
colorScheme: ColorScheme = SmileID.colorScheme,
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<EnhancedDocumentVerificationResult> = {},
Expand All @@ -276,6 +289,7 @@ fun SmileID.EnhancedDocumentVerificationScreen(
countryCode = countryCode,
documentType = documentType,
captureBothSides = captureBothSides,
partnerParams = partnerParams,
)
},
),
Expand Down Expand Up @@ -303,6 +317,7 @@ fun SmileID.EnhancedDocumentVerificationScreen(
* allowing toggling between the back camera and front camera. If not allowed, only the front
* camera will be used.
* @param showAttribution Whether to show the Smile ID attribution or not on the Instructions screen
* @param partnerParams Custom values specific to partners
* @param colorScheme The color scheme to use for the UI. This is passed in so that we show a Smile
* ID branded UI by default, but allow the user to override it if they want.
* @param typography The typography to use for the UI. This is passed in so that we show a Smile ID
Expand All @@ -321,6 +336,7 @@ fun SmileID.BiometricKYC(
jobId: String = rememberSaveable { randomJobId() },
allowAgentMode: Boolean = false,
showAttribution: Boolean = true,
partnerParams: ImmutableMap<String, String> = persistentMapOf(),
colorScheme: ColorScheme = SmileID.colorScheme,
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<BiometricKycResult> = {},
Expand All @@ -337,6 +353,7 @@ fun SmileID.BiometricKYC(
jobId = jobId,
allowAgentMode = allowAgentMode,
showAttribution = showAttribution,
partnerParams = partnerParams,
onResult = onResult,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import com.smileidentity.util.randomJobId
import com.smileidentity.util.randomUserId
import com.smileidentity.viewmodel.BiometricKycViewModel
import com.smileidentity.viewmodel.viewModelFactory
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import java.net.URL

@Composable
Expand All @@ -43,8 +45,16 @@ fun OrchestratedBiometricKYCScreen(
jobId: String = rememberSaveable { randomJobId() },
allowAgentMode: Boolean = false,
showAttribution: Boolean = true,
partnerParams: ImmutableMap<String, String> = persistentMapOf(),
viewModel: BiometricKycViewModel = viewModel(
factory = viewModelFactory { BiometricKycViewModel(idInfo, userId, jobId) },
factory = viewModelFactory {
BiometricKycViewModel(
idInfo = idInfo,
userId = userId,
jobId = jobId,
partnerParams = partnerParams,
)
},
),
onResult: SmileIDCallback<BiometricKycResult> = {},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ internal fun OrchestratedBvnConsentScreen(
modifier: Modifier = Modifier,
showAttribution: Boolean = true,
viewModel: BvnConsentViewModel = viewModel(
factory = viewModelFactory {
BvnConsentViewModel(userId = userId)
},
factory = viewModelFactory { BvnConsentViewModel(userId = userId) },
),
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import com.smileidentity.util.randomJobId
import com.smileidentity.util.randomUserId
import com.smileidentity.viewmodel.SelfieViewModel
import com.smileidentity.viewmodel.viewModelFactory
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf

/**
* Orchestrates the selfie capture flow - navigates between instructions, requesting permissions,
Expand All @@ -43,8 +45,17 @@ internal fun OrchestratedSelfieCaptureScreen(
skipApiSubmission: Boolean = false,
showAttribution: Boolean = true,
showInstructions: Boolean = true,
partnerParams: ImmutableMap<String, String> = persistentMapOf(),
viewModel: SelfieViewModel = viewModel(
factory = viewModelFactory { SelfieViewModel(isEnroll, userId, jobId, skipApiSubmission) },
factory = viewModelFactory {
SelfieViewModel(
isEnroll = isEnroll,
userId = userId,
jobId = jobId,
skipApiSubmission = skipApiSubmission,
partnerParams = partnerParams,
)
},
),
onResult: SmileIDCallback<SmartSelfieResult> = {},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import com.smileidentity.results.BiometricKycResult
import com.smileidentity.results.SmileIDCallback
import com.smileidentity.results.SmileIDResult
import com.smileidentity.util.getExceptionHandler
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
Expand All @@ -33,6 +35,7 @@ class BiometricKycViewModel(
private val idInfo: IdInfo,
private val userId: String,
private val jobId: String,
private val partnerParams: ImmutableMap<String, String> = persistentMapOf(),
) : ViewModel() {
private val _uiState = MutableStateFlow(BiometricKycUiState())
val uiState = _uiState.asStateFlow()
Expand Down Expand Up @@ -92,7 +95,7 @@ class BiometricKycViewModel(
val authResponse = SmileID.api.authenticate(authRequest)

val prepUploadRequest = PrepUploadRequest(
partnerParams = authResponse.partnerParams,
partnerParams = authResponse.partnerParams.copy(extras = partnerParams),
signature = authResponse.signature,
timestamp = authResponse.timestamp,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import com.smileidentity.util.createLivenessFile
import com.smileidentity.util.createSelfieFile
import com.smileidentity.util.getExceptionHandler
import com.smileidentity.util.postProcessImageBitmap
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
Expand Down Expand Up @@ -80,6 +82,7 @@ class SelfieViewModel(
private val userId: String,
private val jobId: String,
private val skipApiSubmission: Boolean,
private val partnerParams: ImmutableMap<String, String> = persistentMapOf(),
) : ViewModel() {
private val _uiState = MutableStateFlow(SelfieUiState())

Expand Down Expand Up @@ -274,7 +277,7 @@ class SelfieViewModel(
val authResponse = SmileID.api.authenticate(authRequest)

val prepUploadRequest = PrepUploadRequest(
partnerParams = authResponse.partnerParams,
partnerParams = authResponse.partnerParams.copy(extras = partnerParams),
signature = authResponse.signature,
timestamp = authResponse.timestamp,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import com.smileidentity.results.SmartSelfieResult
import com.smileidentity.results.SmileIDCallback
import com.smileidentity.results.SmileIDResult
import com.smileidentity.util.getExceptionHandler
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
Expand All @@ -48,6 +50,7 @@ internal abstract class OrchestratedDocumentViewModel<T : Parcelable>(
private val documentType: String? = null,
private val captureBothSides: Boolean,
private var selfieFile: File? = null,
private var partnerParams: ImmutableMap<String, String> = persistentMapOf(),
) : ViewModel() {
private val _uiState = MutableStateFlow(OrchestratedDocumentUiState())
val uiState = _uiState.asStateFlow()
Expand Down Expand Up @@ -125,7 +128,7 @@ internal abstract class OrchestratedDocumentViewModel<T : Parcelable>(
val authResponse = SmileID.api.authenticate(authRequest)

val prepUploadRequest = PrepUploadRequest(
partnerParams = authResponse.partnerParams,
partnerParams = authResponse.partnerParams.copy(extras = partnerParams),
signature = authResponse.signature,
timestamp = authResponse.timestamp,
)
Expand Down Expand Up @@ -213,6 +216,7 @@ internal class DocumentVerificationViewModel(
documentType: String? = null,
captureBothSides: Boolean,
selfieFile: File? = null,
partnerParams: ImmutableMap<String, String> = persistentMapOf(),
) : OrchestratedDocumentViewModel<DocumentVerificationResult>(
jobType = jobType,
userId = userId,
Expand All @@ -221,6 +225,7 @@ internal class DocumentVerificationViewModel(
documentType = documentType,
captureBothSides = captureBothSides,
selfieFile = selfieFile,
partnerParams = partnerParams,
) {

override fun getJobStatus(
Expand Down Expand Up @@ -252,6 +257,7 @@ internal class EnhancedDocumentVerificationViewModel(
documentType: String? = null,
captureBothSides: Boolean,
selfieFile: File? = null,
partnerParams: ImmutableMap<String, String> = persistentMapOf(),
) :
OrchestratedDocumentViewModel<EnhancedDocumentVerificationResult>(
jobType = jobType,
Expand All @@ -261,6 +267,7 @@ internal class EnhancedDocumentVerificationViewModel(
documentType = documentType,
captureBothSides = captureBothSides,
selfieFile = selfieFile,
partnerParams = partnerParams,
) {

override fun getJobStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ class PartnerParamsAdapterTest {
userId = "userId",
extras = mapOf("extra1" to "value1", "extra2" to "value2"),
)
val kepMap = mapOf("jobId" to "job_id", "userId" to "user_id", "jobType" to "job_type")
val kepMap = mapOf(
"jobId" to "job_id",
"userId" to "user_id",
"jobType" to "job_type",
)

// when
val jsonString = adapter.toJson(partnerParams)
Expand Down

0 comments on commit 2030f76

Please sign in to comment.