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.

Implement invocation function in native module

In order to configure kevin. SDK account linking module, you will need to add configurations into the native platform specific components.

Android

KevinModule.kt
1
class KevinModule internal constructor(context: ReactApplicationContext?) :
2
ReactContextBaseJavaModule(context) {
3
4
private var callback: Callback? = null
5
6
//...
7
8
@ReactMethod
9
fun openKevinAccountLinking(state: String, callback: Callback) {
10
try {
11
val accountLinkingConfiguration = AccountSessionConfiguration.Builder(state)
12
.setPreselectedCountry(KevinCountry.LITHUANIA)
13
.build()
14
val intent = Intent(currentActivity, AccountSessionActivity::class.java)
15
intent.putExtra(AccountSessionContract.CONFIGURATION_KEY, accountLinkingConfiguration)
16
currentActivity?.startActivityForResult(intent, REQUEST_CODE_ACCOUNT_LINKING, null)
17
this.callback = callback
18
} catch (error: Exception) {
19
callback("Failed", null)
20
}
21
}
22
23
companion object {
24
const val REQUEST_CODE_ACCOUNT_LINKING = 100
25
}
26
}
Copied!

iOS

KevinModule.swift
1
@objc(KevinModule)
2
class KevinModule: NSObject {
3
4
private var callback: RCTResponseSenderBlock?
5
6
//...
7
8
@objc(openKevinAccountLinking::)
9
func openKevinAccountLinking(state: String, callback: @escaping RCTResponseSenderBlock) -> Void {
10
do {
11
KevinAccountLinkingSession.shared.delegate = self
12
try KevinAccountLinkingSession.shared.initiateAccountLinking(
13
configuration: KevinAccountLinkingSessionConfiguration.Builder(
14
state: state
15
)
16
.setPreselectedCountry(.lithuania)
17
.setCountryFilter([.lithuania, .latvia, .estonia])
18
.setSkipBankSelection(false)
19
.build()
20
)
21
22
self.callback = callback
23
} catch {
24
callback(["Failed", nil])
25
}
26
}
27
}
Copied!
Additionally add this function declaration to your native module bridge:
KevinModuleBridge.m
1
@interface RCT_EXTERN_MODULE(KevinModule, NSObject)
2
3
//...
4
5
RCT_EXTERN_METHOD(openKevinAccountLinking:(NSString):(RCTResponseSenderBlock))
6
7
@end
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 handler module should conform to ActivityEventListener and should override onActivityResult(activity: Activity?, requestCode: Int, resultCode: Int, data: Intent?)
KevinModule.kt
1
class KevinModule internal constructor(context: ReactApplicationContext?) :
2
ReactContextBaseJavaModule(context), ActivityEventListener {
3
4
//...
5
6
override fun onActivityResult(
7
activity: Activity?,
8
requestCode: Int,
9
resultCode: Int,
10
data: Intent?
11
) {
12
if (requestCode == REQUEST_CODE_ACCOUNT_LINKING) {
13
val result = data?.getParcelableExtra<SessionResult<AccountSessionResult>>(AccountSessionContract.RESULT_KEY)
14
when (result) {
15
is SessionResult.Success -> {
16
callback?.invoke(null, result.value.authorizationCode)
17
}
18
is SessionResult.Canceled -> {
19
callback?.invoke("Canceled", null)
20
}
21
is SessionResult.Failure -> {
22
callback?.invoke("Failed", null)
23
}
24
}
25
}
26
}
27
}
Copied!

iOS

iOS handler module should conform to KevinAccountLinkingSessionDelegate and override those methods:
KevinModule.swift
1
@objc(KevinModule)
2
class KevinModule: NSObject, KevinAccountLinkingSessionDelegate {
3
4
//...
5
6
func onKevinAccountLinkingStarted(controller: UINavigationController) {
7
let rootViewController = UIApplication.shared.windows.first!.rootViewController
8
rootViewController?.present(controller, animated: true, completion: nil)
9
}
10
11
func onKevinAccountLinkingCanceled(error: Error?) {
12
callback?(["Failed", nil])
13
}
14
15
func onKevinAccountLinkingSucceeded(authorizationCode: String, bank: ApiBank) {
16
callback?([nil, authorizationCode])
17
}
18
}
Copied!

Invoking account linking flow from React Native code

App.js
1
const {
2
KevinModule
3
} = NativeModules;
4
5
onKevinAccountLinkingCallback = (error, authCode) => {
6
if (error) {
7
console.error(`Error found! ${error}`);
8
} else {
9
console.log(`Authorization code ${authCode} returned`);
10
}
11
}
12
13
const App: () => Node = () => {
14
return (
15
<SafeAreaView>
16
<Button
17
onPress={ () => KevinModule.openKevinAccountLinking("STATE", onKevinAccountLinkingCallback) }
18
title="Account linking"
19
/>
20
</SafeAreaView>
21
);
22
};
Copied!