iOS Loans SDK Integration
Integrate smallcase Gateway Loans iOS SDK to allow your users to apply for loans, pay, withdraw, and much more
Step 1 - Install and Configure
A. Using Cocoapod
smallcase Gateway Loans iOS SDK comes bundled with our primary SDK. It is available as a public cocoa pod dependency.
To install the iOS SDK:
- add following code to your Podfile
- run
pod install
target '${CLIENT_PROJECT_NAME}' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Add the SCGateway pod dependency and replace ${FRAMEWORK_VERSION}
# with latest version code (example: 3.11.2).
pod 'SCGateway', '~> ${FRAMEWORK_VERSION}'
end
endB. Using Swift Package Manager
To install the iOS SDK as a Swift Package Dependency to your Xcode project:
i - Select File > Swift Packages > Add Package Dependency
ii - Enter the following repository URL:
https://github.com/smallcase/SCGatewayPackageIos
iii - Decide whether your project accepts updates to a package dependency up to the next major version or up to the next minor version.
Step 2- Environment Setup
To start using the loans SDK, set up the loans SDK with the desired configuration by calling the setup method which is available inside ScLoan class.
ScLoan.instance.setup (config: ScLoanConfig(
gatewayName : String,
environment : SCLoanEnvironment
)) { result in
switch result {
case .success(let response):
//Handle response
case .failure(let error):
//Handle the exception
}
}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 - ScLoanEnvironment.PRODUCTION
- 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.
ScLoan.instance.apply(presentingController: UIViewController, loanInfo: ScLoanInfo(interactionToken: String)) { result in
switch result {
case .success(let response):
//Handle response
case .failure(let error):
//Handle error
}
}
Params :
- ScLoanInfo :
- interactionToken (required): a unique string you received from the backend in the previous step.
Go to the next step for response handling
- interactionToken (required): a unique string you received from the backend in the previous step.
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 -
ScLoan.instance.pay(presentingController: UIViewController, loanInfo: ScLoanInfo(interactionToken: String)) { result in
switch result {
case .success(let response):
//Handle response
case .failure(let error):
//Handle error
}
}Params :
- ScLoanInfo :
- interactionToken (required): a unique string you received from the backend in the previous step.
Go to the next step for response handling
- interactionToken (required): a unique string you received from the backend in the previous step.
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.
ScLoan.instance.withdraw(presentingController: UIViewController, loanInfo: ScLoanInfo(interactionToken: String)) { result in
switch result {
case .success(let response):
//Handle response
case .failure(let error):
//Handle error
}
}Params :
- ScLoanInfo :
- interactionToken (required): a unique string you received from the backend in the previous step.
Go to the next step for response handling
- interactionToken (required): a unique string you received from the backend in the previous step.
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).
ScLoan.instance.service(presentingController: UIViewController, loanInfo: ScLoanInfo(interactionToken: String)) { result in
switch result {
case .success(let response):
//Handle response
case .failure(let error):
//Handle error
}
}Params :
- ScLoanInfo :
- interactionToken (required): a unique string you received from the backend in the previous step.
Go to the next step for response handling
- interactionToken (required): a unique string you received from the backend in the previous step.
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 iOS 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 iOS 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. |
| 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.