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

Adjust setMethodCallHandler

To call kevin. SDK payment initiation flow add call handler in setMethodCallHandler method for each of your platforms:

Android

1
class MainActivity: FlutterActivity() {
2
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
3
4
//...
5
6
MethodChannel(
7
flutterEngine.dartExecutor.binaryMessenger,
8
"your.application.name/kevinChannel"
9
).setMethodCallHandler { call, result ->
10
when (call.method) {
11
"OpenKevinBankPayment" -> {
12
try {
13
val id: String? = call.argument("id")
14
15
val paymentConfiguration = PaymentSessionConfiguration.Builder(id!!)
16
.setPaymentType(PaymentType.BANK)
17
.setPreselectedCountry(KevinCountry.LITHUANIA)
18
.build()
19
20
val intent = Intent(this, PaymentSessionActivity::class.java)
21
intent.putExtra(PaymentSessionContract.CONFIGURATION_KEY, paymentConfiguration)
22
startActivityForResult(intent, REQUEST_CODE_PAYMENT)
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_PAYMENT = 101
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 == "OpenKevinBankPayment" {
15
let id = args["id"] as! String
16
17
do {
18
KevinPaymentSession.shared.delegate = self
19
try KevinPaymentSession.shared.initiatePayment(
20
configuration: KevinPaymentSessionConfiguration.Builder(
21
paymentId: id
22
)
23
.setPreselectedCountry(.lithuania)
24
.setSkipBankSelection(false)
25
.build()
26
)
27
28
flutterResult = result
29
} catch {
30
result("Failed")
31
}
32
} else {
33
result(FlutterMethodNotImplemented)
34
}
35
})
36
37
//...
38
}
39
}
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 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_PAYMENT) {
7
val result = data?.getParcelableExtra<SessionResult<PaymentSessionResult>>(PaymentSessionContract.RESULT_KEY)
8
when (result) {
9
is SessionResult.Success -> {
10
flutterResult?.success(result.value.paymentId)
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 KevinPaymentSessionDelegate and override those methods:
1
@UIApplicationMain
2
@objc class AppDelegate: FlutterAppDelegate, KevinPaymentSessionDelegate {
3
4
//...
5
6
func onKevinPaymentInitiationStarted(controller: UINavigationController) {
7
flutterController?.present(controller, animated: true, completion: nil)
8
}
9
10
func onKevinPaymentCanceled(error: Error?) {
11
flutterResult?("Failed")
12
}
13
14
func onKevinPaymentSucceeded(paymentId: String) {
15
flutterResult?(paymentId)
16
}
17
}
Copied!

Invoke payment initiation flow from Flutter

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