# Express Checkout

One-click solution for last used saved payment method with Juspay Hyperswitch.

### Add Express Checkout Widget to Layout

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

<Button
    android:id="@+id/confirmEC"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Confirm EC" />
```

### Initialize Express Checkout Launcher

```kotlin
private lateinit var ecLauncherInstance: UnifiedPaymentLauncher

private fun setupECLauncher() {
    ecLauncherInstance = UnifiedPaymentLauncher.createExpressCheckoutLauncher(
        activity = this,
        clientSecret = paymentIntentClientSecret,
        readyCallback = ::onExpressCheckoutReady,
        resultCallback = ::onExpressCheckoutResult
    )

    findViewById<View>(R.id.confirmEC).setOnClickListener {
        if (::ecLauncherInstance.isInitialized) {
            ecLauncherInstance.presentForPayment(paymentIntentClientSecret)
        } else {
            Toast.makeText(this, "Express Checkout Launcher not initialized", Toast.LENGTH_SHORT).show()
        }
    }
}
```

### Handle Express Checkout Callbacks

```kotlin
private fun onExpressCheckoutReady(isReady: Boolean) {
    findViewById<View>(R.id.confirmEC).isEnabled = isReady
}

private fun onExpressCheckoutResult(result: ExpressCheckoutPaymentMethodLauncher.Result) {
    when (result) {
        is ExpressCheckoutPaymentMethodLauncher.Result.Completed -> {
            Toast.makeText(this, "Express checkout successful: ${result.paymentMethod}", Toast.LENGTH_LONG).show()
        }
        is ExpressCheckoutPaymentMethodLauncher.Result.Canceled -> {
            Toast.makeText(this, "Express checkout canceled: ${result.data}", Toast.LENGTH_LONG).show()
        }
        is ExpressCheckoutPaymentMethodLauncher.Result.Failed -> {
            Toast.makeText(this, "Express checkout failed: ${result.error.message}", Toast.LENGTH_LONG).show()
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hyperswitch.io/integration-guide/payment-experience/payment/mobile/android/widgets/express-checkout.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
