Flutter
Installing the SDK
In your Flutter project directory:
flutter pub add knotapi_flutter
Importing the SDK
Import knotapi
import 'package:knotapi_flutter/knotapi_flutter.dart';
import 'package:knotapi_flutter/knotapi_configuration.dart';
Create a session
Then, Create a Session to retrieve a session_id
. We recommend saving this session_id
for future debugging and logging in development.
Open Card On File Switcher
_knotapiFlutterPlugin.openCardOnFileSwitcher(KnotConfiguration(
sessionId: SESSION_ID,
clientId: CLIENT_ID,
environment: ENVIRONMENT,
));
Expected behavior
It's expected that your integration with Knot will retrieve and pass a new
session_id
into the SDK on each initialization.
Switch a Card
After a user authenticates to a merchant, you will receive the AUTHENTICATED
webhook indicating that it is time to switch the card. Immediately upon receiving this webhook, make a call to the Switch Card endpoint.
Opening With Specific Merchants
If you decide to use Get Merchants to retrieve a list of merchants, list them in your app, and then open the SDK with a specific merchant, you can do so by passing a merchant ID in the session instance as an array of numbers. More in Retrieving & Listing Merchants. The merchant ID is the same across all environments.
Single Merchant ID
If a single merchant ID or merchant name is provided, the user will be sent directly to that merchant's login experience in the SDK.
Multiple Merchant IDs (Not Recommended)
If multiple merchant IDs are provided, the user will see a list of only those merchants to select from. It is not recommended that you provide a long list of merchants in order to remove a few, but rather "hide" certain merchants that you desire from your Customer Dashboard.
_knotapiFlutterPlugin.openCardOnFileSwitcher(KnotConfiguration(
sessionId: SESSION_ID,
clientId: CLIENT_ID,
environment: ENVIRONMENT,
merchantIds: [44]
));
Opening With an Entry Point
In your app's user experience, you may choose to integrate Knot in one or multiple places (e.g. from different tabs or screens). How users behave when interacting with Knot from each of these "entry points" may vary and it will be useful for you to be able to differentiate these groups of users by entry point in order to assess the value of each entry point. You can provide a value for the entry point in the session instance when you open the SDK. This value will be returned in the AUTHENTICATED
webhook.
_knotapiFlutterPlugin.openCardOnFileSwitcher(KnotConfiguration(
sessionId: SESSION_ID,
clientId: CLIENT_ID,
environment: ENVIRONMENT,
entryPoint: "onBoarding",
));
Opening with Categories and Search
Users are presented with a list of merchants in the SDK (unless you provide a single merchant as described above). Along with the list is a set of categories and search experience. Each of these components is visible to users by defalt (as set in Knot's backend), however, you can choose to remove either of them by setting setUseCategories: false
and setUseSearch: false
. This is not recommended.
_knotapiFlutterPlugin.openCardOnFileSwitcher(KnotConfiguration(
sessionId: SESSION_ID,
clientId: CLIENT_ID,
environment: ENVIRONMENT,
setUseCategories: true,
setUseSearch: true,
))
Testing in Development
To test a user's lifecycle through the SDK in the Development environment, you can use the following credentials when authenticating to a merchant:
username/email: user_good; password: pass_good
A full list of credentials useful in testing various merchant login scenarios can be found here.
Events
Events provide your application with real time feedback and can be used to build in-app functionality or for logging purposes.
import 'dart:async';
import 'package:knotapi_flutter/events.dart';
onSuccess
This event is called when a user successfully logged in to the merchant and their card was switched. It two string arguments containing the product (type
) and name of the merchant (merchant
).
StreamSubscription<KnotSuccess>? _streamSuccess;
void initState() {
super.initState();
_streamSuccess = KnotapiFlutter.onSuccess.listen(_onSuccess);
}
void _onSuccess (KnotSuccess event) {
String eventName = event.eventName;
String type = event.type;
String merchant = event.merchant;
print("eventName: $eventName, type: $type, merchant: $merchant");
}
onError
This event is called when an error occurs during SDK initialization or when a card switch is unsuccessful. It takes three string arguments containing the product (type
), error code (errorCode
), and error message (message
).
StreamSubscription<KnotError>? _streamError;
void initState() {
super.initState();
_streamError = KnotapiFlutter.onError.listen(_onError);
}
void _onError (KnotError event) {
String eventName = event.eventName;
String type = event.type;
String errorMessage = event.errorMessage;
String errorCode = event.errorCode;
print("eventName: $eventName, type: $type, errorCode: $errorCode, errorMessage: $errorMessage");
}
onExit
This event is called when a user closes the SDK. It takes one string argument containing the product (type
).
StreamSubscription<KnotExit>? _streamExit;
void initState() {
super.initState();
_streamExit = KnotapiFlutter.onExit.listen(_onExit);
}
void _onExit (KnotExit event) {
String eventName = event.eventName;
String type = event.type;
print("eventName: $eventName, type: $type");
}
onEvent
This event is called when certain events occur in the SDK. With this callback, you will be able to understand how a user is progressing through their lifecycle of authenticating to a merchant. This event takes three four arguments containing the product (type
), event name (event
), task id (taskId
) and merchant name (merchant
).
void _onError (KnotError event) {
String eventName = event.eventName;
String type = event.type;
String name = event.event;
String taskId = event.taskId;
String merchantName = event.merchant;
print("eventName: $eventName, type: $type, event: $name, taskId: $taskId, merchant: $merchantName");
}
Events
Event | Description |
---|---|
refresh session request | When the session used to initialize the SDK needs to be refreshed. |
merchant clicked | When a user clicks on a merchant from the merchant list. |
login started | When a user submits their credentials to login to the merchant. |
login success (Deprecated) | When a user successfully logs in to the merchant. |
authenticated | When a user successfully logs in to the merchant. |
require otp | When a user needs to enter an OTP code to login to the merchant. |
Updated 3 months ago