Adding support for Google Pay within Android WebView

Google Pay support within Android WebView is now available, starting with WebView version 137 and Play Services 25.18.30, allowing users to utilize the native Google Pay payment sheet within embedded web checkout processes.

Does your Android App embed a web checkout process by using a WebView?

We are happy to announce that Google Pay is now supported within Android WebView. This feature is available in WebView starting with version 137.


How does Google Pay within Android WebView work?

The solution uses the Payment Request API which allows launching Android payment apps when the website is embedded inside of a WebView.

Starting with Google Play Services 25.18.30 (available today), Google Pay will trigger the native payment sheet which means user device tokens will be available for facilitation when triggered from within a WebView.


What changes are required for my App?

Since the Payment Request API will be disabled by default for WebView, the following simple changes need to be implemented:

Add (or update) build dependency:

androidx.webkit:webkit:1.14.0-rc01

Kotlin

The stable version of 1.14.0 follows beginning of June

Add the following queries tags to your AndroidManifest.xml:

<!-- Allow Chromium defined actions PAY, IS_READY_TO_PAY, UPDATE_PAYMENT_DETAILS to be initiated in your Android App or SDK
-->
<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>

Kotlin

Enable the Payment Request API for the WebView you use in your App. Make sure to use the correct import statement. No other Google Pay specific changes are needed.

Kotlin (Compose):

import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature; AndroidView( factory = { WebView(it).apply { // Update WebView settings to allow JavaScript and payment request settings.javaScriptEnabled = true if (WebViewFeature.isFeatureSupported( WebViewFeature.PAYMENT_REQUEST)) { WebSettingsCompat.setPaymentRequestEnabled(settings, true); } } }, update = { 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(); // Update WebView settings to allow JavaScript and payment request
webSettings.setJavaScriptEnabled(true);
if (WebViewFeature.isFeatureSupported(WebViewFeature.PAYMENT_REQUEST)) { WebSettingsCompat.setPaymentRequestEnabled(webSettings, true);
}

Java

An approved Android app integration

An approved Android app integration

Unlock seamless payments in your Android App

Supporting Google Pay within Android WebView allows you to offer Google Pay to your Android users when embedding your web checkout in your app. For more assistance with your implementation, sign in to the Google Pay & Wallet Console to create a support ticket. In addition, you can join the developer community in the #payments channel on Discord.

Follow @GooglePayDevs on X for future updates. If you have questions, tag @GooglePayDevs and include #AskGooglePayDevs in your tweets.

Lasă un răspuns

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *

Fill out this field
Fill out this field
Te rog să introduci o adresă de email validă.
You need to agree with the terms to proceed

Sarghy Design
Prezentare generală a confidențialității

Acest site utilizează cookie-uri pentru a vă oferi cea mai bună experiență de utilizare posibilă. Informațiile cookie sunt stocate în browserul dvs. și efectuează funcții cum ar fi recunoașterea dvs. atunci când vă întoarceți pe site-ul nostru și ajutând echipa noastră să înțeleagă ce secțiuni ale site-ului le găsiți cele mai interesante și mai utile.