Skip to content

Commit 1065a2f

Browse files
authored
Merge pull request #17 from klippa-app/development
0.2.5 Release
2 parents f386909 + f641dea commit 1065a2f

File tree

8 files changed

+203
-175
lines changed

8 files changed

+203
-175
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.2.5
2+
3+
* Bump Android SDK version to 0.7.0
4+
* Bump iOS SDK version to 0.5.11
5+
* Added `retryThreshold` to `IdentityBuilder` which is to set the threshold the user can attempt a task before a contact support button is shown.
6+
17
## 0.2.4
28

39
* Bump Android SDK version to 0.6.5

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ The reject reason object has a code and a message, the used codes are:
8888
- E_MISSING_SESSION_TOKEN
8989
- E_CANCELED
9090
- E_UNKNOWN_ERROR
91+
- E_CONTACT_SUPPORT_PRESSED
9192

9293
## How to use a specific version of the SDK?
9394

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ android {
5353

5454
dependencies {
5555
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
56-
def klippaIdentityVerificationVersion = project.hasProperty('klippaIdentityVerificationVersion') ? project.klippaIdentityVerificationVersion : "0.6.5"
56+
def klippaIdentityVerificationVersion = project.hasProperty('klippaIdentityVerificationVersion') ? project.klippaIdentityVerificationVersion : "0.7.0"
5757
implementation "com.klippa:identity_verification:$klippaIdentityVerificationVersion"
5858
}
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,179 @@
11
package com.klippa.identity_verification.klippa_identity_verification_sdk
22

3-
import android.util.Log
4-
import com.klippa.identity_verification.model.KlippaError
5-
import com.klippa.identity_verification.modules.base.IdentityBuilder
6-
import com.klippa.identity_verification.modules.base.IdentityBuilder.IdentityBuilderListener
3+
import android.content.Intent
4+
import com.klippa.identity_verification.modules.base.IdentitySession
5+
import com.klippa.identity_verification.modules.base.IdentitySessionResultCode
76
import io.flutter.embedding.engine.plugins.FlutterPlugin
87
import io.flutter.embedding.engine.plugins.activity.ActivityAware
98
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
109
import io.flutter.plugin.common.MethodCall
1110
import io.flutter.plugin.common.MethodChannel
1211
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
1312
import io.flutter.plugin.common.MethodChannel.Result
13+
import io.flutter.plugin.common.PluginRegistry
1414

1515
/** KlippaIdentityVerificationSdkPlugin */
16-
class KlippaIdentityVerificationSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
17-
/// The MethodChannel that will the communication between Flutter and native Android
18-
///
19-
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
20-
/// when the Flutter Engine is detached from the Activity
21-
private lateinit var channel : MethodChannel
22-
23-
private var activityPluginBinding : ActivityPluginBinding? = null
24-
25-
companion object {
26-
private const val E_ACTIVITY_DOES_NOT_EXIST = "E_ACTIVITY_DOES_NOT_EXIST"
27-
private const val E_MISSING_SESSION_TOKEN = "E_MISSING_SESSION_TOKEN"
28-
private const val E_FAILED_TO_SHOW_SESSION = "E_FAILED_TO_SHOW_SESSION"
29-
private const val E_CANCELED = "E_CANCELED"
30-
private const val E_SUPPORT_PRESSED = "E_CONTACT_SUPPORT_PRESSED"
31-
}
32-
33-
34-
private val listener = object: IdentityBuilderListener {
35-
override fun identityVerificationFinished() {
36-
val resultMap = HashMap<String, Any>()
37-
resultHandler?.success(resultMap)
16+
class KlippaIdentityVerificationSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
17+
PluginRegistry.ActivityResultListener {
18+
/// The MethodChannel that will the communication between Flutter and native Android
19+
///
20+
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
21+
/// when the Flutter Engine is detached from the Activity
22+
private lateinit var channel: MethodChannel
23+
24+
private var activityPluginBinding: ActivityPluginBinding? = null
25+
26+
companion object {
27+
private const val E_ACTIVITY_DOES_NOT_EXIST = "E_ACTIVITY_DOES_NOT_EXIST"
28+
private const val E_MISSING_SESSION_TOKEN = "E_MISSING_SESSION_TOKEN"
29+
private const val E_FAILED_TO_SHOW_SESSION = "E_FAILED_TO_SHOW_SESSION"
30+
private const val E_CANCELED = "E_CANCELED"
31+
private const val E_SUPPORT_PRESSED = "E_CONTACT_SUPPORT_PRESSED"
32+
33+
private const val REQUEST_CODE = 99991801
3834
}
3935

40-
override fun identityVerificationCanceled(error: KlippaError) {
41-
val err = when (error) {
42-
KlippaError.InsufficientPermissions -> "Insufficient permissions"
43-
KlippaError.InvalidSessionToken -> "Invalid session token"
44-
KlippaError.UserCanceled -> "User canceled session"
45-
KlippaError.NoInternetConnection -> "No internet connection"
46-
KlippaError.DeviceDoesNotSupportNFC -> "Device doesn't support NFC"
47-
KlippaError.DeviceNFCDisabled -> "Device NFC is disabled"
48-
}
49-
50-
resultHandler?.error(E_CANCELED, err, null)
36+
private var resultHandler: Result? = null
37+
38+
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
39+
channel =
40+
MethodChannel(flutterPluginBinding.binaryMessenger, "klippa_identity_verification_sdk")
41+
channel.setMethodCallHandler(this)
5142
}
5243

53-
override fun identityVerificationContactSupportPressed() {
54-
resultHandler?.error(E_SUPPORT_PRESSED, "Contact support pressed", null)
44+
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
45+
this.activityPluginBinding = binding
46+
binding.addActivityResultListener(this)
5547
}
56-
}
5748

49+
override fun onDetachedFromActivityForConfigChanges() {
50+
this.activityPluginBinding = null
51+
}
5852

59-
private var resultHandler : Result? = null
53+
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
54+
this.activityPluginBinding = binding
55+
binding.addActivityResultListener(this)
56+
}
6057

61-
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
62-
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "klippa_identity_verification_sdk")
63-
channel.setMethodCallHandler(this)
64-
}
58+
override fun onDetachedFromActivity() {
59+
this.activityPluginBinding = null
60+
}
6561

