Payment Initiation
Good to know: payment initiation is responsible for bank and card payment support.

Implement invocation function in native module

In order to configure kevin. SDK payment initiation 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 openKevinBankPayment(state: String, callback: Callback) {
10
try {
11
val paymentConfiguration = PaymentSessionConfiguration.Builder(id)
12
.setPaymentType(PaymentType.BANK)
13
.setPreselectedCountry(KevinCountry.LITHUANIA)
14
.build()
15
val intent = Intent(currentActivity, PaymentSessionActivity::class.java)
16
intent.putExtra(PaymentSessionContract.CONFIGURATION_KEY, paymentConfiguration)
17
currentActivity?.startActivityForResult(intent, REQUEST_CODE_PAYMENT, null)
18
this.callback = callback
19
} catch (error: Exception) {
20
callback("Failed", null)
21
}
22
}
23
24
companion object {
25
const val REQUEST_CODE_PAYMENT = 101
26
}
27
}
Copied!

iOS

KevinModule.swift
1
@objc(KevinModule)
2
class KevinModule: NSObject {
3
4
private var callback: RCTResponseSenderBlock?
5
6
//...
7
8
@objc(openKevinBankPayment::)
9
func openKevinBankPayment(id: String, callback: @escaping RCTResponseSenderBlock) -> Void {
10
do {
11
KevinPaymentSession.shared.delegate = self
12
try KevinPaymentSession.shared.initiatePayment(
13
configuration: KevinPaymentSessionConfiguration.Builder(
14
paymentId: id
15
)
16
.setPreselectedCountry(.lithuania)
17
.setSkipBankSelection(false)
18
.build()
19
)
20
21
self.callback = callback
22
} catch {
23
callback(["Failed", nil])
24
}
25
}
26
}
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(openKevinBankPayment:(NSString):(RCTResponseSenderBlock))
6
7
@end
Copied!
For additional information on available SDK parameters, please refer to the corresponding platform-specific section of our documentation.

Handle SDK callbacks

To get results from kevin. SDK payment initiation 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_PAYMENT) {
13
val result = data?.getParcelableExtra<SessionResult<PaymentSessionResult>>(PaymentSessionContract.RESULT_KEY)
14
when (result) {
15
is SessionResult.Success -> {
16
callback?.invoke(null, result.value.paymentId)
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 KevinPaymentSessionDelegate and override those methods:
KevinModule.swift
1
@objc(KevinModule)
2
class KevinModule: NSObject, KevinAccountLinkingSessionDelegate {
3
4
//...
5
6
func onKevinPaymentInitiationStarted(controller: UINavigationController) {
7
let rootViewController = UIApplication.shared.windows.first!.rootViewController
8
rootViewController?.present(controller, animated: true, completion: nil)
9
}
10
11
func onKevinPaymentCanceled(error: Error?) {
12
callback?(["Failed", nil])
13
}
14
15
func onKevinPaymentSucceeded(paymentId: String) {
16
callback?([nil, paymentId])
17
}
18
}
Copied!

Invoke payment initiation flow from React Native code

App.js
1
const {
2
KevinModule
3
} = NativeModules;
4
5
onKevinPaymentCallback = (error, paymentId) => {
6
if (error) {
7
console.error(`Error found! ${error}`);
8
} else {
9
console.log(`Payment id ${paymentId} returned`);
10
}
11
}
12
13
const App: () => Node = () => {
14
return (
15
<SafeAreaView>
16
<Button
17
onPress={ () => KevinModule.openKevinBankPayment("ID", onKevinPaymentCallback) }
18
title="Bank payment"
19
/>
20
</SafeAreaView>
21
);
22
};
Copied!