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.

Dominik Mengelt
2 min readbeginner
--
View Original

Overview

The article discusses the integration of Google Pay within Android WebView, highlighting its availability starting from WebView version 137. It outlines the necessary changes developers must implement in their applications to enable this feature, including dependencies and configuration steps.

What You'll Learn

1

How to enable Google Pay support in your Android WebView application

2

Why using the Payment Request API is essential for integrating Google Pay

3

When to update your AndroidManifest.xml for Google Pay integration

Prerequisites & Requirements

  • Familiarity with Android development and WebView
  • Android Studio with the latest SDK(optional)

Key Questions Answered

How does Google Pay work within Android WebView?
Google Pay within Android WebView utilizes the Payment Request API, allowing the launch of native payment apps when a website is embedded in a WebView. This integration enables seamless payment processing directly from the app.
What changes are necessary to support Google Pay in my app?
To support Google Pay in your app, you need to add the dependency 'androidx.webkit:webkit:1.14.0', update your AndroidManifest.xml with specific queries for payment actions, and enable the Payment Request API in your WebView settings.
What is the minimum version of WebView required for Google Pay support?
Google Pay support is available starting from WebView version 137, which is essential for utilizing the Payment Request API effectively within your application.

Technologies & Tools

Frontend
Android Webview
Used to embed web content in Android applications and facilitate Google Pay integration.
API
Payment Request API
Enables launching native payment apps from within a WebView.

Key Actionable Insights

1
Ensure that your app's WebView settings allow JavaScript and enable the Payment Request API to facilitate Google Pay transactions.
This is crucial for providing a smooth checkout experience for users, as it allows them to use their saved payment methods directly within the app.
2
Regularly check for updates to Google Play Services and WebView to maintain compatibility with the latest features and security enhancements.
Staying updated ensures that your app benefits from the latest improvements in payment processing and user experience.
3
Utilize the Google Pay & Wallet Console to request production access for your app after implementing the necessary changes.
This step is vital for moving from testing to live transactions, allowing users to make real payments through your app.

Common Pitfalls

1
Failing to enable JavaScript in the WebView settings can lead to payment functionalities not working as intended.
This is a common oversight that prevents the Payment Request API from functioning correctly, resulting in a poor user experience.
2
Not updating the AndroidManifest.xml with the required queries can block payment actions.
Without these queries, the app won't be able to initiate payment requests, leading to failed transactions and user frustration.

Related Concepts

Payment Processing In Mobile Applications
Webview Best Practices
Integrating Third-party Payment Solutions