Using Android WebView

Some businesses require the ability to embed their web checkout process in their mobile applications by using a WebView. This guide walks you through the steps needed to support Google Pay in your WebView after you completed the Google Pay Web integration.

User device requirements

  • Google Play services version 25.14.30 or higher
  • Chrome version 136 or higher

Required App changes

The Payment Request API is used to launch the Google Pay sheet when the web checkout process is embedded in an Android WebView. By default the Payment Request API will be disabled for WebView. The following changes to your app code are required:

Add (or update) build dependency:

Groovy

dependencies {
    implementation 'androidx.webkit:webkit:1.14.0-alpha01'
}

Kotlin

dependencies {
    implementation("androidx.webkit:webkit:1.14.0-alpha01")
}

Version catalog

[versions]
webkit = "1.14.0-alpha01"

[libraries]
androidx-ktx = { group = "androidx.webkit", name = "webkit", version.ref = "webkit" }

Add the following <queries> tags to your AndroidManifest.xml:

<queries>
  <intent>
    <action android:name="org.chromium.intent.action.PAY"/>
  </intent>
  <intent>
    <action android:name="org.chromium.intent.action.IS_READY_TO_PAY"/>
  </intent>
  <intent>
    <action android:name="org.chromium.intent.action.UPDATE_PAYMENT_DETAILS"/>
  </intent>
</queries>
    

Enable the Payment Request API for the WebView you use in your App.

Make sure to use the correct import statement for the code you are using.

Kotlin

import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;

AndroidView(
    factory = {
        // Update WebView settings to allow JavaScript and payment request
        settings.javaScriptEnabled = true
        WebView(it).apply {
            if (WebViewFeature.isFeatureSupported(
                    WebViewFeature.PAYMENT_REQUEST)) {
                WebSettingsCompat.setPaymentRequestEnabled(settings, true);
            }
        }
    },
    update = {it.loadUrl(url)
    }
)
      

Java

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();

// Update WebView settings to allow JavaScript and payment request
webSettings.setJavaScriptEnabled(true);
if (WebViewFeature.isFeatureSupported(
          WebViewFeature.PAYMENT_REQUEST)) {
    WebSettingsCompat.setPaymentRequestEnabled(webSettings, true);
}
      

Publish your integration

In order for your App to be allowed to use Google Pay within Android WebView, you must complete the publish your integration guide.

Early testing

The feature will be rolled out to 100% of the users using Chrome >= 136 by the end of May. If you want to test the feature right away, follow steps 2-6 in the WebView PaymentRequest Test Instructions.