For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

<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

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

Best Practices

UI State Management

Disable payment buttons until launchers are ready:

Last updated

Was this helpful?