The [com.google.android.gms.wallet documentation](https://developers.google.com/android/reference/com/google/android/gms/wallet/package-summary.md.txt)
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

## [Wallet](https://developers.google.com/android/reference/com/google/android/gms/wallet/Wallet.md.txt)

Generate a `PaymentsClient` for a test or production environment.

### Example

```java
mPaymentsClient = Wallet.getPaymentsClient(
  this,
  new Wallet.WalletOptions.Builder()
      .setEnvironment(WalletConstants.ENVIRONMENT_TEST)
      .build()
);
```

## [PaymentsClient](https://developers.google.com/android/reference/com/google/android/gms/wallet/PaymentsClient.md.txt)

A client for interacting with the Google Pay APIs.

### [isReadyToPay(IsReadyToPayRequest)](https://developers.google.com/android/reference/com/google/android/gms/wallet/PaymentsClient.md.txt#isReadyToPay(com.google.android.gms.wallet.IsReadyToPayRequest))

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`](https://developers.google.com/pay/api/android/reference/request-objects.md.txt#existingPaymentMethodRequired)
to `true`.

### [loadPaymentData(PaymentDataRequest)](https://developers.google.com/android/reference/com/google/android/gms/wallet/PaymentsClient.md.txt#loadPaymentData(com.google.android.gms.wallet.PaymentDataRequest))

Present a Google Pay payment sheet allowing selection of a payment method and optionally configured parameters.

## [IsReadyToPayRequest](https://developers.google.com/android/reference/com/google/android/gms/wallet/IsReadyToPayRequest.md.txt)

Build an `IsReadyToPayRequest` Java object suitable for use with [PaymentsClient.isReadyToPay()](https://developers.google.com/pay/api/android/reference/client.md.txt#isReadyToPay).

### [fromJson(java.lang.String)](https://developers.google.com/android/reference/com/google/android/gms/wallet/IsReadyToPayRequest.md.txt#fromJson(java.lang.String))

Create an `IsReadyToPayRequest` Java object from a JSON-formatted string. See the
[IsReadyToPayRequest object reference](https://developers.google.com/pay/api/android/reference/request-objects.md.txt#IsReadyToPayRequest)
for the expected structure of the provided JSON-formatted string.

## PaymentDataRequest

Build a `PaymentDataRequest` Java object suitable for use with [PaymentsClient.loadPaymentData](https://developers.google.com/pay/api/android/reference/client.md.txt#loadPaymentData).

### [fromJson(java.lang.String)](https://developers.google.com/android/reference/com/google/android/gms/wallet/PaymentDataRequest.md.txt#fromJson(java.lang.String))

Create a `PaymentDataRequest` Java object from a JSON-formatted string. See the
[PaymentDataRequest object reference](https://developers.google.com/pay/api/android/reference/request-objects.md.txt#PaymentDataRequest)
for the expected structure of the provided JSON-formatted string.

## [PaymentData](https://developers.google.com/android/reference/com/google/android/gms/wallet/PaymentData.md.txt)

Handle a Google Pay API JSON-formatted response for use in your app.

### [toJson()](https://developers.google.com/android/reference/com/google/android/gms/wallet/PaymentData.md.txt#toJson())

Output a Google Pay API response as a JSON-formatted string. See the
[PaymentData object reference](https://developers.google.com/pay/api/android/reference/response-objects.md.txt#PaymentData)
for more information about the structure of the JSON object.

## PayButton

### public void initialize(ButtonOption buttonOptions)

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](https://developers.google.com/pay/api/android/reference/request-objects.md.txt#ButtonOptions) for configurable properties. |

#### Example: Initialize the payment button with custom configurations:

```java
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](https://developer.android.com/reference/android/view/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:

```java
payButton.setVisibility(View.VISIBLE);
```

### public void setOnClickListener([View.OnClickListener](https://developer.android.com/reference/android/view/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. |

## [BasePaymentDataCallbacksService](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/BasePaymentDataCallbacksService.md.txt)

Base service class which hosts the payment data callbacks initiated by Google Play services
within a [`PaymentsClient.loadPaymentData(PaymentDataRequest)`](https://developers.google.com/pay/api/android/reference/client.md.txt#loadPaymentData) flow.

Extend this service in your application and declare it in your `AndroidManifest.xml` with the
`com.google.android.gms.permission.BIND_PAYMENTS_CALLBACK_SERVICE` permission and an intent filter
for `com.google.android.gms.wallet.callback.PAYMENT_DATA_CALLBACKS`.

### [createPaymentDataCallbacks()](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/BasePaymentDataCallbacksService.md.txt#createPaymentDataCallbacks())

Returns an implementation of [`BasePaymentDataCallbacks`](https://developers.google.com/pay/api/android/reference/client.md.txt#BasePaymentDataCallbacks)
to handle incoming callback events. Called once per callback event.

> [!NOTE]
> **Note:** A new instance of your `BasePaymentDataCallbacks` implementation should be created on every `createPaymentDataCallbacks()` call. Avoid storing persistent state directly in the service class, as the service process may be destroyed by the Android OS between invocations. Use [`getLastSavedState()`](https://developers.google.com/pay/api/android/reference/client.md.txt#getLastSavedState) and [`withUpdatedSavedState()`](https://developers.google.com/pay/api/android/reference/client.md.txt#withUpdatedSavedState) instead.

## [BasePaymentDataCallbacks](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/BasePaymentDataCallbacks.md.txt)

Abstract base class containing the payment data callback handlers implemented by the merchant
to support Dynamic Price Updates and Payment Authorization.

### [onPaymentDataChanged(intermediatePaymentData, onCompleteListener)](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/BasePaymentDataCallbacks.md.txt#onPaymentDataChanged(com.google.android.gms.wallet.callback.IntermediatePaymentData,%20com.google.android.gms.wallet.callback.OnCompleteListener<com.google.android.gms.wallet.callback.PaymentDataRequestUpdate>))

This method handles payment data changes in the payment sheet such as shipping address and
shipping options.
**Note:** The `onPaymentAuthorized` callback must also be set to use the `onPaymentDataChanged` callback. You must call `onCompleteListener.complete(...)` within 30 seconds. If the callback isn't completed within this timeframe, the request times out, and the Google Pay sheet displays a `CALLBACK_TIMED_OUT` error to the user.

#### Arguments

| Name | Type | Description |
|---|---|---|
| `intermediatePaymentData` | [`IntermediatePaymentData`](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/IntermediatePaymentData.md.txt) | An object that contains the selected address and shipping option in the payment sheet. For details, see [`IntermediatePaymentData`](https://developers.google.com/pay/api/android/reference/response-objects.md.txt#IntermediatePaymentData). |
| `onCompleteListener` | [`OnCompleteListener<PaymentDataRequestUpdate>`](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/OnCompleteListener.md.txt) | A listener to resolve with the updated transaction information, shipping options, and payment data errors. Pass a [`PaymentDataRequestUpdate`](https://developers.google.com/pay/api/android/reference/client.md.txt#PaymentDataRequestUpdate) instance to `complete()`. |

#### Example

```kotlin
override fun onPaymentDataChanged(
    intermediatePaymentData: IntermediatePaymentData,
    onCompleteListener: OnCompleteListener<PaymentDataRequestUpdate>
) {
    val paymentDataRequestUpdateJson = handlePaymentDataChanged(intermediatePaymentData.toJson())
    val update = PaymentDataRequestUpdate.fromJson(paymentDataRequestUpdateJson.toString())
    onCompleteListener.complete(update)
}
```

### [onPaymentAuthorized(paymentData, onCompleteListener)](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/BasePaymentDataCallbacks.md.txt#onPaymentAuthorized(com.google.android.gms.wallet.PaymentData,%20com.google.android.gms.wallet.callback.OnCompleteListener<com.google.android.gms.wallet.callback.PaymentAuthorizationResult>))

This method is called when a payment is authorized in the payment sheet.
**Note:** You must call `onCompleteListener.complete(...)` within 30 seconds. If the callback isn't completed within this timeframe, the request times out, and the Google Pay sheet displays a `CALLBACK_TIMED_OUT` error to the user.

#### Arguments

| Name | Type | Description |
|---|---|---|
| `paymentData` | [`PaymentData`](https://developers.google.com/android/reference/com/google/android/gms/wallet/PaymentData.md.txt) | An object that contains the requested shopper data. For details, see [`PaymentData`](https://developers.google.com/pay/api/android/reference/response-objects.md.txt#PaymentData). |
| `onCompleteListener` | [`OnCompleteListener<PaymentAuthorizationResult>`](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/OnCompleteListener.md.txt) | A listener to resolve with the authorization result. Pass a [`PaymentAuthorizationResult`](https://developers.google.com/pay/api/android/reference/client.md.txt#PaymentAuthorizationResult) instance to `complete()`. |

#### Example

```kotlin
override fun onPaymentAuthorized(
    paymentData: PaymentData,
    onCompleteListener: OnCompleteListener<PaymentAuthorizationResult>
) {
    val paymentAuthorizationResultJson = handlePaymentAuthorized(paymentData.toJson())
    val result = PaymentAuthorizationResult.fromJson(paymentAuthorizationResultJson.toString())
    onCompleteListener.complete(result)
}
```

## [IntermediatePaymentData](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/IntermediatePaymentData.md.txt)

Handle intermediate callback data passed to [`BasePaymentDataCallbacks.onPaymentDataChanged`](https://developers.google.com/pay/api/android/reference/client.md.txt#onPaymentDataChanged).

### [toJson()](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/IntermediatePaymentData.md.txt#toJson())

Outputs the callback request data as a JSON-formatted string. See the
[IntermediatePaymentData object reference](https://developers.google.com/pay/api/android/reference/response-objects.md.txt#IntermediatePaymentData)
for more information about the structure of the JSON object.

### [getLastSavedState()](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/IntermediatePaymentData.md.txt#getLastSavedState())

Returns the `Bundle` containing the state saved during the previous callback iteration.

## PaymentDataRequestUpdate

Build a `PaymentDataRequestUpdate` Java object to return in
[`BasePaymentDataCallbacks.onPaymentDataChanged`](https://developers.google.com/pay/api/android/reference/client.md.txt#onPaymentDataChanged).

### [fromJson(java.lang.String)](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/PaymentDataRequestUpdate.md.txt#fromJson(java.lang.String))

Create a `PaymentDataRequestUpdate` Java object from a JSON-formatted string. See the
[PaymentDataRequestUpdate object reference](https://developers.google.com/pay/api/android/reference/request-objects.md.txt#PaymentDataRequestUpdate)
for the expected structure of the provided JSON-formatted string.

### [withUpdatedSavedState(Bundle)](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/PaymentDataRequestUpdate.md.txt#withUpdatedSavedState(android.os.Bundle))

Attaches an updated state `Bundle` to persist between callback invocations.

## PaymentAuthorizationResult

Build a `PaymentAuthorizationResult` Java object to return in
[`BasePaymentDataCallbacks.onPaymentAuthorized`](https://developers.google.com/pay/api/android/reference/client.md.txt#onPaymentAuthorized).

### [fromJson(java.lang.String)](https://developers.google.com/android/reference/com/google/android/gms/wallet/callback/PaymentAuthorizationResult.md.txt#fromJson(java.lang.String))

Create a `PaymentAuthorizationResult` Java object from a JSON-formatted string. See the
[PaymentAuthorizationResult response object reference](https://developers.google.com/pay/api/android/reference/response-objects.md.txt#PaymentAuthorizationResult)
for the expected structure of the provided JSON-formatted string.