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
Copy class KevinModule internal constructor (context: ReactApplicationContext ?) :
ReactContextBaseJavaModule (context) {
private var callback: Callback ? = null
//...
@ReactMethod
fun openKevinAccountLinking (state: String , callback: Callback ) {
try {
val accountLinkingConfiguration = AccountSessionConfiguration. Builder (state)
. setPreselectedCountry (KevinCountry.LITHUANIA)
. build ()
val intent = Intent (currentActivity, AccountSessionActivity:: class .java)
intent. putExtra (AccountSessionContract.CONFIGURATION_KEY, accountLinkingConfiguration)
currentActivity?. startActivityForResult (intent, REQUEST_CODE_ACCOUNT_LINKING, null )
this .callback = callback
} catch (error: Exception ) {
callback ( "Failed" , null )
}
}
companion object {
const val REQUEST_CODE_ACCOUNT_LINKING = 100
}
}
iOS
Copy @objc ( KevinModule )
class KevinModule : NSObject {
private var callback: RCTResponseSenderBlock ?
//...
@objc ( openKevinAccountLinking:: )
func openKevinAccountLinking ( state : String , callback : @escaping RCTResponseSenderBlock) -> Void {
do {
KevinAccountLinkingSession.shared.delegate = self
try KevinAccountLinkingSession.shared. initiateAccountLinking (
configuration : KevinAccountLinkingSessionConfiguration.Builder (
state : state
)
.setPreselectedCountry ( .lithuania )
.setCountryFilter ( [.lithuania, .latvia, .estonia] )
.setSkipBankSelection ( false )
.build ()
)
self.callback = callback
} catch {
callback ( [ "Failed" , nil ] )
}
}
}
Additionally add this function declaration to your native module bridge:
Copy @interface RCT_EXTERN_MODULE(KevinModule, NSObject)
//...
RCT_EXTERN_METHOD(openKevinAccountLinking:(NSString):(RCTResponseSenderBlock))
@end
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?)
Copy class KevinModule internal constructor (context: ReactApplicationContext ?) :
ReactContextBaseJavaModule (context), ActivityEventListener {
//...
override fun onActivityResult (
activity: Activity ?,
requestCode: Int ,
resultCode: Int ,
data : Intent ?
) {
if (requestCode == REQUEST_CODE_ACCOUNT_LINKING) {
val result = data?.getParcelableExtra<SessionResult<AccountSessionResult>>(AccountSessionContract.RESULT_KEY)
when (result) {
is SessionResult.Success -> {
callback?. invoke ( null , result. value .authorizationCode)
}
is SessionResult.Canceled -> {
callback?. invoke ( "Canceled" , null )
}
is SessionResult.Failure -> {
callback?. invoke ( "Failed" , null )
}
}
}
}
}
iOS
iOS handler module should conform to KevinAccountLinkingSessionDelegate
and override those methods:
Copy @objc ( KevinModule )
class KevinModule : NSObject , KevinAccountLinkingSessionDelegate {
//...
func onKevinAccountLinkingStarted ( controller : UINavigationController) {
let rootViewController = UIApplication.shared.windows. first ! .rootViewController
rootViewController ? . present ( controller, animated : true , completion : nil )
}
func onKevinAccountLinkingCanceled ( error : Error ? ) {
callback ? ([ "Failed" , nil ])
}
func onKevinAccountLinkingSucceeded ( authorizationCode : String , bank : ApiBank) {
callback ? ([ nil , authorizationCode])
}
}
Invoking account linking flow from React Native code
Copy const {
KevinModule
} = NativeModules;
onKevinAccountLinkingCallback = (error , authCode) => {
if (error) {
console .error ( `Error found! ${ error } ` );
} else {
console .log ( `Authorization code ${ authCode } returned` );
}
}
const App : () => Node = () => {
return (
< SafeAreaView >
< Button
onPress = { () => KevinModule .openKevinAccountLinking ( "STATE" , onKevinAccountLinkingCallback) }
title = "Account linking"
/>
</ SafeAreaView >
);
};
Last updated 9 months ago