Use the Web SDK with a mobile webview

To ensure correct app-to-app flows when using the Web SDK with a mobile app's webview, implement the onBankRedirect callback.

When using the Web SDK alongside a mobile app’s webview, configure and listen for the onBankRedirect callback.

Instead of automatically navigating to the bank page, you should use this callback to pass the redirection URL back to your app so it can open the link in an external browser. This ensures that app-to-app flows work correctly.

How onBankRedirect works

When you provide an onBankRedirect callback to the Web SDK, the SDK will not perform a direct redirect to the bank page.

Instead, it calls your onBankRedirect function and pass the bank’s redirect URL as an argument. Your app opens that URL in the device’s browser.

Below are example implementations for iOS and Android. For both iOS and Android, you must ensure that you open the URL exactly as you receive it, without altering it.

iOS

On iOS, you can pass this URL from the webview to native code using WKScriptMessageHandler.

Swift (native code)

class ViewController: UIViewController, WKScriptMessageHandler {
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        if message.name == "openLink", let urlStr = message.body as? String {
            if let url = URL(string: urlStr) {
                UIApplication.shared.open(url)
            }
        }
    }
}

// Setup
let config = WKWebViewConfiguration()
config.userContentController.add(self, name: "openLink")
let webView = WKWebView(frame: .zero, configuration: config)

JavaScript inside the webview

onBankRedirect(redirectUri) {
    window.webkit.messageHandlers.openLink.postMessage(redirectUri);
}

Android

Java/Kotlin

class WebAppInterface(val context: Context) {  
    @JavascriptInterface  
    fun openLink(uri: String) {  
        try {  
            val intent = Intent(ACTION_VIEW, Uri.parse(uri)).apply {  
                // The URL should either launch directly in a non-browser app (if it's  
                // the default), or in the disambiguation dialog.  
                addCategory(CATEGORY_BROWSABLE)  
                flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {  
                    FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_REQUIRE_NON_BROWSER  
                } else {  
                    FLAG_ACTIVITY_NEW_TASK  
                }  
            }  
            context.startActivity(intent)  
        } catch (e: ActivityNotFoundException) {  
            // Only browser apps are available, or a browser is the default.  
            // So you will have to open the website  
            val intent = Intent(ACTION_VIEW, Uri.parse(uri))  
            context.startActivity(intent)  
        }  
    }  
}

webView.settings.javaScriptEnabled = true  
webView.addJavascriptInterface(WebAppInterface(this), "Android")

JavaScript inside WebView

function requestOpenLink(url) {  
    Android.openLink(url); // Calls native method  
}