> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://developers.cash.app/afterpay/guides/sdk/android-sdk/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.cash.app/_mcp/server. # Android SDK The [Afterpay Android SDK](https://github.com/afterpay/sdk-android) presents Afterpay checkout in your Android app and provides prebuilt UI components, such as the payment button and price breakdown. It also lets you accept Cash App Pay through your Afterpay merchant account. This guide covers installation, configuration, the available checkout integrations, and how to test with the sample app. For the complete SDK reference, see the [Android SDK documentation](https://afterpay.github.io/sdk-android/). ## Requirements * Android 7.0 (API level 24) or later > **WebView support** > > Afterpay checkout runs in a WebView that requires specific browser features. The SDK runs on API level 24, but checkout depends on the WebView version installed on the device, which is independent of the Android version. If your app knows the WebView version, show Afterpay only on supported versions. ## Install the SDK Add the SDK to your module's `build.gradle.kts` or `build.gradle` file. The SDK uses Java 8+ APIs, so also enable core library desugaring: #### Kotlin DSL ```kotlin android { compileOptions { isCoreLibraryDesugaringEnabled = true } } dependencies { implementation("com.afterpay:afterpay-android:4.9.0") coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.2") } ``` #### Groovy ```groovy android { compileOptions { coreLibraryDesugaringEnabled true } } dependencies { implementation 'com.afterpay:afterpay-android:4.9.0' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.2' } ``` R8 applies the SDK's shrinking and obfuscation rules automatically. If you use ProGuard, apply the rules in [`consumer-rules.pro`](https://github.com/afterpay/sdk-android/blob/master/afterpay/consumer-rules.pro) manually. ## Configure the SDK The SDK uses your merchant configuration to render UI components with the correct branding, terms, and currency formatting. Web Redirect, Built-in UI, and Cash App Pay require it. The Afterpay Button uses its own configuration, described in [Afterpay Button](/cash-app-afterpay/guides/sdk/android-sdk/present-checkout/afterpay-button). Your server fetches the configuration from the [Get Configuration](/cash-app-afterpay/api-reference/reference/configuration/get-configuration) endpoint and passes it to your app: ```kotlin val configuration = api.getConfiguration() Afterpay.setConfiguration( minimumAmount = configuration.minimumAmount?.amount, maximumAmount = configuration.maximumAmount.amount, currencyCode = configuration.maximumAmount.currency, locale = Locale.US, environment = AfterpayEnvironment.SANDBOX, consumerLocale = Locale.ENGLISH, // Optional. Overrides the device language. ) ``` * Call `setConfiguration` on the main thread, before you start a checkout or initialize any UI component. * Use `AfterpayEnvironment.SANDBOX` for development and `AfterpayEnvironment.PRODUCTION` for release builds. The environment must match the environment your server uses to create checkouts. * Refresh the configuration about once a day, because your merchant configuration can change. * A UK locale displays Clearpay branding, terms, and currency formatting. ## Present checkout After you configure the SDK, present checkout in one of four ways: * [Web Redirect](/cash-app-afterpay/guides/sdk/android-sdk/present-checkout/web-redirect): your server creates a checkout, and the SDK loads its redirect URL. The SDK calls this Checkout V1. * [Built-in UI](/cash-app-afterpay/guides/sdk/android-sdk/present-checkout/built-in-ui): the SDK opens Afterpay's checkout right away and asks your app for a token. Supports express checkout. The SDK calls this Checkout V2. * [Afterpay Button](/cash-app-afterpay/guides/sdk/android-sdk/present-checkout/afterpay-button): the SDK creates the checkout from your app and returns a one-time virtual card. No server integration. The SDK calls this Checkout V3. * [Cash App Pay](/cash-app-afterpay/guides/sdk/android-sdk/present-checkout/cash-app-pay): the customer approves the payment in Cash App. To compare the options, see [Present checkout](/cash-app-afterpay/guides/sdk/android-sdk/present-checkout). ## UI components The SDK includes prebuilt components that follow Afterpay brand guidelines. In the US, they show Cash App Afterpay branding. * [Payment button](/cash-app-afterpay/guides/sdk/android-sdk/ui-components/payment-button): `AfterpayPaymentButton` starts an Afterpay checkout. * [Logo](/cash-app-afterpay/guides/sdk/android-sdk/ui-components/logo): Shows the Afterpay logo. * [Price breakdown](/cash-app-afterpay/guides/sdk/android-sdk/ui-components/price-breakdown): `AfterpayPriceBreakdown` shows the installment amounts for a price. * [Checkout widget](/cash-app-afterpay/guides/sdk/android-sdk/ui-components/checkout-widget): `AfterpayWidgetView` shows the payment schedule and keeps it in sync with the order total. For branding, color schemes, and accessibility, see [Android UI components](/cash-app-afterpay/guides/sdk/android-sdk/ui-components). ## Security To reduce the risk of a man-in-the-middle attack during checkout, pin the certificate for the Afterpay portal with an Android [network security configuration](https://developer.android.com/privacy-and-security/security-config#CertificatePinning). Add a domain configuration to `res/xml/network_security_config.xml`, and reference the file from your manifest with ``: ```xml portal.afterpay.com YOUR_PIN_BASE64 ``` Keep the pins and the expiration date up to date. When the certificate rotates, outdated pins block checkout until the expiration date passes. ## Test with the sample app The [sample app](https://github.com/afterpay/sdk-android/tree/master/sample) uses the [example server](https://github.com/afterpay/sdk-example-server), which creates sandbox checkouts with your merchant credentials. It includes separate screens for Built-in UI, the Afterpay Button, Cash App Pay with the Afterpay Button, and the UI components. 1. Start the example server. It requires Node.js and listens on `http://localhost:3000`. In `.env`, set `AFTERPAY_MERCHANT_ID` and `AFTERPAY_SECRET_KEY` to your sandbox credentials, and set `AFTERPAY_REGION`, for example `en-US`. ```bash git clone https://github.com/afterpay/sdk-example-server.git cd sdk-example-server cp .env.example .env npm install npm run build npm run start ``` 2. Clone the SDK and add your merchant ID to `local.properties` in the project root. The sample uses it as the `shopDirectoryMerchantId` for the Afterpay Button. ```properties merchantId="your_merchant_id" ``` 3. Run the `sample` module on an Android emulator. The sample connects to the example server at `http://10.0.2.2:3000`, which is the emulator's address for your computer. To use a different address, change `MERCHANT_API_BASE_URL` in `sample/src/main/java/com/example/api/MerchantApi.kt`. 4. Start a checkout and log in with a sandbox customer account. For details, see [Test environments](/cash-app-afterpay/guides/api-development/test-environments). > **Debug builds use a mock checkout** > > The sample builds the SDK from source. In debug builds, the SDK replaces the Built-in UI checkout page and the widget scripts with local mocks. The mock checkout immediately returns a test order token, so the checkout closes right after it opens. To test against the sandbox, build the sample's release variant with a signing configuration, or depend on the published `com.afterpay:afterpay-android` artifact instead of the local module. ## Docs - [Present Checkout](https://developers.cash.app/afterpay/guides/sdk/android-sdk/present-checkout.md) - [Web Redirect](https://developers.cash.app/afterpay/guides/sdk/android-sdk/present-checkout/web-redirect.md) - [Built-in UI](https://developers.cash.app/afterpay/guides/sdk/android-sdk/present-checkout/built-in-ui.md) - [Afterpay Button](https://developers.cash.app/afterpay/guides/sdk/android-sdk/present-checkout/afterpay-button.md) - [Cash App Pay](https://developers.cash.app/afterpay/guides/sdk/android-sdk/present-checkout/cash-app-pay.md) - [UI Components](https://developers.cash.app/afterpay/guides/sdk/android-sdk/ui-components.md) - [Payment Button](https://developers.cash.app/afterpay/guides/sdk/android-sdk/ui-components/payment-button.md) - [Logo](https://developers.cash.app/afterpay/guides/sdk/android-sdk/ui-components/logo.md) - [Price Breakdown](https://developers.cash.app/afterpay/guides/sdk/android-sdk/ui-components/price-breakdown.md) - [Checkout Widget](https://developers.cash.app/afterpay/guides/sdk/android-sdk/ui-components/checkout-widget.md)