Android Loans SDK Integration

Integrate smallcase loans Android SDK to allow your users to apply for loans, pay, withdraw, and much more

🙌

Hey, before you read further

Must read: LAMF: Integration overview , Loans SDK integration guide

Step 1 - Install and Configure

smallcase Gateway Android Loans SDK is available as a public gradle dependency. To install the Android SDK, add it to your app level build.gradle file.

// Include maven repository url and authentication details
repositories {
    maven {
        url "https://artifactory.smallcase.com/artifactory/SCGateway"
        credentials {
            username "${artifactory_user}"
            password "${artifactory_password}"
        }
    }
}

// Add smallcase Loans SDK as a dependency
dependencies {
    implementation 'com.smallcase.loans:sdk:5.1.4'
}
  • Replace "${artifactory_user}" and "${artifactory_password}" with the credentials provided to your integration.
  • Check the changelog for the latest version.

Configuration should happen as early as possible in your application's lifecycle. Configure the Loans SDK via AndroidManifest.xml:

<activity android:name="com.smallcase.loans.features.ScLoanCustomTabActivity"
          android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:host="<YOUR_GATEWAY_NAME>"
            android:scheme="scgateway-loans"
        />
    </intent-filter>
</activity>

Replace "{YOUR_GATEWAY_NAME}" with the unique host name given to every integration partner.

🚧

Note

If your app targets Android 12 or higher you must explicitly declare the android:exported attribute for these activities. If an activity doesn't have an explicitly-declared value for android:exported, your app can't be installed on a device that runs Android 12 or higher.


Step 2 - Environment Setup

To start using the loans SDK, initialise it with your configuration by calling the setup method on the ScLoan object.

All public SDK types live in the com.smallcase.loans.core.external package. Import what you use:

import com.smallcase.loans.core.external.ScLoan
import com.smallcase.loans.core.external.ScLoanConfig
import com.smallcase.loans.core.external.ScLoanInfo
import com.smallcase.loans.core.external.ScLoanResult
import com.smallcase.loans.core.external.ScLoanSuccess
import com.smallcase.loans.core.external.ScLoanError
import com.smallcase.loans.core.external.ScLoanEnvironment
// or simply: import com.smallcase.loans.core.external.*
ScLoan.setup(
    config = ScLoanConfig(gatewayName = gatewayName),
    listener = object : ScLoanResult {

        override fun onSuccess(response: ScLoanSuccess) {
            // Handle response
        }

        override fun onFailure(error: ScLoanError) {
            // Handle error
        }
    }
)

Here's a look at the ScLoanConfig class:

data class ScLoanConfig(
    val gatewayName: String,
    val environment: ScLoanEnvironment = ScLoanEnvironment.PRODUCTION
)

Params:

  1. gatewayName (required): A unique name given to every gateway consumer.
    Eg: moneycontrol
  2. environment (optional, default: PRODUCTION): The environment to point SDK API calls to.
    Possible values: ScLoanEnvironment.PRODUCTION | ScLoanEnvironment.STAGING | ScLoanEnvironment.DEVELOPMENT
📘

Note

Call setup every time there is any change in configuration.
setup must be the first method called. All other methods will not work if setup hasn't been called.


Step 3 - Trigger a loan interaction

All loan flows are triggered through a single method: triggerInteraction. The SDK determines the correct flow (application, repayment, withdrawal, servicing) from the interactionToken you pass in.

Interaction Token must be created before calling any Loans SDK method

All Loans SDK methods require an interaction token passed as an argument. The JWT token holds the context of the user action in the form of an Interaction ID — a unique, one-time-use ID created each time a borrower wants to interact with their loan via the SDK. Learn more in the Glossary & API documentation.

triggerInteraction: unified loan interaction

ScLoan.triggerInteraction(
    activity = this,
    config = ScLoanInfo(interactionToken = interactionToken),
    listener = object : ScLoanResult {

        override fun onSuccess(response: ScLoanSuccess) {
            // Handle response
        }

        override fun onFailure(error: ScLoanError) {
            // Handle error
        }
    }
)

Params:

  1. activity (required): The calling Activity instance. Used to launch the SDK UI.
  2. config — ScLoanInfo (required):
    • interactionToken (required): The unique string received from your backend.
  3. listener — ScLoanResult (required): Callback interface with onSuccess and onFailure.

Step 4 - Handle response or error

Success response

ScLoanSuccess is a public data class returned by the SDK on success. Its fields are:

data class ScLoanSuccess(
    val data: String? = null,        // serialised JSON string — parse to get intent-specific data
    val code: Int = 0,
    val message: String = "success"
) {
    val isSuccess: Boolean get() = true   // computed property — always true
}

Parse response.data to read the intent-specific payload. The structure of the parsed JSON depends on the interaction:

{
  "intent": "LOAN_APPLICATION",
  "userId": "string",
  "loanApplication": {
    "status": "<ApplicationStatus>"
  }
}
{
  "intent": "PAYMENT",
  "userId": "string",
  "payment": {
    "status": "<PaymentStatus>"
  }
}
{
  "intent": "WITHDRAW",
  "userId": "string",
  "withdraw": {
    "status": "<WithdrawStatus>"
  }
}
📘

Note

The servicing dashboard (SERVICE intent) will always call onFailure with error code 1012 when the user closes the dashboard. This is by design — there is no specific user action that constitutes a success for the servicing flow.

See the full list of loan application statuses and their meanings here: Loan application statuses.

Error response

ScLoanError is a public data class thrown by the SDK when the user's intended action is not completed. Its fields are:

data class ScLoanError(
    val code: Int,
    val message: String,
    val data: String? = null         // serialised JSON string — parse to get intent-specific data
) {
    val isSuccess: Boolean get() = false  // computed property — always false
}

Example error responses:

{
  "isSuccess": false,
  "code": 1012,
  "message": "user_cancelled",
  "data": "{\"intent\":\"LOAN_APPLICATION\",\"loanApplication\":{\"lid\":\"648c66ffc3488a97c9931a2d\",\"status\":\"SIGN_AGREEMENT\"},\"userId\":\"648c6705ee286538f7bebbbb\"}"
}
{
  "isSuccess": false,
  "code": 3001,
  "message": "existing_loan_found",
  "data": "{\"intent\":\"LOAN_APPLICATION\",\"userId\":\"64ad01ba0241316d036519c6\"}"
}

For the full list of SDK error codes and their meanings, see SDK error codes.


Deprecated methods

The following methods are deprecated as of the current SDK version. Use triggerInteraction() instead — the interaction token carries the intent, so a single method handles all flows.

// All require (activity: Activity, config: ScLoanInfo, listener: ScLoanResult)

@Deprecated("Use triggerInteraction() instead.")
ScLoan.apply(activity, ScLoanInfo(interactionToken), listener)   // loan origination

@Deprecated("Use triggerInteraction() instead.")
ScLoan.pay(activity, ScLoanInfo(interactionToken), listener)     // repayment

@Deprecated("Use triggerInteraction() instead.")
ScLoan.withdraw(activity, ScLoanInfo(interactionToken), listener) // withdrawal

@Deprecated("Use triggerInteraction() instead.")
ScLoan.service(activity, ScLoanInfo(interactionToken), listener) // servicing dashboard

👋

Got queries? Ask our AM for an integrations support email. If an email thread exists, post queries as a reply to that.



Did this page help you?