Client reference
Stay organized with collections Save and categorize content based on your preferences.
The com.google.android.gms.wallet documentation contains full documentation for the library across multiple versions of the Google Pay API. Below is a summary of objects and methods most applicable to the most recent version of the Google Pay API: version 2.0
Generate a PaymentsClient
for a test or production environment.
Example
mPaymentsClient = Wallet.getPaymentsClient( this, new Wallet.WalletOptions.Builder() .setEnvironment(WalletConstants.ENVIRONMENT_TEST) .build() );
A client for interacting with the Google Pay APIs.
Use the isReadyToPay(IsReadyToPayRequest)
method to determine a user's ability to return a form of payment from the Google Pay API.
If the device supports Google Pay, and the user either has already saved a payment method or can add one, IsReadyToPay
returns true
. To determine whether the user already saved a payment method in Google Pay, set IsReadyToPayRequest.existingPaymentMethodRequired
to true
.
Present a Google Pay payment sheet allowing selection of a payment method and optionally configured parameters.
Handle a Google Pay API JSON-formatted response for use in your app.
Output a Google Pay API response as a JSON-formatted string. See the PaymentData object reference for more information about the structure of the JSON object.
The convenience method is used to initialize a Google Pay payment button styled with the latest Google Pay branding.
Arguments
Name | Description |
buttonOptions | An object that configures the Google Pay payment button. See ButtonOptions for configurable properties. |
PayButton googlePayPaymentButton = layoutBinding.googlePayPaymentButton; JSONArray paymentMethods = new JSONArray().put(getBaseCardPaymentMethod()); googlePayPaymentButton.initialize( ButtonOptions.newBuilder() .setButtonTheme(ButtonConstants.ButtonTheme.DARK) .setButtonType(ButtonConstants.ButtonType.BUY) .setCornerRadius(100) .setAllowedPaymentMethods(paymentMethods.toString()) .build() );
public void setVisibility(View view)
The convenience method sets the payment button visibility.
Arguments
Name | Description |
View | View.VISIBLE sets the payment button to visible (default). View.GONE hides the button from users.
|
Example:
payButton.setVisibility(View.VISIBLE);
public void setOnClickListener(View.OnClickListener listener)
Method is called when the user clicks on the Google Pay payment button.
Arguments
Name | Description |
listener | An event listener callback to call when a click event is delivered to the Google Pay payment button. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["\u003cp\u003eThe \u003ccode\u003ecom.google.android.gms.wallet\u003c/code\u003e library provides tools for integrating Google Pay into Android applications, including generating a \u003ccode\u003ePaymentsClient\u003c/code\u003e, checking user readiness for payment, and loading a payment sheet.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ePaymentsClient\u003c/code\u003e class enables interaction with Google Pay APIs, offering methods like \u003ccode\u003eisReadyToPay()\u003c/code\u003e to assess the user's payment capabilities and \u003ccode\u003eloadPaymentData()\u003c/code\u003e to initiate payment transactions.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eIsReadyToPayRequest\u003c/code\u003e and \u003ccode\u003ePaymentDataRequest\u003c/code\u003e objects are used to configure the \u003ccode\u003eisReadyToPay()\u003c/code\u003e and \u003ccode\u003eloadPaymentData()\u003c/code\u003e methods, respectively, and can be constructed from JSON strings.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ePaymentData\u003c/code\u003e facilitates handling Google Pay responses, offering methods like \u003ccode\u003etoJson()\u003c/code\u003e for outputting the response data, while \u003ccode\u003ePayButton\u003c/code\u003e provides a pre-built UI component for initiating Google Pay transactions and can be customized with options like button theme and corner radius.\u003c/p\u003e\n"]]],["The provided content outlines the core components of the Google Pay API, version 2.0, within the `com.google.android.gms.wallet` library. Key actions include generating a `PaymentsClient` via `Wallet`, using `isReadyToPay` to check for Google Pay availability, and loading a payment sheet with `loadPaymentData`. `IsReadyToPayRequest` and `PaymentDataRequest` objects can be built from JSON. `PaymentData` objects can be converted to JSON. Finally, `PayButton` can be initialized, configured, made visible, and have a click listener set.\n"],null,["The [com.google.android.gms.wallet documentation](/android/reference/com/google/android/gms/wallet/package-summary)\ncontains full documentation for the library across multiple versions of the Google Pay API.\nBelow is a summary of objects and methods most applicable to the most recent version of the Google Pay API:\nversion 2.0\n\n[Wallet](/android/reference/com/google/android/gms/wallet/Wallet)\n\nGenerate a `PaymentsClient` for a test or production environment.\n\nExample \n\n```java\nmPaymentsClient = Wallet.getPaymentsClient(\n this,\n new Wallet.WalletOptions.Builder()\n .setEnvironment(WalletConstants.ENVIRONMENT_TEST)\n .build()\n);\n```\n\n[PaymentsClient](/android/reference/com/google/android/gms/wallet/PaymentsClient)\n\nA client for interacting with the Google Pay APIs.\n\n[isReadyToPay(IsReadyToPayRequest)](/android/reference/com/google/android/gms/wallet/PaymentsClient#isReadyToPay(com.google.android.gms.wallet.IsReadyToPayRequest))\n\nUse the `isReadyToPay(IsReadyToPayRequest)` method to determine a user's ability to\nreturn a form of payment from the Google Pay API.\n\nIf the device supports Google Pay, and the user either has already saved a payment method or can\nadd one, `IsReadyToPay` returns `true`. To determine whether the user\nalready saved a payment method in Google Pay, set\n[`IsReadyToPayRequest.existingPaymentMethodRequired`](/pay/api/android/reference/request-objects#existingPaymentMethodRequired)\nto `true`.\n\n[loadPaymentData(PaymentDataRequest)](/android/reference/com/google/android/gms/wallet/PaymentsClient#loadPaymentData(com.google.android.gms.wallet.PaymentDataRequest))\n\nPresent a Google Pay payment sheet allowing selection of a payment method and optionally configured parameters.\n\n[IsReadyToPayRequest](/android/reference/com/google/android/gms/wallet/IsReadyToPayRequest)\n\nBuild an `IsReadyToPayRequest` Java object suitable for use with [PaymentsClient.isReadyToPay()](#isReadyToPay).\n\n[fromJson(java.lang.String)](/android/reference/com/google/android/gms/wallet/IsReadyToPayRequest#fromJson(java.lang.String))\n\nCreate an `IsReadyToPayRequest` Java object from a JSON-formatted string. See the\n[IsReadyToPayRequest object reference](/pay/api/android/reference/request-objects#IsReadyToPayRequest)\nfor the expected structure of the provided JSON-formatted string.\n\nPaymentDataRequest\n\nBuild a `PaymentDataRequest` Java object suitable for use with [PaymentsClient.loadPaymentData](#loadPaymentData).\n\n[fromJson(java.lang.String)](/android/reference/com/google/android/gms/wallet/PaymentDataRequest#fromJson(java.lang.String))\n\nCreate a `PaymentDataRequest` Java object from a JSON-formatted string. See the\n[PaymentDataRequest object reference](/pay/api/android/reference/request-objects#PaymentDataRequest)\nfor the expected structure of the provided JSON-formatted string.\n\n[PaymentData](/android/reference/com/google/android/gms/wallet/PaymentData)\n\nHandle a Google Pay API JSON-formatted response for use in your app.\n\n[toJson()](/android/reference/com/google/android/gms/wallet/PaymentData#toJson())\n\nOutput a Google Pay API response as a JSON-formatted string. See the\n[PaymentData object reference](/pay/api/android/reference/response-objects#PaymentData)\nfor more information about the structure of the JSON object.\n\nPayButton\n\npublic void initialize(ButtonOption buttonOptions)\n\nThe convenience method is used to initialize a Google Pay payment button styled with the latest\nGoogle Pay branding.\n\nArguments\n\n| Name | Description |\n|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `buttonOptions` | An object that configures the Google Pay payment button. See [ButtonOptions](/pay/api/android/reference/request-objects#ButtonOptions) for configurable properties. |\n\nExample: Initialize the payment button with custom configurations: \n\n```java\nPayButton googlePayPaymentButton = layoutBinding.googlePayPaymentButton;\nJSONArray paymentMethods = new JSONArray().put(getBaseCardPaymentMethod());\ngooglePayPaymentButton.initialize(\n ButtonOptions.newBuilder()\n .setButtonTheme(ButtonConstants.ButtonTheme.DARK)\n .setButtonType(ButtonConstants.ButtonType.BUY)\n .setCornerRadius(100)\n .setAllowedPaymentMethods(paymentMethods.toString())\n .build()\n);\n```\n\npublic void setVisibility([View](https://developer.android.com/reference/android/view/View) view)\n\nThe convenience method sets the payment button visibility.\n\nArguments\n\n| Name | Description |\n|--------|-------------------------------------------------------------------------------------------------------|\n| `View` | `View.VISIBLE` sets the payment button to visible (default). `View.GONE` hides the button from users. |\n\nExample: \n\n```java\npayButton.setVisibility(View.VISIBLE);\n```\n\npublic void setOnClickListener([View.OnClickListener](https://developer.android.com/reference/android/view/View.OnClickListener) listener)\n\nMethod is called when the user clicks on the Google Pay payment button.\n\nArguments\n\n| Name | Description |\n|------------|------------------------------------------------------------------------------------------------------|\n| `listener` | An event listener callback to call when a click event is delivered to the Google Pay payment button. |"]]