Javascript Loans SDK Integration
This is an integration guide for enabling LAMF on your website, using our Javascript SDK.
Hey, before you read furtherMust read: LAMF: Integration overview
Good to read: LAMF: Product Overview
Get started with how to integrate our JS SDK has on your client-side website.
Step 1 - Load the SDK from URL
On the relevant pages of your website, include our Javascript SDK using the URL -
<script src="https://gateway.smallcase.com/scdk/2.0.0/scdk.js" type="text/javascript" /><script src="https://gateway.smallcase.com/scdk/2.0.0/lasSdk.js" type="text/javascript" />Since the SDK is not versioned, all future updates will be applied on the fly. It will be ensured that the changes are non-breaking.
Step 2 - Create an Object Instance of ScLoan class
ScLoan classOnce the script executes after loading, ScLoan class is available in JavaScript's global scope. All LAMF methods are to be called on the instance of this class.
const lasSdkInstance = new window.ScLoan({
// ! gateway name integration key is shared by business team
gatewayName: "<gateway_name>"
});Step 3 - Call the relevant method for each functionality
Based on the action to be performed, trigger the relevant method of lasSdkInstance object.
Interaction Token should be created before calling any LAMF related method
All the LAMF 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.
SDK Response (Success or Error)
SDK methods immediately return a JS promise and are asynchronously resolved or rejected whenever the flow ends. If the user completes the intended action, the promise gets resolved with a successful response. Else, it gets rejected with an error.
1. apply: start or resume loan application
apply: start or resume loan applicationYou can start open the loan application UI by calling the apply method on the SDK.
try {
const response = await lasSdkInstance.apply({
interactionToken: "<interaction_token>",
});
// handle success response
} catch (e) {
// handle error
}The method returns a Promise. At the close of the flow, the same promise is either resolved or rejected based on whether the user successfully applied for the loan. More details in the next step.
2. pay: repayments (principal, bounced interest, charges due)
pay: repayments (principal, bounced interest, charges due)For repayment, the gateway UI can be triggered opened by calling the pay method on the SDK -
try {
const response = await lasSdkInstance.pay({
interactionToken: "<interaction_token>",
});
// handle success response
} catch (e) {
// handle error
}Go to the next step for response handling.
3. withdraw: withdraw unutilized credit limit
withdraw: withdraw unutilized credit limitYou can withdraw from your approved credit by calling the withdraw method on the SDK.
try {
const response = await lasSdkInstance.withdraw({
interactionToken: "<interaction_token>",
});
// handle success response
} catch (e) {
// handle error
}The method returns a Promise. Go to the next step for success and error 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 dashboard = lasSdkInstance.service({
interactionToken: "<interaction_token>",
target: "<element id>"
});
const response = await dashboard.task;
// handle success response
} catch (e) {
// handle error
}Notice an additional parameter target is required. The sdk will find an element using getElementById(target) and open the servicing dashboard inside the element. Its left up to the host application to style the target element as preferred. Additionally, .service() method returns an object instead of a promise. The object contains
close(), a method that can be used to close the dashboardtask, a promise that is resolved when user intends to close/go-back from servicing dashboard. You may await on this promise to get SDK response
Step 4 - Handle response or error
If the user's intended action is completed, the Promise returned by the method will resolve with a success response. Else, if flow ends without action completion, it's resolved with an error.
Success responses
{
"intent": "LOAN_APPLICATION",
"userId": string,
"loanApplication": {
"status": "<ApplicationStatus>" // possible enum values below
}
}{
"intent": "PAYMENT",
"userId": string,
"payment": {
"status": <PaymentStatus>
}
}{
"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
When the Gateway UI gets closed without the user completing their intent, an instance of ScLoanError class is returned. ScLoanError is a sub-class of the Javascript Error. It also provides some information related to the interaction.
type ScLoanError = {
name: "ScLoanError",
code: "number", // enums below
message: "string", // enums below
data?: Object // intent specific data point
}// case where user drops off before applying
{
"errorName": "ScLoanError",
"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
{
"errorName": "ScLoanError",
"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. |
| 1032 | missing_permissions | User was not able to go through the flow because necessary browser permissions were not provided |
| 1033 | topup_triggered | User want to start a topup application. A new interaction id with intent LOAN_APPLICATION:TOP_UP needs to be used for topup applications. |
| 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.