Isic Virtual Id Sdk
This class covers following use-cases:
Show Virtual ID screen (with or without card information provided)
Cache or refresh already cached data
Clear SDK data
Screenflow:
Configuration
Before launching the Virtual ID screen or calling other SDK method, SDK must be properly configured. SDK can be configured using IsicVirtualIdSdk.configure method.
See documentation for IsicVirtualIdSdk.configure method.
Authorization method
All calls against server must be authorized.
Recommended authorization method is AuthorizationMethod.ClientCredentials.
If you know user's card information, pass it in AuthorizationMethod.ClientCredentials so the user is not being forced to fill in the card information manually.
See documentation for AuthorizationMethod.
Launch Virtual ID screen
To launch Virtual ID screen, it's necessary to create a launcher instance by calling IsicVirtualIdSdk.createVirtualIdScreenLauncher method. Returned instance contains launch
method requiring LaunchParameters as parameter.
Complete sample code attached below might be helpful.
Customize UI
The appearance of the screen can be customized in following ways:
Night mode can be changed/enforced
Custom (or predefined theme) can be provided
For details, please see UiConfig.
Custom theme
Custom theme can be created by creating a theme extending BaseVirtualIdTheme
.
Example of custom Virtual ID theme:
<style name="CustomVirtualIdIsicTheme" parent="BaseVirtualIdTheme">
<item name="isicThemeColorExtraLight">@color/isic_greeny_blue_extra_light</item>
<item name="isicThemeColorLight">@color/isic_greeny_blue_light</item>
<item name="isicThemeColor">@color/isic_greeny_blue</item>
<item name="isicThemeColorShadow">@color/isic_greeny_blue_shadow</item>
</style>
Then provide custom Theme by providing it's resource ID.
Custom translations
By default, the SDK texts are provided in English only. If another translations are needed, corresponding string values must be overridden. Search for strings with prefix isic_
(e.g.org.isic.sdk.R.string.isic_
).
Clear SDK
SDK stores various kind of data locally so it can be used when a device is offline. For example, if the card information is not passed to the SDK and user fills in their card information manually, it would be reused in future launches automatically. To remove these data, please see documentation for IsicVirtualIdSdk.clear.
Get Virtual ID Info Without Launching the Screen
In some cases, it may be useful to get/cache data before launching the screen. Please see documentation for IsicVirtualIdSdk.getVirtualId. This method can be used for updating data as well. This functionality is optional since the Virtual ID SDK would take care about it on its own.
Sample
Sample below covers complete functionality provided by IsicVirtualIdSdk.
Samples
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.isic.sdk.virtualid.IsicVirtualIdSdk
import org.isic.sdk.virtualid.IsicVirtualIdSdk.createVirtualIdScreenLauncher
import org.isic.sdk.virtualid.model.*
fun main() {
//sampleStart
class VirtualIdSampleActivity : AppCompatActivity() {
private val virtualIdScreen = createVirtualIdScreenLauncher {
Toast.makeText(this@VirtualIdSampleActivity, "Result: $it", Toast.LENGTH_SHORT).show()
}
/**
* Launch Virtual ID screen
*/
private fun launch() {
lifecycleScope.launch(Dispatchers.IO) {
configureIfNecessary()
withContext(Dispatchers.Main) {
virtualIdScreen.launch(LaunchParameters())
}
}
}
/**
* Cache content without launching the screen
*/
private fun cacheContent() {
lifecycleScope.launch(Dispatchers.IO) {
configureIfNecessary()
val result = IsicVirtualIdSdk.getVirtualId()
if (result.isSuccess) {
Toast.makeText(this@VirtualIdSampleActivity, "Content retrieved SUCCESSFULLY", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this@VirtualIdSampleActivity, "Content retrieval FAILED", Toast.LENGTH_SHORT).show()
}
}
}
/**
* Clear all SDK data
*/
private fun clear() {
lifecycleScope.launch(Dispatchers.IO) {
configureIfNecessary()
IsicVirtualIdSdk.clear()
}
}
/**
* Configure SDK in case that it was not configured yet
*/
private suspend fun configureIfNecessary() {
if (!IsicVirtualIdSdk.isConfigured) {
IsicVirtualIdSdk.configure(
appContext = applicationContext,
authorizationMethod = authorizationMethod,
)
}
}
private companion object {
private val authorizationMethod: AuthorizationMethod = AuthorizationMethod.ClientCredentials(
clientId = "example-client-id", // TODO: Change me
clientSecret = "example-client-secret", // TODO: Change me
redirectUri = "example-uri", // TODO: Change me
cardInfo = CardInfo(
cardNumber = "S420000012345A", // TODO: Change me
cardholderName = "Name Surname", // TODO: Change me
)
)
}
}
//sampleEnd
}
Functions
Method required to be called before any further manipulation with the SDK.
Creates and registers VirtualIdScreenContract which is necessary for launching ISIC Virtual ID screen.
Get data without launching Virtual ID screen.