React native Loans SDK Integration

Integrate smallcase loans React Native 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

The Gateway React Native Loans SDK is available on npm.

  1. Add the SDK using your preferred package manager.
yarn add react-native-smallcase-gateway
npm install react-native-smallcase-gateway
  1. The loans API is exposed as the named ScLoan export. Import it with:
import { ScLoan } from "react-native-smallcase-gateway";
📘

Note

ScLoan is a named export. The package's default export is the smallcase investing Gateway SDK — they are separate surfaces. For loans, always use the named ScLoan import shown above.

A. Android

Configure the 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 gateway 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.

B. iOS

Go to your project's ios folder and run pod install.

📘

Note

Running pod install after adding the dependency will trigger a clone of the source repo. This operation might take time the first time it is run. Subsequent updates will be faster.


Step 2 - Environment Setup

Initialise the loans SDK by calling setup before any other method. Pass the config object directly.

try {
    const res = await ScLoan.setup({
        gatewayName: gatewayName,
        environment: "production",
    });
    // res = { isSuccess: true, data: "<serialised JSON string>" }
} catch (error) {
    // error.code, error.message, error.userInfo — see Step 4
}

Params — ScLoanConfig:

  1. gatewayName (required): The unique name given to every gateway consumer.
    Eg: "moneycontrol"
  2. environment (optional, default "production"): The API environment to target.
    Possible values: "production" | "staging"
📘

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 completed successfully.


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

try {
    const res = await ScLoan.triggerInteraction({
        interactionToken: interactionToken,
    });
    alert("Success", `${JSON.stringify(res)}`);
} catch (error) {
    alert("Error", `${error}, ${JSON.stringify(error.userInfo)}`);
}

Params — ScLoanInfo:

  1. interactionToken (required): The unique string you received from your backend.

Step 4 - Handle response or error

Each method returns a Promise. It resolves with a success object, or rejects with an error.

Success response

The promise resolves with a ScLoanSuccess object:

type ScLoanSuccess = {
    isSuccess: boolean;  // always true
    data: string;        // serialised JSON — parse to get the intent-specific payload
};

Parse res.data to read the intent-specific result. 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 reject when the user closes the dashboard (with user_cancelled). 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

When the promise rejects, the caught value is a standard JavaScript Error with three relevant fields populated by the native bridge:

error.code     // string — the SDK error code (eg. "1012")
error.message  // string — the error message (eg. "user_cancelled")
error.userInfo // object — { isSuccess: false, code, message, data }

The intent-specific payload lives in error.userInfo.data as a serialised JSON string. Read errors like this:

try {
    await ScLoan.triggerInteraction({ interactionToken });
} catch (error) {
    console.log(error.code);            // "1012"
    console.log(error.message);         // "user_cancelled"
    const info = error.userInfo;        // { isSuccess: false, code, message, data }
    const payload = JSON.parse(info.data ?? "{}");
}

Example error.userInfo values:

{
  "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. Use triggerInteraction() for all new integrations — the interaction token carries the intent, so a single method handles all flows.

// All take { interactionToken } and return Promise<ScLoanSuccess>

await ScLoan.apply({ interactionToken });    // @deprecated — loan origination
await ScLoan.pay({ interactionToken });      // @deprecated — repayment
await ScLoan.withdraw({ interactionToken }); // @deprecated — withdrawal
await ScLoan.service({ interactionToken });  // @deprecated — 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?