Does your Android App embed an online checkout course of through the use of a WebView?
We’re glad to announce that Google Pay is now supported inside Android WebView. This characteristic is on the market in WebView beginning with model 137.
How does Google Pay inside Android WebView work?
The answer makes use of the Fee Request API which permits launching Android fee apps when the web site is embedded within a WebView.
Beginning with Google Play Companies 25.18.30 (accessible immediately), Google Pay will set off the native fee sheet which implies person system tokens might be accessible for facilitation when triggered from inside a WebView.
What adjustments are required for my App?
Because the Fee Request API might be disabled by default for WebView, the next easy adjustments must be carried out:
Add (or replace) construct dependency:
androidx.webkit:webkit:1.14.0
Kotlin
Add the next queries
tags to your AndroidManifest.xml:
Allow the Fee Request API for the WebView you employ in your App. Be certain to make use of the proper import assertion. No different Google Pay particular adjustments are wanted.
Kotlin (Compose):
import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;
AndroidView(
manufacturing facility = {
WebView(it).apply {
// Replace WebView settings to permit JavaScript and fee request
settings.javaScriptEnabled = true
if (WebViewFeature.isFeatureSupported(
WebViewFeature.PAYMENT_REQUEST)) {
WebSettingsCompat.setPaymentRequestEnabled(settings, true);
}
}
},
replace = {
it.loadUrl(url)
}
)
Kotlin
import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;
WebView webView = findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
// Replace WebView settings to permit JavaScript and fee request
webSettings.setJavaScriptEnabled(true);
if (WebViewFeature.isFeatureSupported(WebViewFeature.PAYMENT_REQUEST)) {
WebSettingsCompat.setPaymentRequestEnabled(webSettings, true);
}
Java
An accepted Android app integration
Unlock seamless funds in your Android App
Supporting Google Pay inside Android WebView permits you to supply Google Pay to your Android customers when embedding your net checkout in your app. For extra help together with your implementation, register to the Google Pay & Pockets Console to create a assist ticket. As well as, you may be part of the developer neighborhood within the #funds channel on Discord.
Observe @GooglePayDevs on X for future updates. When you’ve got questions, tag @GooglePayDevs and embody #AskGooglePayDevs in your tweets.