React native Loans SDK Integration
Integrate smallcase loans React Native SDK to allow your users to apply for loans, pay, withdraw, and much more
Step 1 - Install and Configure
Gateway React-Native Loans SDK is available on npm. To install the SDK:
- Add the SDK using the preferred package manager.
yarn add react-native-smallcase-gatewaynpm install react-native-smallcase-gateway- The library exports all its methods with one default import. Import it using
import SmallcaseGateway from "react-native-smallcase-gateway";A. Android
Configure smallcase Gateway Android 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_HOST_NAME}" with unique host name which is given to every integration partners.
NoteIf 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 run pod install within the directory
NoteRunning pod update after adding a source will trigger a clone of the the source repo. This operation might take time when
pod updateis run for the first time. Subsequent updates will be faster.
Step 2- Environment Setup
To start using loans setup the gateway SDK with the desired configuration by calling the setup method.
const config = ScLoanConfig(gatewayName, environment);
try {
const res = await ScLoan.setup({config: config});
alert('Success', `${res}`);
} catch (error: any) {
alert('Error', `${error}, ${JSON.stringify(error.userInfo)}`);
}
Params :
- ScLoanConfig
- gatewayName (required): This is a unique name given to every gateway consumer
Eg : moneycontrol - environment (required): This defines the Url environment to which all the gateway apis would point to Possible values - **_SmallcaseGateway.ENV.PROD
- gatewayName (required): This is a unique name given to every gateway consumer
NoteCall setup every time there is any change in the setup.
setup must be the first method to be fired.If setup is not called all other methods will not work.
Step 3 - Call the relevant method for each functionality
Based on the action to be performed, trigger the relevant method of ScLoan class.
Interaction Token should be created before calling any Loans related method
All the Loans methods on the SDK instance require an interaction token to be passed as an argument. The JWT token holds the context of user action in the form of Interaction ID. It is a unique, one-time-use ID created each time a borrower wants to interact with their loan via SDK. Learn what & how of interaction ID & token in Glossary & API documentation.
1. apply: start or resume loan application
apply: start or resume loan applicationYou can start or resume a loan application by calling the apply method on the SDK.
try {
const applyRes = await ScLoan.apply({
interactionToken: interactionToken,
});
alert('Success', `${JSON.stringify(applyRes)}`);
} catch (error: any) {
alert('Error', `${error}, ${JSON.stringify(error.userInfo)}`);
}
Params :
- interactionToken (required): a unique string you received from the backend in the previous step.
Go to the next step for response handling
2. pay: repayments (principal, bounced interest, charges due)
pay: repayments (principal, bounced interest, charges due)For repayment, the gateway flow can be triggered opened by calling the pay method on the SDK -
try {
const payRes = await ScLoan.pay({
interactionToken: interactionToken,
});
alert('Success', `${JSON.stringify(payRes)}`);
} catch (error: any) {
alert('Error', `${error}, ${JSON.stringify(error.userInfo)}`);
}
Params :
- interactionToken (required): a unique string you received from the backend in the previous step.
Go to the next step for response handling
3. withdraw: withdraw un-utilised credit limit
withdraw: withdraw un-utilised credit limitYou can withdraw from your approved credit by calling the withdraw method on the SDK.
try {
const withdrawRes = await ScLoan.withdraw({
interactionToken: interactionToken,
});
alert('Success', `${JSON.stringify(withdrawRes)}`);
} catch (error: any) {
alert('Error', `${error}, ${JSON.stringify(error.userInfo)}`);
}Params :
- interactionToken (required): a unique string you received from the backend in the previous step.
Go to the next step for response handling
4. service: view loan dashboard (aka servicing dashboard)
service: view loan dashboard (aka servicing dashboard)This will open up Gateway's UI for servicing dashboard where user can view all of their loan details and take any further action (eg. repayment, withdrawal, closure).
try {
const serviceRes = await ScLoan.service({
interactionToken: interactionToken,
});
alert('Success', `${JSON.stringify(serviceRes)}`);
} catch (error: any) {
alert('Error', `${error}, ${JSON.stringify(error.userInfo)}`);
}Params :
- interactionToken (required): a unique string you received from the backend in the previous step.
Go to the next step for response handling
Step 4 - Handle response or error
If the user's intended action is completed, the Future returned by the method will resolve with a success response. Else, if flow ends without action completion, an exception is thrown.
Success responses
ScLoanSuccess is an internal class that denotes a success response on the SDK.
The React Native SDK returns a serialised version of this object whose signature is defined below.
{
"isSuccess": true,
"data": {
"intent": "LOAN_APPLICATION",
"userId": "string",
"loanApplication": {
"status": "<ApplicationStatus>" // possible enum values below
}
}
}{
"isSuccess": true,
"data": {
"intent": "PAYMENT",
"userId": "string",
"payment": {
"status": "<PaymentStatus>"
}
}
}{
"isSuccess": true,
"data": {
"intent": "WITHDRAW",
"userId": "string",
"withdraw": {
"status": "<WithdrawStatus>"
}
}
}// .service() promise will always be rejected with an error.
// This is because there's no specific user intent that should cause a success.What are possible values of Application Status?
| Application status | Description |
|---|---|
| REGISTER_LEAD | Initial status of the application |
| IMPORT_HOLDINGS | User dropped off without completing the holdings import step |
| CONFIRM_OFFER | User completed holdings import but didn't continue with the credit limit available |
| FETCH_CKYC | User continued with credit limit available but dropped off before completing KYC |
| LINK_BANK_ACCOUNT | User completed KYC but dropped off before entering bank details & setting up e-mandate |
| PLEDGE_FUNDS | User created e-mandate but didn't complete the pledging of mutual funds |
| SUBMISSION_FAILED | User pledged the mutual funds but due to some issues, the application submission to lender failed & the agreement was not generated |
| SIGN_AGREEMENT | User pledged the mutual funds & agreement was generated but user dropped off before signing the agreement |
| SUBMITTED | User signed the agreement and the loan application is available to the lender for approval |
| APPROVED | Loan application was approved by the lender |
| DISBURSEMENT_REQUESTED | Disbursement for the loan amount has been requested |
| DISBURSED | Loan amount has been disbursed by the lender to user's bank account |
Error response
ScLoanError is an internal class that denotes an error response on the SDK.
The React Native SDK throws a serialised version of this object whose signature is defined below.
{
"isSuccess": false,
"code": "number", // enums below
"message": "string", // enums below
"data"?: {} // intent specific data point
}// case where user drops off before applying
{
"isSuccess": false,
"code": 1012,
"message": "user_cancelled",
"data": {
"intent": "LOAN_APPLICATION",
"loanApplication": {
"lid": "648c66ffc3488a97c9931a2d",
"status": "SIGN_AGREEMENT"
},
"userId": "648c6705ee286538f7bebbbb"
}
}
// case where loan is active with another platform
{
"isSuccess": false,
"code": 3001,
"message": "existing_loan_found",
"data": {
"intent": "LOAN_APPLICATION",
"userId": "64ad01ba0241316d036519c6"
}
}
// other error codes bellowThe error code <> message mapping -
| Error code | Corresponding Error message | reason |
|---|---|---|
| 1012 | user_cancelled | The user aborted the flow by closing/abandoning the UI |
| 1031 | contact_support | The user wants to customer support and has tapped the contact icon. Redirect them to the support page or trigger chat page. |
| 1033 | topup_triggered | The user intent topup journey on service-dashboard. HostApp may handle topup loan application/trigger SDK with loan-application:topup intent. |
| 2000 | internal_error | |
| 2001 | missing_url_params | |
| 3001 | existing_loan_found | |
| 4000 | invalid_request | |
| 4001 | partner_inactive | |
| 4002 | guest_not_allowed | |
| 4003 | interaction_expired | |
| 4004 | invalid_intent | |
| 4005 | invalid_interaction | |
| 4006 | invalid_intent_config | |
| 4007 | api_secret_mismatch | |
| 4008 | invalid_auth_token |
Got queries? Ask our AM for an integrations support email. If an email thread exists, post queries as a reply to that.