> 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/headless-sdk.md).

# Headless SDK

Hyperswitch is designed to facilitate the integration and management of payment-related functionalities in a decoupled or headless architecture with flexibility to customize your checkout UI.

#### Customize the payment experience using Headless functions

**1. Initialize the Juspay Hyperswitch SDK**

Initialize Juspay Hyperswitch Headless SDK onto your app with your publishable key. To get a Publishable Key please find it [here](https://app.hyperswitch.io/developers).

```kotlin
// dependencies: implementation 'io.hyperswitch:hyperswitch-sdk-android:+' val 
hyperswitchInstance = Hyperswitch.init(
          activity = this,
          config = HyperswitchConfiguration(
              publishableKey = publishableKey,
              profileId = profileId,
          ),
      )
```

**2. Create a Payment Intent**

Make a request to the endpoint on your server to create a new Payment. The `sdk_authorization` returned by your endpoint is used to initialize the payment session.

{% hint style="danger" %}
**Important**: Make sure to never share your API key with your client application as this could potentially compromise your security
{% endhint %}

**3. Initialize your Payment Session**

Initialize a Payment Session by passing the sdk\_authorization to the `initPaymentSession`

```kotlin
lifecycleScope.launch {
          paymentSession = instance.initPaymentSession(
              PaymentSessionConfiguration(
                  sdkAuthorization = sdkAuthorization,
              ),
          )
      }
```

**4. Craft a customized payments experience**

Call `paymentSession.getCustomerSavedPaymentMethods`, keep the `PaymentSessionHandler` it hands to your callback, and work from that handler. It carries the saved payment method data and the confirm functions, as the example below shows. `paymentSession` itself does not expose them.

<pre class="language-kotlin"><code class="lang-kotlin"><strong>var handler: PaymentSessionHandler? = null
</strong>
paymentSession.getCustomerSavedPaymentMethods { paymentSessionHandler ->
    handler = paymentSessionHandler
}

val savedPaymentMethod = handler!!.getCustomerLastUsedSavedPaymentMethodData()

button.setOnClickListener { 
    handler!!.confirmWithCustomerLastUsedPaymentMethod { paymentResult -> 
        println(paymentResult)
    }
}
</code></pre>

**Payload for** `confirmWithCustomerLastUsedPaymentMethod(callback)`

<table><thead><tr><th width="296">options (Required)</th><th>Description</th></tr></thead><tbody><tr><td><code>callback (method)</code></td><td>Callback to get confirm response.</td></tr></tbody></table>


---

# 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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
