> This page is for Afterpay.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.cash.app/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.cash.app/_mcp/server.

# Afterpay Button on Android

The Afterpay Button runs entirely in your app. You pass the order details to the SDK, the customer completes checkout, and the SDK returns a one-time virtual card for the order. You process the card through your existing card payments flow, so your server doesn't need an Afterpay API integration.

The SDK supports the Afterpay Button in the US and Canada. The SDK calls it Checkout V3.

```mermaid
%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#FFF',
      'primaryTextColor': '#000',
      'primaryBorderColor': '#000',
      'lineColor': '#000',
      'secondaryColor': '#fff',
      'tertiaryColor': '#fff',
      'noteBkgColor': '#fff',
      'noteBorderColor': '#000',
      'background': '#fff'
    }
  }
}%%
sequenceDiagram
    participant App
    participant SDK as Afterpay SDK
    participant Gateway as Your card processor
    App->>SDK: Start checkout with order details
    Note over SDK: Customer logs in and confirms
    SDK-->>App: Virtual card and tokens
    App->>Gateway: Authorize the virtual card
    App->>SDK: Update merchant reference (optional)
```

## Step 1: Configure the SDK

Set the Afterpay Button configuration when your app starts. Your Afterpay account manager provides your `shopDirectoryMerchantId`.

```kotlin
Afterpay.setCheckoutV3Configuration(
  CheckoutV3Configuration(
    shopDirectoryMerchantId = "your_merchant_id",
    region = AfterpayRegion.US,
    environment = AfterpayEnvironment.SANDBOX,
  ),
)
```

The Afterpay Button doesn't need your server to fetch the merchant configuration. To show [UI components](/cash-app-afterpay/guides/sdk/android-sdk/ui-components), such as the payment button and price breakdown, fetch the configuration with the SDK and set it. `fetchMerchantConfigurationV3` makes a network request, so call it off the main thread:

```kotlin
lifecycleScope.launch {
  withContext(Dispatchers.IO) { Afterpay.fetchMerchantConfigurationV3() }
    .onSuccess { Afterpay.setConfigurationV3(it) }
    .onFailure { /* Handle the error. */ }
}
```

## Step 2: Start the checkout

When the customer taps your [payment button](/cash-app-afterpay/guides/sdk/android-sdk/ui-components/payment-button), launch the intent from `createCheckoutV3Intent` with the customer and order details:

```kotlin
private val checkoutV3Launcher =
  registerForActivityResult(StartActivityForResult()) { result ->
    val data = result.data ?: return@registerForActivityResult
    when (result.resultCode) {
      RESULT_OK -> {
        val checkout = Afterpay.parseCheckoutSuccessResponseV3(data)
        // Process the virtual card in checkout?.cardDetails.
      }
      RESULT_CANCELED -> {
        val cancellation =
          Afterpay.parseCheckoutCancellationResponseV3(data)
        // cancellation?.first is the status; second is the exception.
      }
    }
  }

private fun onAfterpayButtonClicked() {
  val intent = Afterpay.createCheckoutV3Intent(
    context = this,
    consumer = Consumer(email = "customer@example.com"),
    orderTotal = OrderTotal(
      total = BigDecimal("100.00"),
      shipping = BigDecimal.ZERO,
      tax = BigDecimal.ZERO,
    ),
    items = cartItems, // Array<CheckoutV3Item>
    buyNow = false,
  )
  checkoutV3Launcher.launch(intent)
}
```

* `consumer` implements `CheckoutV3Consumer`. The SDK's `Consumer` class takes the email address, and optionally the name, phone number, and shipping and billing addresses.
* `orderTotal.total` is the amount to charge, including shipping and tax. The SDK sends `shipping` and `tax` for fraud detection.
* `items` is optional. The SDK doesn't use it to calculate the total.
* Set `buyNow` to `true` to show a **Buy Now** button at the end of checkout.

`createCheckoutV3Intent` throws an `IllegalArgumentException` if you haven't set the configuration. A cancellation returns a `CancellationStatusV3` of `USER_INITIATED` or `REQUEST_ERROR`, with the exception for `REQUEST_ERROR`.

## Step 3: Process the virtual card

A successful result contains `CheckoutV3Data`:

| Property         | Description                                                                                                                                                                                    |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cardDetails`    | The virtual card. It's either `VirtualCard.Card`, with the card number, CVC, card type, and expiry, or `VirtualCard.TokenizedCard`, with a card token for your payment gateway and the expiry. |
| `cardValidUntil` | The `Instant` before which you must authorize the card, or `null` if Afterpay didn't return one.                                                                                               |
| `tokens`         | The tokens that identify the checkout. Keep them to update the merchant reference.                                                                                                             |

Authorize the card through your card processor before `cardValidUntil`, as you would any other card payment.

## Step 4: Update the merchant reference

If you don't have an order number when the checkout starts, associate the order with the virtual card after you create the order. `updateMerchantReferenceV3` blocks, so call it off the main thread, or use `updateMerchantReferenceV3Async`, which returns a `CompletableFuture`:

```kotlin
lifecycleScope.launch(Dispatchers.IO) {
  Afterpay.updateMerchantReferenceV3(
    merchantReference = "merchant-order-123",
    tokens = checkout.tokens,
  ).onFailure { /* Handle the error. */ }
}
```

## Accept Cash App Pay

You can also offer Cash App Pay with the Afterpay Button. The SDK creates the checkout and signs it for Cash App Pay Kit. For the full flow, see [Cash App Pay on Android](/cash-app-afterpay/guides/sdk/android-sdk/present-checkout/cash-app-pay).