Android WebView allows web content to be displayed inside an Android app, enabling Samsung Pay Web Checkout to run within the app interface. When used in a mobile app, the Web Checkout follows the usual mobile payment flow while running in WebView mode and invoking the Samsung Wallet app for authentication or card selection.
Because WebView disables certain browser capabilities by default and does not automatically handle deep links, a few additional configurations are required to ensure the payment flow works correctly:
Launch the Samsung Wallet app with deep links.
When the Web Checkout flow needs to switch to the Samsung Wallet app for authentication, the SDK uses a Samsung Pay-specific deep link (e.g., samsungpay://). WebView does not handle these links by default, so you must override shouldOverrideUrlLoading() to detect and launch them using an Intent.
Enable JavaScript and DOM storage.
The Web Checkout SDK requires JavaScript and DOM storage. Both are disabled by default in WebView, and you must enable them through WebSettings. For more information, see WebSettings.
The following code snippet is an example of how to configure the WebView integration to function with Web Checkout:
import android.webkit.WebView
import android.webkit.WebViewClient
import android.content.Intent
import android.content.ActivityNotFoundException
companion object {
private const val SAMSUNG_PAY_URL_PREFIX: String = "samsungpay"
private const val SAMSUNG_APP_STORE_URL: String = "samsungapps://ProductDetail/com.samsung.android.spay"
}
private lateinit var webView: WebView
webView.settings.run {
javaScriptEnabled = true
domStorageEnabled = true
}
webView.webViewClient = object: WebViewClient() {
override fun shouldOverrideUrlLoading(
view: WebView,
request: WebResourceRequest
): Boolean {
// Get URL from WebResourceRequest
val url = request.url.toString()
// Add below if statement to check if URL is Samsung Pay or Samsung App Store deep link
if (url.startsWith(SAMSUNG_PAY_URL_PREFIX) || url.startsWith(SAMSUNG_APP_STORE_URL), ignoreCase = false) {
try {
val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
startActivity(intent)
} catch (e: ActivityNotFoundException) {
// Exception occurs if the Samsung Wallet app is not installed
// Go to install the Samsung Wallet app from market
val installIntent = Intent.parseUri("samsungapps://ProductDetail/com.samsung.android.spay", Intent.URI_INTENT_SCHEME)
installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(installIntent)
}
// return true causes the URL not to be loaded in WebView
return true
}
// Remaining part of the shouldOverrideUrlLoading method code
// return false when you want to load URL automatically by WebView
return false
}
}
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
developer.samsung.com, .samsung.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
Samsung Electronics
.samsung.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
Samsung Electronics
developer.samsung.com, google.account.samsung.com
Preferences Submitted
You have successfully updated your cookie preferences.