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](https://developers.google.com/pay/api/web/guides/tutorial.md.txt).

> [!WARNING]
> **Important:** In order for your app to be allowed to use Google Pay within Android WebView you need to [publish your App integration](https://developers.google.com/pay/api/android/guides/test-and-deploy/publish-your-integration.md.txt).

## User device requirements

- Google Play services version 25.18.30 or higher
- [Android Webview for Chrome](https://play.google.com/store/apps/details?id=com.google.android.webview) version 137 or higher

> [!NOTE]
> **Note** : If you are using a custom user agent, append the following String to the user agent of the `WebView`: `"GOOGLE_PAY_SUPPORTED"`. For example:
>
> ```kotlin
> val currentUserAgent = settings.userAgentString
> settings.userAgentString = "$currentUserAgent GOOGLE_PAY_SUPPORTED"
>   
> ```

> [!NOTE]
> **Note** : If the user device requirements are not met, the `IS_READY_TO_PAY` API will return `false`.

## 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

```groovy
dependencies {
    implementation 'androidx.webkit:webkit:1.14.0'
}
```

### Kotlin

```kotlin
dependencies {
    implementation("androidx.webkit:webkit:1.14.0")
}
```

### Version catalog

```toml
[versions]
webkit = "1.14.0"

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

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

```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

```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

```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);
}
      
```

> [!CAUTION]
> **Caution:** Using `shouldInterceptRequest` to intercept requests and use a 3rd party http client is not supported.

### 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.](https://developers.google.com/pay/api/android/guides/test-and-deploy/publish-your-integration.md.txt)