Risk Android SDK
Last updated: October 16, 2024
Our checkout-risk-sdk-android
SDK captures advanced fraud signals that are leveraged in our fraud scoring machine learning model.
Information
To enable access to the Risk SDK, contact your Account Manager or [email protected].
Generate a public API key from your Dashboard.
The minimum requirements to use the Android SDK are:
- Android API level 21 (Android 5.0) or later as a build target
- Compatibility with targetSdk versions 21 to 33
Add the Risk Android SDK as a dependency from GitHub.
Information
To see the installation steps and available versions, refer to the jitpack.io/frames-android documentation.
Add the JitPack repository to your project-level build.gradle
file:
1// project gradle file23allprojects {4repositories {5maven { url 'https://jitpack.io' }6maven { url = uri("https://maven.fpregistry.io/releases") }7}8}
Add Risk SDK dependency to the module gradle file:
1// module gradle file23dependencies {4implementation 'com.github.checkout:checkout-risk-sdk-android:<latest_version>'5}
To ensure you have the correct build configuration, make sure you:
- Add the Jitpack repository to the project gradle file
- Add the dependency to the module gradle file
Initialize the package with the getInstance
method by passing the:
- API key
- Environment
1// Example usage of package23val yourConfig = RiskConfig(publicKey = "pk_qa_xxx", environment = RiskEnvironment.QA)45// Initialize the package with the getInstance method early-on6val riskInstance =7Risk.getInstance(8context,9RiskConfig(10BuildConfig.SAMPLE_MERCHANT_PUBLIC_KEY,11RiskEnvironment.QA,12false,13),14).let {15it?.let {16it17} ?: run {18null19}20}
When the shopper selects the option to pay, publish the device data with the publishData
method on the Risk instance and retrieve the deviceSessionId
.
1// Publish the device data with the publishData method23riskInstance?.publishData().let {4if (it is PublishDataResult.Success) {5println("Device session ID: ${it.deviceSessionId}") // dsid_XXXX6}7}
The getInstance
method returns a singleton instance of Risk
. When you call the method, preliminary checks are made to Checkout.com's internal APIs. These APIs retrieve the public keys used to initialize the package for collecting device data.
If the checks fail or the merchant is disabled, the method returns null
.
If the checks are successful, the method returns an instance of Risk
to the consumer of the package. You can then call the publishData
method on the instance to publish the data.
1data class RiskConfig(val publicKey: String, val environment: RiskEnvironment, val framesMode: Boolean = false)23// Instance creation of Risk Android package4public class Risk private constructor(...) {5public companion object {6...7public suspend fun getInstance(applicationContext: Context, config: RiskConfig): Risk? {8...9}10}11}1213enum class RiskEnvironment {14SANDBOX,15PROD16}
1class Risk private constructor(...) {2companion object {3...4suspend fun publishData(...): ... {5...6}7}8}
Use publishData
to publish and persist the device data.
1public suspend fun publishData(cardToken: string? = null): PublishDataResult {2...3}
1public sealed class PublishDataResult {2public data class Success(val deviceSessionId: String) : PublishDataResult()34public data object PublishFailure : PublishDataResult()5}
1// Example usage of package2val yourConfig = RiskConfig(publicKey = "pk_qa_xxx", environment = RiskEnvironment.QA)34// Initialize the package with the getInstance method5val riskInstance =6Risk.getInstance(7context,8RiskConfig(9BuildConfig.SAMPLE_MERCHANT_PUBLIC_KEY,10RiskEnvironment.QA,11false,12),13).let {14it?.let {15it16} ?: run {17null18}19}2021// Publish the device data with the publishData method when the user selects the option to pay2223riskInstance?.publishData().let {24if (it is PublishDataResult.Success) {25println("Device session ID: ${it.deviceSessionId}") // dsid_XXXX26}27}