66-
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
67-
this.activityPluginBinding = binding
68-
}
62+
override fun onMethodCall(call: MethodCall, result: Result) {
63+
if (call.method == "startSession") {
64+
startSession(call, result)
65+
} else {
66+
result.notImplemented()
67+
}
68+
}
6969

70-
override fun onDetachedFromActivityForConfigChanges() {
71-
this.activityPluginBinding = null
72-
}
70+
private fun startSession(call: MethodCall, result: Result) {
71+
val activity = activityPluginBinding?.activity ?: kotlin.run {
72+
result.error(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist", null)
73+
return
74+
}
7375

74-
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
75-
this.activityPluginBinding = binding
76-
}
76+
try {
77+
if (!call.hasArgument("SessionToken")) {
78+
result.error(E_MISSING_SESSION_TOKEN, "Missing session token", null)
79+
return
80+
}
81+
82+
val token = call.argument<String>("SessionToken")!!
83+
84+
val identitySession = IdentitySession(
85+
token
86+
)
87+
88+
call.argument<String>("Language")?.let { language ->
89+
when (language) {
90+
"KIVLanguage.English" -> {
91+
identitySession.language = IdentitySession.KIVLanguage.English
92+
}
93+
"KIVLanguage.Dutch" -> {
94+
identitySession.language = IdentitySession.KIVLanguage.Dutch
95+
}
96+
"KIVLanguage.Spanish" -> {
97+
identitySession.language = IdentitySession.KIVLanguage.Spanish
98+
}
99+
}
100+
}
101+
102+
call.argument<Boolean>("HasIntroScreen")?.let { hasIntroScreen ->
103+
identitySession.hasIntroScreen = hasIntroScreen
104+
}
105+
106+
call.argument<Boolean>("HasSuccessScreen")?.let { hasSuccessScreen ->
107+
identitySession.hasSuccessScreen = hasSuccessScreen
108+
}
109+
110+
call.argument<Boolean>("IsDebug")?.let { isDebug ->
111+
identitySession.isDebug = isDebug
112+
}
113+
114+
call.argument<List<String>>("VerifyIncludeList")?.let { include ->
115+
identitySession.kivIncludeList = include
116+
}
117+
118+
call.argument<List<String>>("VerifyExcludeList")?.let { exclude ->
119+
identitySession.kivExcludeList = exclude
120+
}
121+
122+
call.argument<Int>("RetryThreshold")?.let { retryThreshold ->
123+
identitySession.retryThreshold = retryThreshold
124+
}
125+
126+
val intent = identitySession.getIntent(activity)
127+
resultHandler = result
128+
activity.startActivityForResult(intent, REQUEST_CODE)
129+
} catch (e: Exception) {
130+
result.error(
131+
E_FAILED_TO_SHOW_SESSION,
132+
"Could not launch identity verification session",
133+
e.message + "\n" + e.stackTrace
134+
)
135+
}
136+
}
137+
138+
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
139+
channel.setMethodCallHandler(null)
140+
}
141+
142+
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
143+
val mappedResultCode = IdentitySessionResultCode.mapResultCode(resultCode)
144+
when (mappedResultCode) {
145+
IdentitySessionResultCode.FINISHED -> identityVerificationFinished()
146+
IdentitySessionResultCode.CONTACT_SUPPORT_PRESSED -> identityVerificationContactSupportPressed(
147+
mappedResultCode.message()
148+
)
149+
150+
IdentitySessionResultCode.INSUFFICIENT_PERMISSIONS,
151+
IdentitySessionResultCode.INVALID_SESSION_TOKEN,
152+
IdentitySessionResultCode.USER_CANCELED,
153+
IdentitySessionResultCode.NO_INTERNET_CONNECTION,
154+
IdentitySessionResultCode.DEVICE_DOES_NOT_SUPPORT_NFC,
155+
IdentitySessionResultCode.DEVICE_NFC_DISABLED,
156+
IdentitySessionResultCode.TAKING_PHOTO_FAILED,
157+
IdentitySessionResultCode.UNKNOWN_ERROR -> identityVerificationCanceled(mappedResultCode.message())
158+
}
159+
160+
return true
161+
}
77162

