diff --git a/README.md b/README.md
index 5c7b7cb..b634a88 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,18 @@
-# Trustly Mobile Webview Example App
+# Trustly Mobile In-app Browser Example App
-This project is provided as an example of integration between a web app serving the Trustly UI and mobile apps that render that web app from a webview. Specifically, this example focuses on successfully handling OAuth and App-to-App bank authorization user flows. The repository can be used alongside Trustly's [Mobile App Webview tutorial](https://amer.developers.trustly.com/payments/docs/oauth-for-mobile-apps).
-
-## The Web App
-
-The `react-web-app` directory contains a simple React app that displays a "Pay with Trustly" button which launches the Lightbox. Instructions for running this app can be found in that directory's [ReadMe](./react-web-app/README.md).
+This project is provided as an example of integrating Trustly’s hosted UI within a mobile app using an in-app browser. It demonstrates how to handle OAuth and App-to-App bank authorization flows when the app simply opens a Trustly URL. The repository can be used alongside Trustly’s mobile App In-app Browser tutorial.
## The iOS App
-The `ios-app` directory contains a simple Swift app that renders a Webview of a given URL. With the above React app running, the iOS app can be pointed to the resulting URL to demonstrate the webview and secure-in-app-browser functionality required to successfully integrate the two applications. Additional instructions can be found in that directory's [ReadMe](./ios-app/README.md).
+The `ios-app` directory contains a simple Swift app that launches an OAuth web authentication session. Additional instructions can be found in Trustly’s mobile In-app Browser tutorial.
## The Android App
-The `android-app` directory contains a simple Kotlin app that renders a Webview of a given URL. With the above React app running, the Android app can be pointed to the resulting URL to demonstrate the webview and secure-in-app-browser functionality required to successfully integrate the two applications. Additional instructions can be found in that directory's [ReadMe](./android-app/README.md).
+The `android-app` directory contains a simple Android Kotlin app that launches an OAuth web authentication session. Additional instructions can be found in Trustly’s mobile In-app Browser tutorial.
# Contributing
You can participate in this project by submitting bugs and feature requests in the [Issues](https://github.com/TrustlyInc/trustly-webview-example/issues) tab.
-
-If you are interested in fixing issues and contributing directly to the code base, feel free to open a Pull Request with your changes. Please, make sure to fulfill our [Pull Request Template](https://github.com/TrustlyInc/trustly-webview-example/blob/main/.github/pull_request_template.md).
+If you are interested in fixing issues and contributing directly to the code base, feel free to open a Pull Request with your changes. Please, make sure to fulfill our [Pull Request Template](https://github.com/TrustlyInc/trustly-webview-example/blob/main/.github/pull_request_template.md).
\ No newline at end of file
diff --git a/android-app/.idea/AndroidProjectSystem.xml b/android-app/.idea/AndroidProjectSystem.xml
new file mode 100644
index 0000000..4a53bee
--- /dev/null
+++ b/android-app/.idea/AndroidProjectSystem.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app/.idea/compiler.xml b/android-app/.idea/compiler.xml
index b589d56..b86273d 100644
--- a/android-app/.idea/compiler.xml
+++ b/android-app/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/android-app/.idea/copilot.data.migration.agent.xml b/android-app/.idea/copilot.data.migration.agent.xml
new file mode 100644
index 0000000..4ea72a9
--- /dev/null
+++ b/android-app/.idea/copilot.data.migration.agent.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app/.idea/copilot.data.migration.ask.xml b/android-app/.idea/copilot.data.migration.ask.xml
new file mode 100644
index 0000000..7ef04e2
--- /dev/null
+++ b/android-app/.idea/copilot.data.migration.ask.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app/.idea/copilot.data.migration.ask2agent.xml b/android-app/.idea/copilot.data.migration.ask2agent.xml
new file mode 100644
index 0000000..1f2ea11
--- /dev/null
+++ b/android-app/.idea/copilot.data.migration.ask2agent.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app/.idea/copilot.data.migration.edit.xml b/android-app/.idea/copilot.data.migration.edit.xml
new file mode 100644
index 0000000..8648f94
--- /dev/null
+++ b/android-app/.idea/copilot.data.migration.edit.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app/.idea/deploymentTargetSelector.xml b/android-app/.idea/deploymentTargetSelector.xml
new file mode 100644
index 0000000..b268ef3
--- /dev/null
+++ b/android-app/.idea/deploymentTargetSelector.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app/.idea/gradle.xml b/android-app/.idea/gradle.xml
index a2d7c21..639c779 100644
--- a/android-app/.idea/gradle.xml
+++ b/android-app/.idea/gradle.xml
@@ -4,9 +4,9 @@
-
-
+
+
diff --git a/android-app/.idea/migrations.xml b/android-app/.idea/migrations.xml
new file mode 100644
index 0000000..f8051a6
--- /dev/null
+++ b/android-app/.idea/migrations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app/.idea/misc.xml b/android-app/.idea/misc.xml
index 773fe0f..b2c751a 100644
--- a/android-app/.idea/misc.xml
+++ b/android-app/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/android-app/.idea/runConfigurations.xml b/android-app/.idea/runConfigurations.xml
new file mode 100644
index 0000000..16660f1
--- /dev/null
+++ b/android-app/.idea/runConfigurations.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android-app/README.md b/android-app/README.md
index eef22f2..61951dd 100644
--- a/android-app/README.md
+++ b/android-app/README.md
@@ -7,70 +7,34 @@ This app demo has a propose to demonstrate how to implement the oauth authentica
`Chrome Custom Tabs` has no method to close itself, and this implementation is based on redirecting to previous Activity, by Intent flags, finishing the called Activity with registered scheme.
-
## Introduction
These are some example how to implement a sign-in on OAuth flow to use Trustly JavaScript SDK.
The code is using Kotlin language implementation.
-## WebClient
-
-There are two ways to create web clients for a WebView, `WebViewClient` and `WebChromeClient`.
+To open Trustly widget or lightbox we need to build an url with a `token`. This `token` is the `establish data` in `base 64` format.
-### WebViewClient implementation
+### Building url
+The base url is `https://sandbox.paywithmybank.com/frontend/mobile/establish`.
-Using `WebViewClient` you'll need to add a configuration in the `settings` property.
-Set the `javaScriptCanOpenWindowsAutomatically` property to true in order to enable the application to properly handle `window.open` events.
+`Establish data` is a dictionary with all parameters to create a transaction, to transform `establish data` to `base 64` format we should convert the dicitionary in a `json string` and after that create the `base 64` value.
```kotlin
- webView.settings.apply {
- javaScriptCanOpenWindowsAutomatically = true
- }
+val establishData = JSONUtils.getJsonFromParameters(getEstablishDataValues(this))
+val establishDataBase64 = JSONUtils.encodeStringToBase64(establishData)
```
-Using `WebViewClient` you can override many methods, but you need to implement the `shouldOverrideUrlLoading` method. This method determines what will happen when a URL is loaded in WebView.
-The example below is a simple implementation that calls the method which opens the CustomTabs.
+The `JSONUtils` class, is a custom class created by Trustly, you can check the content in the file `JSONUtils.kt`.
-```kotlin
- webView.webViewClient = object : WebViewClient() {
- override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
- val url = request.url.toString()
- if (url.contains(TrustlyConstants.OAUTH_LOGIN_PATH))
- launchUrl(this@WebViewClientActivity, url)
- return true
- }
- }
-```
-
-### WebChromeClient implementation
+In the url, you can send the `widget` parameter, to ask to open the `widget` if the `true`, or the lightbox, if `false`.
-Using `WebChromeClient` you'll need to create your own WebView, add some configuration in the `settings` property, and transport itself to a custom WebView.
-The example below explain more about those implementation. First you need to add both `javaScriptCanOpenWindowsAutomatically` and `setSupportMultipleWindows(true)`, they are needed to listen the `window.open` method.
+The complete url with `base 64` `token` and `widget` parameter as `true`.
```kotlin
- webView.settings.apply {
- javaScriptCanOpenWindowsAutomatically = true
- setSupportMultipleWindows(true)
- }
+https://sandbox.paywithmybank.com/frontend/mobile/establish?widget=true&token=eyJhY2Nlc3NJZCI6IkE0OEI3M0Y2OTRDNEM4RUU2MzA2IiwicGF5bWVudFR5cGUiOiJSZXRyaWV2YWwiLCJmbG93VHlwZSI6IiIsIm1ldGFkYXRhIjp7InNka0lPU1ZlcnNpb24iOiIzLjMuMCIsInVybFNjaGVtZSI6ImRlbW9hcHA6XC9cLyIsImNpZCI6IjEwRjYtNENFQy1NRVQwWERIUSIsInRoZW1lIjoiZGFyayJ9LCJzZXNzaW9uQ2lkIjoiMTBGNi00NDFBLU1FVDBCV0c0IiwicmV0dXJuVXJsIjoiZGVtb2FwcDpcL1wvIiwicmVxdWVzdFNpZ25hdHVyZSI6IkhUNW1WT3FCWGE4Wmx2Z1gyVVNtUGVMbnM1bz0iLCJ0aGVtZSI6ImRhcmsiLCJ2ZXJzaW9uIjoiMiIsImVudiI6InNhbmRib3giLCJjdXJyZW5jeSI6IlVTRCIsIm1lcmNoYW50SWQiOiIxMTAwMDU1MTQiLCJjYW5jZWxVcmwiOiJkZW1vYXBwOlwvXC8iLCJtZXJjaGFudFJlZmVyZW5jZSI6ImNhYzczZGY3LTUyYjQtNDdkNy04OWQzLTk2MjhkNGNmYjY1ZSIsImVudkhvc3QiOiIxOTIuMTY4LjAuMTMiLCJwYXltZW50UHJvdmlkZXJJZCI6IjIwMDAwNTUwMSIsImdycCI6IjE4Iiwid2lkZ2V0TG9hZGVkIjoidHJ1ZSIsImN1c3RvbWVyIjp7ImFkZHJlc3MiOnsiY291bnRyeSI6IlVTIn0sIm5hbWUiOiJKb2huIn0sImRldmljZVR5cGUiOiJtb2JpbGU6aW9zOm5hdGl2ZSIsImFtb3VudCI6IjEwLjAwIiwiZGVzY3JpcHRpb24iOiJGaXJzdCBEYXRhIE1vYmlsZSBUZXN0In0=
```
-This is the `WebChromeClient` implementation, using a custom WebView to transport the URL and than open it inside that.
-The `trustlyWebView` is an instance of the custom WebView, which has the same implementation of a `WebViewClient`.
-
-```kotlin
- webView.webChromeClient = object : WebChromeClient() {
- override fun onCreateWindow(view: WebView, isDialog: Boolean, isUserGesture: Boolean, resultMsg: Message): Boolean {
- return if (view.hitTestResult.type == 0) {
- //window.open
- webView.addView(trustlyWebView)
- val transport = resultMsg.obj as WebViewTransport
- transport.webView = trustlyWebView.webView
- resultMsg.sendToTarget()
- true
- } else false
- }
- }
-```
+After built Trustly url, now, you can open widget or lightbox with oAuth component.
### CustomTabsIntent
@@ -80,19 +44,23 @@ In your custom web view you need to create a CustomTabIntent to open the url:
```kotlin
private fun launchUrl(context: Context, url: String) {
val customTabsIntent = CustomTabsIntent.Builder().build()
+ customTabsIntent.intent.setPackage("com.android.chrome")
customTabsIntent.launchUrl(context, Uri.parse(url))
}
```
-### TrustlyWebChromeClientRedirectActivity and TrustlyWebViewClientRedirectActivity
+### RedirectActivity
-When the application receive some action for example `web-chrome-client-redirect`, or the name that you defined in `urlScheme`, it will call your target Activity with some flags, and reload it.
-The example below is from `TrustlyWebChromeClientRedirectActivity`
+When the application receive some action for example `in-app-browser-android`, or the name that you defined in `urlScheme`, it will call your target Activity with some flags, and reload it.
+We added a validation for in case the return information has no transaction data, for example in the app-to-app OAuth flow.
+The example below is from `RedirectActivity`
```kotlin
- Intent(this, WebChromeClientActivity::class.java).apply {
- addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
- }.run { startActivity(this) }
+ if (intent.extras != null && intent.data!!.getQueryParameter(STATUS_PARAM) != null) {
+ Intent(this, MainActivity::class.java).apply {
+ addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
+ }.run { startActivity(this) }
+ }
finish()
```
@@ -100,21 +68,13 @@ The example below is from `TrustlyWebChromeClientRedirectActivity`
```xml
-
+
-```
-
-### ProceedToChooseAccount
-
-Finally, in order to support a smooth user experience when an OAuth login authorization is completed and the user returns to the Lightbox, call this function using some code like this:
-
-```kotlin
- webView.loadUrl("javascript:window.Trustly.proceedToChooseAccount();")
```
\ No newline at end of file
diff --git a/android-app/app/build.gradle b/android-app/app/build.gradle
index 6b21ddc..64321c6 100644
--- a/android-app/app/build.gradle
+++ b/android-app/app/build.gradle
@@ -5,7 +5,7 @@ plugins {
android {
namespace 'net.trustly.inappbrowserandroid'
- compileSdk 33
+ compileSdk 36
defaultConfig {
applicationId "net.trustly.inappbrowserandroid"
@@ -33,11 +33,12 @@ android {
}
dependencies {
- implementation 'androidx.core:core-ktx:1.10.0'
- implementation 'androidx.appcompat:appcompat:1.6.1'
- implementation 'androidx.browser:browser:1.5.0'
- implementation 'com.google.android.material:material:1.8.0'
+ implementation 'androidx.core:core-ktx:1.17.0'
+ implementation 'androidx.appcompat:appcompat:1.7.1'
+ implementation 'androidx.browser:browser:1.9.0'
+ implementation 'com.google.android.material:material:1.13.0'
+ implementation 'com.google.code.gson:gson:2.13.2'
testImplementation 'junit:junit:4.13.2'
- androidTestImplementation 'androidx.test.ext:junit:1.1.5'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
+ androidTestImplementation 'androidx.test.ext:junit:1.3.0'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
}
\ No newline at end of file
diff --git a/android-app/app/src/main/AndroidManifest.xml b/android-app/app/src/main/AndroidManifest.xml
index 9be17b0..faa4802 100644
--- a/android-app/app/src/main/AndroidManifest.xml
+++ b/android-app/app/src/main/AndroidManifest.xml
@@ -23,15 +23,7 @@
-
-
-
@@ -39,26 +31,12 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
+ android:name=".InAppBrowserActivity"
+ android:exported="false" />
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/InAppBrowserActivity.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/InAppBrowserActivity.kt
new file mode 100644
index 0000000..d06ba6a
--- /dev/null
+++ b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/InAppBrowserActivity.kt
@@ -0,0 +1,68 @@
+package net.trustly.inappbrowserandroid
+
+import android.content.Context
+import android.content.Intent
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import androidx.browser.customtabs.CustomTabsIntent
+import androidx.core.net.toUri
+
+class InAppBrowserActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ val openWidget = intent.getBooleanExtra(OPEN_WIDGET, false)
+ val establishData = JSONUtils.getJsonFromParameters(getEstablishDataValues(this))
+ val establishDataBase64 = JSONUtils.encodeStringToBase64(establishData)
+ val url =
+ "https://sandbox.paywithmybank.com/frontend/mobile/establish?widget=$openWidget&token=$establishDataBase64"
+ launchUrl(this, url)
+ finish()
+ }
+
+ private fun getEstablishDataValues(context: Context): MutableMap {
+ val establishDataValues: MutableMap = HashMap()
+ establishDataValues["accessId"] = "ACCESS_ID"
+ establishDataValues["amount"] = "10.00"
+ establishDataValues["merchantId"] = "MERCHANT_ID"
+ establishDataValues["currency"] = "USD"
+ establishDataValues["merchantReference"] = "MERCHANT_REFERENCE"
+ establishDataValues["requestSignature"] = "REQUEST_SIGNATURE"
+ establishDataValues["paymentType"] = "Retrieval"
+ establishDataValues["env"] = "sandbox"
+ establishDataValues["grp"] = "GRP"
+ establishDataValues["paymentProviderId"] = "PAYMENT_PROVIDER_ID"
+ establishDataValues["description"] = "Android InAppBrowser"
+ establishDataValues["localUrl"] = "YOUR LOCAL URL WHEN `ENV` PROPERTY IS `LOCAL` (ex: https://192.168.0.30)"
+ establishDataValues["customer.name"] = "John Smith Android"
+ establishDataValues["customer.address.address1"] = "2000 Broadway Street"
+ establishDataValues["customer.address.city"] = "Redwood City"
+ establishDataValues["customer.address.state"] = "CA"
+ establishDataValues["customer.address.zip"] = "94063"
+ establishDataValues["customer.address.country"] = "US"
+ establishDataValues["customer.phone"] = "2145553434"
+ establishDataValues["customer.email"] = "jsmith@email.com"
+ establishDataValues["metadata.urlScheme"] = context.getString(R.string.url_scheme) + "://"
+ establishDataValues["cancelUrl"] = context.getString(R.string.url_scheme) + "://"
+ establishDataValues["returnUrl"] = context.getString(R.string.url_scheme) + "://"
+ return establishDataValues
+ }
+
+ private fun launchUrl(context: Context, url: String) {
+ val customTabsIntent = CustomTabsIntent.Builder().build()
+ customTabsIntent.intent.setPackage("com.android.chrome")
+ customTabsIntent.launchUrl(context, url.toUri())
+ }
+
+ companion object {
+
+ private const val OPEN_WIDGET = "OPEN_WIDGET"
+
+ fun startIntent(context: Context, openWidget: Boolean = false) =
+ Intent(context, InAppBrowserActivity::class.java)
+ .putExtra(OPEN_WIDGET, openWidget)
+
+ }
+
+}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/JSONUtils.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/JSONUtils.kt
new file mode 100644
index 0000000..ac4f4f2
--- /dev/null
+++ b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/JSONUtils.kt
@@ -0,0 +1,37 @@
+package net.trustly.inappbrowserandroid
+
+import android.util.Base64
+import com.google.gson.JsonObject
+import java.nio.charset.StandardCharsets
+
+object JSONUtils {
+
+ private const val SEPARATOR: String = "\\."
+
+ fun getJsonFromParameters(parameters: Map) =
+ buildJsonObjectSecond(parameters).toString()
+
+ private fun buildJsonObjectSecond(data: Map): JsonObject {
+ val json = JsonObject()
+ for ((key1, value) in data) {
+ val keys = key1.split(SEPARATOR.toRegex()).toTypedArray()
+ var current = json
+ for (i in keys.indices) {
+ val key = keys[i]
+ if (i == keys.size - 1) {
+ current.addProperty(key, value)
+ } else {
+ if (!current.has(key)) {
+ current.add(key, JsonObject())
+ }
+ current = current.getAsJsonObject(key)
+ }
+ }
+ }
+ return json
+ }
+
+ fun encodeStringToBase64(value: String): String =
+ Base64.encodeToString(value.toByteArray(StandardCharsets.UTF_8), Base64.DEFAULT)
+
+}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/MainActivity.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/MainActivity.kt
index f178b70..482c10e 100644
--- a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/MainActivity.kt
+++ b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/MainActivity.kt
@@ -1,11 +1,10 @@
package net.trustly.inappbrowserandroid
-import android.content.Intent
import android.os.Bundle
import android.widget.Button
+import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
-import net.trustly.inappbrowserandroid.webchromeclient.WebChromeClientActivity
-import net.trustly.inappbrowserandroid.webviewclient.WebViewClientActivity
+
class MainActivity : AppCompatActivity() {
@@ -13,15 +12,41 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
- val webViewClientButton = findViewById(R.id.webViewClientButton)
- webViewClientButton.setOnClickListener {
- startActivity(Intent(this, WebViewClientActivity::class.java))
+ val widgetButton = findViewById(R.id.widgetButton)
+ widgetButton.setOnClickListener {
+ startActivity(InAppBrowserActivity.startIntent(this, true))
+ }
+
+ val lightboxButton = findViewById(R.id.lightboxButton)
+ lightboxButton.setOnClickListener {
+ startActivity(InAppBrowserActivity.startIntent(this))
}
- val webViewChromeButton = findViewById(R.id.webViewChromeButton)
- webViewChromeButton.setOnClickListener {
- startActivity(Intent(this, WebChromeClientActivity::class.java))
+ if (intent.hasExtra(ESTABLISH_DATA)) {
+ val establishDataValues =
+ intent.getSerializableExtra(ESTABLISH_DATA) as Map
+ if (establishDataValues.contains(STATUS_PARAM)) {
+ val status = establishDataValues[STATUS_PARAM].equals(STATUS_SUCCESS)
+ if (status) showDialogResult(true)
+ else showDialogResult(false)
+ }
}
}
+ private fun showDialogResult(result: Boolean) {
+ val message = if (result) "Authorization successful!" else "Authorization failed!"
+ val builder: AlertDialog.Builder = AlertDialog.Builder(this)
+ builder.setMessage(message).setTitle("Authorization")
+ .setNeutralButton("OK") { dialog, _ -> dialog.dismiss() }
+ builder.create().show()
+ }
+
+ companion object {
+
+ const val ESTABLISH_DATA = "establishData"
+ const val STATUS_PARAM = "status"
+ const val STATUS_SUCCESS = "2"
+
+ }
+
}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/RedirectActivity.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/RedirectActivity.kt
new file mode 100644
index 0000000..54ee910
--- /dev/null
+++ b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/RedirectActivity.kt
@@ -0,0 +1,42 @@
+package net.trustly.inappbrowserandroid
+
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import java.io.Serializable
+
+class RedirectActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ if (intent.extras != null && intent.data!!.getQueryParameter(STATUS_PARAM) != null) {
+ val transactionDetail = getTransactionDetailFromUri(intent.data!!)
+ Intent(this, MainActivity::class.java).apply {
+ addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
+ }.putExtra(MainActivity.ESTABLISH_DATA, transactionDetail as Serializable)
+ .run { startActivity(this) }
+ }
+ finish()
+ }
+
+ private fun getTransactionDetailFromUri(appLinkData: Uri): Map {
+ return mapOf(
+ Pair(TRANSACTION_ID_PARAM, appLinkData.getQueryParameter(TRANSACTION_ID_PARAM)!!),
+ Pair(TRANSACTION_TYPE_PARAM, appLinkData.getQueryParameter(TRANSACTION_TYPE_PARAM)!!),
+ Pair(PANEL_PARAM, appLinkData.getQueryParameter(PANEL_PARAM)!!),
+ Pair(PAYMENT_TYPE_PARAM, appLinkData.getQueryParameter(PAYMENT_TYPE_PARAM)!!),
+ Pair(STATUS_PARAM, appLinkData.getQueryParameter(STATUS_PARAM)!!)
+ )
+ }
+
+ companion object {
+ const val TRANSACTION_ID_PARAM = "transactionId"
+ const val TRANSACTION_TYPE_PARAM = "transactionType"
+ const val PANEL_PARAM = "panel"
+ const val PAYMENT_TYPE_PARAM = "payment.paymentType"
+ const val STATUS_PARAM = "status"
+ }
+
+}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/TrustlyConstants.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/TrustlyConstants.kt
deleted file mode 100644
index a76d1b0..0000000
--- a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/TrustlyConstants.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package net.trustly.inappbrowserandroid
-
-object TrustlyConstants {
-
- const val TRUSTLY_URL = "http://localhost:3000?integrationContext=InAppBrowser&urlScheme="
- const val OAUTH_LOGIN_PATH = "/oauth/login"
- const val TRUSTLY_PROCEED_TO_CHOOSE_ACCOUNT_SCRIPT = "javascript:window.Trustly.proceedToChooseAccount();"
-
-}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/WebViewBaseActivity.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/WebViewBaseActivity.kt
deleted file mode 100644
index ddab8b8..0000000
--- a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/WebViewBaseActivity.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package net.trustly.inappbrowserandroid
-
-import android.os.Bundle
-import android.webkit.WebView
-import androidx.appcompat.app.AppCompatActivity
-
-abstract class WebViewBaseActivity : AppCompatActivity() {
-
- lateinit var webView: WebView
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_webviewbase)
-
- webView = findViewById(R.id.webView)
- }
-
-}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webchromeclient/TrustlyWebChromeClientRedirectActivity.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webchromeclient/TrustlyWebChromeClientRedirectActivity.kt
deleted file mode 100644
index 0fef99b..0000000
--- a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webchromeclient/TrustlyWebChromeClientRedirectActivity.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package net.trustly.inappbrowserandroid.webchromeclient
-
-import android.content.Intent
-import android.os.Bundle
-import androidx.appcompat.app.AppCompatActivity
-
-class TrustlyWebChromeClientRedirectActivity : AppCompatActivity() {
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- Intent(this, WebChromeClientActivity::class.java).apply {
- addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
- }.run { startActivity(this) }
- finish()
- }
-
-}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webchromeclient/TrustlyWebView.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webchromeclient/TrustlyWebView.kt
deleted file mode 100644
index bff2a82..0000000
--- a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webchromeclient/TrustlyWebView.kt
+++ /dev/null
@@ -1,71 +0,0 @@
-package net.trustly.inappbrowserandroid.webchromeclient
-
-import android.annotation.SuppressLint
-import android.content.Context
-import android.net.Uri
-import android.util.AttributeSet
-import android.view.ViewGroup
-import android.webkit.WebResourceRequest
-import android.webkit.WebView
-import android.webkit.WebViewClient
-import android.widget.LinearLayout
-import android.widget.RelativeLayout
-import androidx.browser.customtabs.CustomTabsIntent
-import net.trustly.inappbrowserandroid.TrustlyConstants
-
-@SuppressLint("SetJavaScriptEnabled")
-class TrustlyWebView : LinearLayout {
-
- var webView: WebView = WebView(context!!)
-
- constructor(context: Context?) : super(context, null)
-
- constructor(context: Context?, attrs: AttributeSet) : super(context, attrs, 0)
-
- constructor(context: Context?, attrs: AttributeSet, defStyleAttr: Int) : super(
- context,
- attrs,
- defStyleAttr
- )
-
- init {
- with(webView) {
- this.settings.apply {
- javaScriptEnabled = true
- domStorageEnabled = true
- }
-
- this.layoutParams =
- RelativeLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT
- )
-
- this.webViewClient = object : WebViewClient() {
- override fun shouldOverrideUrlLoading(
- view: WebView,
- request: WebResourceRequest
- ): Boolean {
- val url = request.url.toString()
- if (url.contains(TrustlyConstants.OAUTH_LOGIN_PATH))
- launchUrl(view.context, url)
-
- // This return depends on your context, visit the Android documentation to learn more about it.
- // https://developer.android.com/reference/android/webkit/WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView,%20java.lang.String)
- return true
- }
- }
- }
- }
-
- fun proceedToChooseAccount() {
- webView.loadUrl(TrustlyConstants.TRUSTLY_PROCEED_TO_CHOOSE_ACCOUNT_SCRIPT)
- }
-
- private fun launchUrl(context: Context, url: String) {
- val customTabsIntent = CustomTabsIntent.Builder().build()
- customTabsIntent.intent.setPackage("com.android.chrome")
- customTabsIntent.launchUrl(context, Uri.parse(url))
- }
-
-}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webchromeclient/WebChromeClientActivity.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webchromeclient/WebChromeClientActivity.kt
deleted file mode 100644
index 902169c..0000000
--- a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webchromeclient/WebChromeClientActivity.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-package net.trustly.inappbrowserandroid.webchromeclient
-
-import android.annotation.SuppressLint
-import android.os.Bundle
-import android.os.Message
-import android.webkit.WebChromeClient
-import android.webkit.WebView
-import android.webkit.WebView.WebViewTransport
-import net.trustly.inappbrowserandroid.TrustlyConstants
-import net.trustly.inappbrowserandroid.WebViewBaseActivity
-
-class WebChromeClientActivity : WebViewBaseActivity() {
-
- private lateinit var trustlyWebView: TrustlyWebView
-
- @SuppressLint("SetJavaScriptEnabled")
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- trustlyWebView = TrustlyWebView(this)
-
- webView.settings.apply {
- javaScriptCanOpenWindowsAutomatically = true
- javaScriptEnabled = true
- domStorageEnabled = true
- setSupportMultipleWindows(true)
- }
-
- webView.webChromeClient = object : WebChromeClient() {
- override fun onCreateWindow(
- view: WebView,
- isDialog: Boolean,
- isUserGesture: Boolean,
- resultMsg: Message
- ): Boolean {
- return if (view.hitTestResult.type == 0) {
- //window.open
- webView.addView(trustlyWebView)
- val transport = resultMsg.obj as WebViewTransport
- transport.webView = trustlyWebView.webView
- resultMsg.sendToTarget()
- true
- } else false
- }
- }
- webView.loadUrl(TrustlyConstants.TRUSTLY_URL + "web-chrome-client-redirect")
- }
-
- override fun onResume() {
- super.onResume()
-
- trustlyWebView.proceedToChooseAccount()
- }
-
-}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webviewclient/TrustlyWebViewClientRedirectActivity.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webviewclient/TrustlyWebViewClientRedirectActivity.kt
deleted file mode 100644
index f529482..0000000
--- a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webviewclient/TrustlyWebViewClientRedirectActivity.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package net.trustly.inappbrowserandroid.webviewclient
-
-import android.content.Intent
-import android.os.Bundle
-import androidx.appcompat.app.AppCompatActivity
-
-class TrustlyWebViewClientRedirectActivity : AppCompatActivity() {
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- Intent(this, WebViewClientActivity::class.java).apply {
- addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
- }.run { startActivity(this) }
- finish()
- }
-
-}
\ No newline at end of file
diff --git a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webviewclient/WebViewClientActivity.kt b/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webviewclient/WebViewClientActivity.kt
deleted file mode 100644
index 730687f..0000000
--- a/android-app/app/src/main/java/net/trustly/inappbrowserandroid/webviewclient/WebViewClientActivity.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-package net.trustly.inappbrowserandroid.webviewclient
-
-import android.annotation.SuppressLint
-import android.content.Context
-import android.net.Uri
-import android.os.Bundle
-import android.webkit.WebResourceRequest
-import android.webkit.WebView
-import android.webkit.WebViewClient
-import androidx.browser.customtabs.CustomTabsIntent
-import net.trustly.inappbrowserandroid.TrustlyConstants
-import net.trustly.inappbrowserandroid.WebViewBaseActivity
-
-class WebViewClientActivity : WebViewBaseActivity() {
-
- @SuppressLint("SetJavaScriptEnabled")
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- webView.settings.apply {
- javaScriptEnabled = true
- domStorageEnabled = true
- javaScriptCanOpenWindowsAutomatically = true
- }
-
- webView.webViewClient = object : WebViewClient() {
- override fun shouldOverrideUrlLoading(
- view: WebView,
- request: WebResourceRequest
- ): Boolean {
- val url = request.url.toString()
- if (url.contains(TrustlyConstants.OAUTH_LOGIN_PATH))
- launchUrl(this@WebViewClientActivity, url)
-
- // This return depends on your context, visit the Android documentation to learn more about it.
- // https://developer.android.com/reference/android/webkit/WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView,%20java.lang.String)
- return true
- }
- }
- webView.loadUrl(TrustlyConstants.TRUSTLY_URL + "web-view-client-redirect")
- }
-
- override fun onResume() {
- super.onResume()
-
- webView.loadUrl(TrustlyConstants.TRUSTLY_PROCEED_TO_CHOOSE_ACCOUNT_SCRIPT)
- }
-
- private fun launchUrl(context: Context, url: String) {
- val customTabsIntent = CustomTabsIntent.Builder().build()
- customTabsIntent.intent.setPackage("com.android.chrome")
- customTabsIntent.launchUrl(context, Uri.parse(url))
- }
-
-}
\ No newline at end of file
diff --git a/android-app/app/src/main/res/drawable/globex.png b/android-app/app/src/main/res/drawable/globex.png
new file mode 100644
index 0000000..ab98bbd
Binary files /dev/null and b/android-app/app/src/main/res/drawable/globex.png differ
diff --git a/android-app/app/src/main/res/layout/activity_main.xml b/android-app/app/src/main/res/layout/activity_main.xml
index 4a9f518..d1286e0 100644
--- a/android-app/app/src/main/res/layout/activity_main.xml
+++ b/android-app/app/src/main/res/layout/activity_main.xml
@@ -4,24 +4,33 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
+
+
+ app:layout_constraintTop_toBottomOf="@+id/widgetButton" />
\ No newline at end of file
diff --git a/android-app/app/src/main/res/values-night/themes.xml b/android-app/app/src/main/res/values-night/themes.xml
index a9bd1a3..bf83df1 100644
--- a/android-app/app/src/main/res/values-night/themes.xml
+++ b/android-app/app/src/main/res/values-night/themes.xml
@@ -2,8 +2,8 @@