Flutter Integration
Integrate smallcase Gateway Flutter SDK to allow your users to transact in stocks, ETFs & smallcases, and much more
Step 1 - Install and Configure
Gateway Flutter SDK is available on pub.dev. To install the SDK
- Add the scgateway_flutter_plugin/scloans as a dependency of your app.
flutter pub add scgateway_flutter_plugin
flutter pub add scloans // for loans
- Run the following code from the terminal
flutter pub get
- The plugin exports all its methods with one default import. Import it using
import 'package:scgateway_flutter_plugin.dart';
import 'package:scloans.dart'; //in case of loans sdk
A. Android
Configure smallcase Gateway Android SDK via AndroidManifest.xml :
<activity android:name="com.smallcase.gateway.screens.transaction.activity.TransactionProcessActivity"
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"
/>
</intent-filter>
</activity>
<activity android:name="com.smallcase.gateway.screens.common.RedirectActivity"
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="scgatewayredirect"
/>
</intent-filter>
</activity>
Replace "{YOUR_HOST_NAME}" with unique host name which is given to every integration partners.
Add this to your app-level build.gradle file.
// Include maven repository url and authentication details
repositories {
maven {
url "https://artifactory.smallcase.com/artifactory/SCGateway"
}
}
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
smallcase Gateway iOS SDK is available as a private cocoa pod dependency.
add following code to your Podfile and run pod install
within the directory containing the Podfile.
# default source for all other pods
source 'https://cdn.cocoapods.org'
# private podspec for smallcase (only for versions < 2.2.0)
source 'https://github.com/smallcase/cocoapodspecs.git'
Step 2- Environment Setup
To start using gateway setup the gateway SDK with the desired configuration by calling setConfigEnvironment method which is available as a static method of ScgatewayFlutterPlugin class.
ScgatewayFlutterPlugin.setConfigEnvironment(
enviroment, // should always be `GatewayEnvironment.PRODUCTION`
gateway,
leprechaun_mode,
brokers,
isAmoEnabled
)
Params :
- environment (required): This defines the Url environment to which all the gateway apis would point to Possible values - GatewayEnvironment.PRODUCTION
- gateway (required): This is a unique name given to every gateway consumer
Eg : moneycontrol - leprachaun_mode (required): For Testing purpose only. Default value is false
- brokers (required): If you want to support only certain brokers, default all brokers are shown if empty list is passed
Possible values - aliceblue, angelbroking, axis, dhan, edelweiss, fisdom, fivepaisa, fundzbazar, groww, hdfc, icici, iifl, kite, kotak, motilal, trustline & upstox - isAmoEnabled (optional): To control after-market order placement.
Note
Call setConfigEnvironment every time there is any change in the setup.
setConfigEnvironment must be the first method to be fired.If setup is not called all other methods will not work.
Step 3- Initialise user session
User initialization starts a session between the distributor and the gateway. Whenever there is a change in user session, this method needs to be triggered.
ScgatewayFlutterPlugin.initGateway(authToken);
Params :
authToken (required): JWT with the information of user signed using a shared secret between smallcase API and gateway backend. Learn more about using JWT
Step 4- Triggering SDK Method
A. For transactional flows
Transactional flows are those user journeys where interaction with their broker is required to complete the flow. For example - placing stocks / smallcase order, importing user holdings, connecting broker account to your app.
smallcase Gateway assigns a unique transactionId for each such user intent. The transactionId is a short-lived identifier that represents a single user interaction session.
i - Create transactionId
The transactionId can be created by making a server-to-server request to create transactionId API with relevant order config. The API call must be made from your backend (it is critical that secrets not be used on the app).
So whenever your user wants to perform transaction action, your app must call your backed with relevant order config, which in turn will hit smallcase Gateway's create transactionId API and respond back with transactionId.
Create transactionId API reference -
ii - Call triggerTransaction SDK method
To start the actual transactional flow, call the triggerGatewayTransaction method.
ScgatewayFlutterPlugin.triggerGatewayTransaction(transactionId)
Params :
transactionId (required): a unique string that you received from backend in the previous step.
B. For Non-transactional flows
i - Call relevant SDK method
Description | SDK Method |
---|---|
Broker account opening | triggerLeadGen |
Logout from smallcase platform | logoutUser |
(More details in Non-transactional flow section)
Step 4 - Save order response
Order response is shared in the onSucess()
block of the triggerTransaction
method as well as over API webhooks
Check response structure here
In case the transaction is not placed with the broker, any error is available in the onError
block
A list of transaction errors is available here
Non-transactional flows
Note
In order to use any of the following methods, the gateway session should be initialized with relevant user data.
Broker Account Opening
To trigger account opening flow call triggerLeadGen
method.
ScgatewayFlutterPlugin.leadGen(name, email, contact);
Params
name (optional): Name of the User.
email (optional): Email of the User.
contact (optional): Contact number of the User.
And for all relevant keys passed to the triggerLeadGen
method, the SDK will pre-populate relevant user data in the signup flow, ensuring a smooth user experience.
Logout from smallcase platform
This method is particularly useful when your users want to switch accounts for the same broker. When triggered, this method will make sure that the user gets logged out from the smallcase platform. So that the next time user interacts with smallcase Gateway, they will be asked to log in again.
Note
This flow is only available for connected users.
ScgatewayFlutterPlugin.logoutUser();
Show Orders
This will display a list of all the orders that a user recently placed. This includes pending, successful, and failed orders.
ScgatewayFlutterPlugin.showOrders();
Updated 4 months ago