Skip to content

Commit

Permalink
Fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
gau4sar committed Aug 11, 2022
2 parents eb510b4 + 1a5e96e commit 01833be
Show file tree
Hide file tree
Showing 26 changed files with 475 additions and 243 deletions.
66 changes: 37 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
## Ballerine KMP Integration example
## Ballerine Integration example

### Integration into Android
### Integration into Android version of KMP project

1. Create a Fragment or Activity which contains the WebView, it should load `https://[YOUR-SUBDOMAIN].dev.ballerine.app` (sanbox) or `https://[YOUR-SUBDOMAIN].ballerine.app` (prod) URL.
2. Set webViewSettings to the following WebView settings:
1. Generate JWT token in your backend which is required to access the Ballerine KYC flow APIs. Here is the link to the documentation on how to generate token.
2. Add gradle dependency for Ballerine webview in your app-level `build.gradle` file
```kt
webviewSettings.javaScriptEnabled = true
webviewSettings.domStorageEnabled = true
webviewSettings.allowFileAccess = true
dependencies {
implementation("com.github.gau4sar:Ballerine-android-webview:1.0.0")
}
```
3. Setup the WebViewClient and WebChromeClient. In WebChromeClient override the method `onShowFileChooser` the same way as it is implemented in `UserRegistrationFlowActivity`.
4. Add `onActivityResultListener` or `registerForActivityResult` to listen to the callback from the camera application:
We need to add the maven dependency for jitpack in settings.gradle
```kt
val resultCode = result.resultCode
val data = result.data

when (resultCode) {
Activity.RESULT_OK -> {
//Image Uri will not be null for RESULT_OK
val uri: Uri = data?.data!!

// Use Uri object instead of File to avoid storage permissions
filePathCallback!!.onReceiveValue(arrayOf(uri))
filePathCallback = null
}
ImagePicker.RESULT_ERROR -> {
Toast.makeText(this, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
}
else -> {
Toast.makeText(this, "Task Cancelled", Toast.LENGTH_SHORT).show()
}
allprojects {
repositories {
...
maven("https://jitpack.io")
}
}
```
5. Create a method that is checking for the finished state of the registration flow and saves the received results, see `checkWebViewUrl` method for more details.
3. Add `BallerineKYCFlowWebview` composable to your Activity/Fragment to initiate the web KYC verification flow process.
Then we receive the result of the callback function `onVerificationComplete` in your Activity/Fragment.
#### MainActivity.kt
```kt
BallerineKYCFlowWebView(
outputFileDirectory = outputFileDirectory,
cameraExecutorService = cameraExecutorService,
url = "$BALLERINE_WEB_URL?/b_t=$BALLERINE_API_TOKEN",
onVerificationComplete = { verificationResult ->

//Do something with the verification result

// Here we are just displaying the verification result as a Toast message
val toastMessage = "Idv result : ${verificationResult.idvResult} \n" +
"Status : ${verificationResult.status} \n" +
"Code : ${verificationResult.code}"

// Here we are just displaying the verification result as Text on the screen
Toast.makeText(this, toastMessage, Toast.LENGTH_LONG).show()
})
```
4. Once you have received the `VerificationResult` we can do further checks on the different values of the `VerificationResult` like `status`|`idvResult`|`code`|`isSync`.
(As shown above in Point 3)


### Integration into iOS
Expand All @@ -43,7 +51,7 @@
```swift
webView.addObserver(self, forKeyPath: "URL", options: .new, context: nil)
```
4. Implement observeValue forKeyPath method to handle URL updates:
4. Implement observeValue forKeyPath method to handle URL updates:
```swift
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard let key = change?[NSKeyValueChangeKey.newKey], let url = (key as? NSURL)?.absoluteString else { return }
Expand Down
29 changes: 24 additions & 5 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
compileSdk = 32
defaultConfig {
applicationId = "io.ballerine.kmp.example.android"
minSdk = 22
minSdk = 23
targetSdk = 32
versionCode = 1
versionName = "1.0"
Expand All @@ -17,12 +17,31 @@ android {
isMinifyEnabled = false
}
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.1.1"
}
}

dependencies {
implementation(project(":shared"))
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.0")
implementation("com.github.dhaval2404:imagepicker:2.1")

implementation("com.github.ballerine-io:ballerine-android-sdk:1.0.4")

implementation("androidx.appcompat:appcompat:1.5.0")

val compose_version = "1.1.1"

implementation ("androidx.core:core-ktx:1.8.0")
implementation ("androidx.activity:activity-compose:1.5.1")

implementation ("androidx.compose.ui:ui:$compose_version")
implementation ("androidx.compose.material:material:$compose_version")
implementation ("androidx.compose.ui:ui-tooling-preview:$compose_version")
androidTestImplementation ("androidx.compose.ui:ui-test-junit4:$compose_version")
debugImplementation ("androidx.compose.ui:ui-tooling:$compose_version")

implementation("com.google.accompanist:accompanist-permissions:0.26.0-alpha")
}
10 changes: 5 additions & 5 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
package="io.ballerine.kmp.example.android">
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>

<application
android:allowBackup="false"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".MainActivity"
android:exported="true">
Expand All @@ -16,9 +20,5 @@
</intent-filter>
</activity>

<activity
android:name=".BallerineKYCFlow"
android:exported="false">
</activity>
</application>
</manifest>

This file was deleted.

Loading

0 comments on commit 01833be

Please sign in to comment.