> For the complete documentation index, see [llms.txt](https://docs.hyperswitch.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hyperswitch.io/integration-guide/payment-experience/pay-then-vault/mobile/android/widgets/google-pay.md).

# Google Pay

Learn how to integrate the Google Pay widget for accepting Google Pay payments in your Android app using Juspay Hyperswitch SDK.

**Purpose:** Google Pay payments with Juspay Hyperswitch

**Add Google Pay Widget to Layout**

```xml
<io.hyperswitch.view.BasePaymentWidget
    android:id="@+id/googlePayButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:paymentMethod="google_pay" />
```

**Initialize Google Pay Launcher**

```kotlin
private lateinit var googlePayButton: BasePaymentWidget
private lateinit var googlePayLauncherInstance: UnifiedPaymentLauncher

private fun setupGooglePayLauncher() {
    googlePayButton = findViewById(R.id.googlePayButton)
    googlePayButton.isEnabled = false
    
    googlePayLauncherInstance = UnifiedPaymentLauncher.createGooglePayLauncher(
        activity = this,
        clientSecret = paymentIntentClientSecret,
        config = GooglePayConfig(
            environment = GooglePayEnvironment.Test, // Use GooglePayEnvironment.Production for live
            merchantCountryCode = "US",
            merchantName = "Your Store Name"
        ),
        readyCallback = ::onGooglePayReady,
        resultCallback = ::onGooglePayResult
    )

    googlePayButton.setOnClickListener {
        if (::googlePayLauncherInstance.isInitialized) {
            googlePayLauncherInstance.presentForPayment(paymentIntentClientSecret)
        } else {
            Toast.makeText(this, "Google Pay Launcher not initialized", Toast.LENGTH_SHORT).show()
        }
    }
}
```

**Handle Google Pay Callbacks**

```kotlin
private fun onGooglePayReady(isReady: Boolean) {
    googlePayButton.isEnabled = isReady
}

private fun onGooglePayResult(result: GooglePayPaymentMethodLauncher.Result) {
    when (result) {
        is GooglePayPaymentMethodLauncher.Result.Completed -> {
            val paymentMethodId = result.paymentMethod.id
            Toast.makeText(this, "Payment successful: $paymentMethodId", Toast.LENGTH_LONG).show()
        }
        is GooglePayPaymentMethodLauncher.Result.Canceled -> {
            Toast.makeText(this, "Payment canceled: ${result.data}", Toast.LENGTH_LONG).show()
        }
        is GooglePayPaymentMethodLauncher.Result.Failed -> {
            Toast.makeText(this, "Payment failed: ${result.error.message}", Toast.LENGTH_LONG).show()
        }
    }
}
```

#### Best Practices

**UI State Management**

Disable payment buttons until launchers are ready:

```kotlin
private fun onGooglePayReady(isReady: Boolean) {
    googlePayButton.isEnabled = isReady
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hyperswitch.io/integration-guide/payment-experience/pay-then-vault/mobile/android/widgets/google-pay.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
