Account Linking
Good to know: account linking is useful if you wish to use AIS (Account Information Service) or skip authentication steps when initiating payments via the in-app payments module.

Adjust setMethodCallHandler

In order to call kevin. SDK account linking flow add a call handler in setMethodCallHandler method for each of your platforms:

Android

1
class MainActivity: FlutterActivity() {
2
private var flutterResult: Result? = null
3
4
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
5
6
//...
7
8
MethodChannel(
9
flutterEngine.dartExecutor.binaryMessenger,
10
"your.application.name/kevinChannel"
11
).setMethodCallHandler { call, result ->
12
when (call.method) {
13
"OpenKevinAccountLinking" -> {
14
try {
15
val state: String? = call.argument("state")
16
17
val accountLinkingConfiguration = AccountSessionConfiguration.Builder(state!!)
18
.setPreselectedCountry(KevinCountry.LITHUANIA)
19
.build()
20
val intent = Intent(this, AccountSessionActivity::class.java)
21
intent.putExtra(AccountSessionContract.CONFIGURATION_KEY, accountLinkingConfiguration)
22
startActivityForResult(intent, REQUEST_CODE_ACCOUNT_LINKING)
23
24
flutterResult = result
25
} catch (error: Exception) {
26
result.success("Failed")
27
}
28
}
29
else -> {
30
result.notImplemented()
31
}
32
}
33
}
34
}
35
36
companion object {
37
const val REQUEST_CODE_ACCOUNT_LINKING = 100
38
}
39
}
Copied!

iOS

1
@UIApplicationMain
2
@objc class AppDelegate: FlutterAppDelegate {
3
private var flutterResult: FlutterResult?
4
5
override func application(
6
_ application: UIApplication,
7
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
8
) -> Bool {
9
10
//...
11
12
kevinChannel.setMethodCallHandler({
13
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
14
if call.method == "OpenKevinAccountLinking" {
15
let state = args["state"] as! String
16
17
do {
18
KevinAccountLinkingSession.shared.delegate = self
19
try KevinAccountLinkingSession.shared.initiateAccountLinking(
20
configuration: KevinAccountLinkingSessionConfiguration.Builder(
21
state: state
22
)
23
.setPreselectedCountry(.lithuania)
24
.setCountryFilter([.lithuania, .latvia, .estonia])
25
.setSkipBankSelection(false)
26
.build()
27
)
28
29
flutterResult = result
30
} catch {
31
result("Failed")
32
}
33
} else {
34
result(FlutterMethodNotImplemented)
35
}
36
})
37
38
//...
39
}
40
}
Copied!
For additional information on available SDK configuration parameters, please refer to the corresponding platform-specific section of our documentation.

Handle SDK callbacks

To get results from kevin. SDK account linking flow you need to override platform-specific callbacks.

Android

Android should override onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
1
class MainActivity: FlutterActivity() {
2
3
//...
4
5
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
6
if (requestCode == REQUEST_CODE_ACCOUNT_LINKING) {
7
val result = data?.getParcelableExtra<SessionResult<AccountSessionResult>>(AccountSessionContract.RESULT_KEY)
8
when (result) {
9
is SessionResult.Success -> {
10
flutterResult?.success(result.value.authorizationCode)
11
}
12
is SessionResult.Canceled -> {
13
flutterResult?.success("Canceled")
14
}
15
is SessionResult.Failure -> {
16
flutterResult?.success("Failed")
17
}
18
}
19
} else {
20
flutterResult?.success("Failed")
21
}
22
}
23
}
Copied!

iOS

iOS handler should conform to KevinAccountLinkingSessionDelegate and override those methods:
1
@UIApplicationMain
2
@objc class AppDelegate: FlutterAppDelegate, KevinAccountLinkingSessionDelegate {
3
4
//...
5
6
func onKevinAccountLinkingStarted(controller: UINavigationController) {
7
flutterController?.present(controller, animated: true, completion: nil)
8
}
9
10
func onKevinAccountLinkingCanceled(error: Error?) {
11
flutterResult?("Failed")
12
}
13
14
func onKevinAccountLinkingSucceeded(authorizationCode: String, bank: ApiBank) {
15
flutterResult?(authorizationCode)
16
}
17
}
Copied!

Invoking account linking flow from Flutter code

1
class KevinRepository {
2
static const MethodChannel _channel = MethodChannel(
3
"your.application.name/kevinChannel",
4
);
5
6
Future<void> startAccountLinking(String state) async {
7
try {
8
final result = await _channel.invokeMethod(
9
"OpenKevinAccountLinking",
10
{
11
"state": state,
12
},
13
);
14
15
// TODO: Handle the result
16
} on PlatformException catch (e) {
17
debugPrint("Error: '${e.message}'.");
18
}
19
}
20
}
Copied!