78-
override fun onDetachedFromActivity() {
79-
this.activityPluginBinding = null
80-
}
81163

82-
override fun onMethodCall(call: MethodCall, result: Result) {
83-
if (call.method == "startSession") {
84-
startSession(call, result)
85-
} else {
86-
result.notImplemented()
164+
private fun identityVerificationFinished() {
165+
val resultMap = HashMap<String, Any>()
166+
resultHandler?.success(resultMap)
87167
}
88-
}
89168

90-
private fun startSession(call: MethodCall, result: Result) {
91-
if (activityPluginBinding == null) {
92-
result.error(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist", null)
93-
return
169+
170+
private fun identityVerificationCanceled(message: String) {
171+
resultHandler?.error(E_CANCELED, message, null)
94172
}
95173

96-
try {
97-
if (!call.hasArgument("SessionToken")) {
98-
result.error(E_MISSING_SESSION_TOKEN, "Missing session token", null)
99-
return
100-
}
101-
102-
val builder = IdentityBuilder(listener, call.argument<String>("SessionToken")!!)
103-
104-
if (call.hasArgument("Language")) {
105-
val language = call.argument<String>("Language")!!
106-
if (language == "KIVLanguage.English") {
107-
builder.language = IdentityBuilder.KIVLanguage.English
108-
} else if (language == "KIVLanguage.Dutch") {
109-
builder.language = IdentityBuilder.KIVLanguage.Dutch
110-
} else if (language == "KIVLanguage.Spanish") {
111-
builder.language = IdentityBuilder.KIVLanguage.Spanish
112-
}
113-
}
114-
115-
if (call.hasArgument("HasIntroScreen")) {
116-
val hasIntroScreen = call.argument<Boolean>("HasIntroScreen")!!
117-
builder.hasIntroScreen = hasIntroScreen
118-
}
119-
120-
if (call.hasArgument("HasSuccessScreen")) {
121-
val hasSuccessScreen = call.argument<Boolean>("HasSuccessScreen")!!
122-
builder.hasSuccessScreen = hasSuccessScreen
123-
}
124-
125-
if (call.hasArgument("IsDebug")) {
126-
val isDebug = call.argument<Boolean>("IsDebug")!!
127-
builder.isDebug = isDebug
128-
}
129-
130-
if (call.hasArgument("VerifyIncludeList")) {
131-
val include = call.argument<List<String>>("VerifyIncludeList")!!
132-
builder.kivIncludeList = include
133-
}
134-
135-
if (call.hasArgument("VerifyExcludeList")) {
136-
val exclude = call.argument<List<String>>("VerifyExcludeList")!!
137-
builder.kivExcludeList = exclude
138-
}
139-
140-
val intent = builder.getIntent(activityPluginBinding!!.activity)
141-
resultHandler = result
142-
activityPluginBinding?.activity?.startActivity(intent)
143-
} catch (e: Exception) {
144-
result.error(E_FAILED_TO_SHOW_SESSION, "Could not launch identity verification session", e.message + "\n" + Log.getStackTraceString(e))
174+
private fun identityVerificationContactSupportPressed(message: String) {
175+
resultHandler?.error(E_SUPPORT_PRESSED, message, null)
145176
}
146-
}
147177

148-
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
149-
channel.setMethodCallHandler(null)
150-
}
151178

152179
}

0 commit comments

Comments
 (0)