Callbacks
Use callbacks to get notified about SDK state changes, errors, and events.
The following callbacks are available:
Pass the state, error and completion callbacks in one withHandlers(...) call.
On SDK state changes
Use withHandlers(onStateChanged=onSDKStateChangedHandler) or withStateChangedHandler(stateChangedHandler) in the SDK builder to get notified about changes in the flow of the verification process.
The callback takes two parameters:
newStateis the current SDK State.prevStateis the previous state value.
The following example lists all the possible states:
val onSDKStateChangedHandler: (SNSSDKState, SNSSDKState) -> Unit = { newState, prevState ->
Timber.d("onSDKStateChangedHandler: $prevState -> $newState")
when (newState) {
is SNSSDKState.Ready -> Timber.d("SDK is ready")
is SNSSDKState.Failed -> {
when (newState) {
is SNSSDKState.Failed.ApplicantNotFound -> Timber.e(newState.message)
is SNSSDKState.Failed.ApplicantMisconfigured -> Timber.e(newState.message)
is SNSSDKState.Failed.InitialLoadingFailed -> Timber.e(newState.exception,"Initial loading error")
is SNSSDKState.Failed.InvalidParameters -> Timber.e(newState.message)
is SNSSDKState.Failed.NetworkError -> Timber.e(newState.exception,newState.message)
is SNSSDKState.Failed.Unauthorized -> Timber.e(newState.message)
is SNSSDKState.Failed.Unknown -> Timber.e(newState.exception, "Unknown error")
}
}
is SNSSDKState.Initial -> Timber.d("No verification steps are passed yet")
is SNSSDKState.Incomplete -> Timber.d("Some but not all verification steps are passed over")
is SNSSDKState.Pending -> Timber.d("Verification is in pending state")
is SNSSDKState.FinallyRejected -> Timber.d("Applicant has been finally rejected")
is SNSSDKState.TemporarilyDeclined -> Timber.d("Applicant has been declined temporarily")
is SNSSDKState.Approved -> Timber.d("Applicant has been approved")
}
}
val snsSdkBuilder = SNSMobileSDK.Builder(this).withHandlers(onStateChanged = onSDKStateChangedHandler)On SDK errors
Use withHandlers(onError=onSDKErrorHandler) in the SDK builder to know about errors that occur within the SDK.
Refer to the example below to see how.
val onSDKErrorHandler: (SNSException) -> Unit = { exception ->
Timber.d("The SDK throws an exception. Exception: $exception")
when (exception) {
is SNSException.Api -> Timber.d("Api exception. ${exception.description}")
is SNSException.Network -> Timber.d(exception, "Network exception.")
is SNSException.Unknown -> Timber.d(exception, "Unknown exception.")
is SNSException.Internal -> Timber.d(exception, "Internal exception.")
}
}
val snsSdkBuilder = SNSMobileSDK.Builder(this).withHandlers(onError = onSDKErrorHandler)On SDK completion
An optional callback to get notified when the SDK is closed.
val onSDKCompletedHandler: (SNSCompletionResult, SNSSDKState) -> Unit = { result, state ->
when (result) {
is SNSCompletionResult.SuccessTermination -> Timber.d("The SDK finished successfully")
is SNSCompletionResult.AbnormalTermination -> Timber.e(result.exception, "The SDK got closed because of errors")
}
}
val snsSdkBuilder = SNSMobileSDK.Builder(this).withHandlers(onCompleted = onSDKCompletedHandler)The callback takes two parameters:
result:SNSCompletionResult.SuccessTermination— a successful completion of the work of the SDK, including adismiss()call, except on the error screen.SNSCompletionResult.AbnormalTermination— an error occurred. Look at theexceptionobject to get more information.
state: The state at which the SDK was closed. For possible states, refer to the following On SDK state changes
Events
Providing events callback allows you to be aware of the events happening during the processing.
Events are passed into the callback as instances of a class inherited from the base SNSEvent class; this way, each event has its eventType and some parameters packed into payload dictionary. So, depending on your needs, you can get event parameters either by examining the payload directly or by casting the given event instance to a specific SNSEvent* class according to its type.
val onEventHandler: SNSEventHandler = object : SNSEventHandler {
override fun onEvent(event: SNSEvent) {
when (event) {
is SNSEvent.SNSEventStepInitiated -> {
Timber.d("onEvent: step initiated")
}
is SNSEvent.SNSEventStepCompleted -> {
Timber.d("onEvent: step completed")
}
else -> Unit
}
}
}
val snsSdkBuilder = SNSMobileSDK.Builder(this).withEventHandler(onEventHandler)Icon handler
By providing an icon handler, you are able to provide a drawable for specific positions on the Sumsub SDK screens.
This includes instruction and document icons, country flags, and many other images.
You will be provided with an icon key and the themed context. The handler should return a drawable or null if the drawable is not needed.
The SDK uses the following keys:
default/do_idCard— an icon for the identity card instruction, the DO block.default/do_idCard_backSide— an icon for the back side of the identity card instruction, the DO block.default/do_passport— an icon for the password instruction, the DO block.default/dont_idCard— an icon for the identity card instruction, the DON'T block.default/dont_idCard_backSide— an icon for the back side of the identity card instruction, the DON'T block.default/dont_passport— an icon for the password instruction, the DON'T block.default/facescan— an icon for the Liveness instruction.IdentityType/<DOCUMENT TYPE>— an icon for the document's item on the Document Selector screen, where<DOCUMENT TYPE>is PASSPORT, DRIVERS, RESIDENCE_PERMIT, or another document.Flag/<COUNTRY_CODE>— an icon for a country flag, where <COUNTRY_CODE> is a lowercase ISO 3166-1 alpha-2 code, for example,Flag/de.
You can provide your own icons or overwrite existing ones by extending the SNSDefaultIconHandler. Your handler replaces the default, so return super.onResolveIcon(context, key) for other keys. If no handler has been provided, the SNSDefaultIconHandler is used.
val iconHandler = object : SNSDefaultIconHandler() {
override fun onResolveIcon(context: Context, key: String): Drawable? {
val iconRes = when {
key == "default/do_idCard" -> R.drawable.sns_ic_intro_do
key == "default/do_passport" -> R.drawable.sns_ic_intro_do_passport
key == "default/dont_idCard" -> R.drawable.sns_ic_intro_dont
key == "default/dont_passport" -> R.drawable.sns_ic_intro_dont_passport
key == "default/facescan" -> R.drawable.sns_ic_intro_liveness
key == "default/do_idCard_backSide" -> R.drawable.sns_ic_intro_do_back
key == "default/dont_idCard_backSide" -> R.drawable.sns_ic_intro_dont_back
key == "IdentityType/PASSPORT" -> R.drawable.sns_ic_iddoc_passport
key == "IdentityType/DRIVERS" -> R.drawable.sns_ic_iddoc_driving_license
key == "IdentityType/RESIDENCE_PERMIT" -> R.drawable.sns_ic_iddoc_residence_permit
key.startsWith("IdentityType/") -> R.drawable.sns_ic_iddoc_id_card
else -> return super.onResolveIcon(context, key)
}
return ResourcesCompat.getDrawable(context.resources, iconRes, context.theme)
}
}
val snsSdkBuilder = SNSMobileSDK.Builder(this).withIconHandler(iconHandler)Updated 12 days ago