---
updatedAt: 2026-02-02T21:57:19.000Z
agentTools:
  siteIndex: https://docs.affirm.com/llms.txt
  projectIndex: https://docs.affirm.com/payments/llms.txt
---

# Set Up Virtual Card on Android

Learn how to set up Affirm Virtual Card on your Android mobile app.

## Prerequisites

* Review [About Affirm Virtual Card](docs.affirm.com/payments/docs/vcn-overview).

## Steps

### 1. Set up Affirm on Android

Note: The [Android SDK](https://github.com/Affirm/affirm-merchant-sdk-android) is open-source and fully documented.

#### *With Gradle*

To install the SDK, add `affirm-merchant-sdk-android` to the dependencies block of your [app/build.gradle](https://developer.android.com/studio/build/dependencies)  file:

```java build.gradle
apply plugin: 'com.android.application'

android { ... }

dependencies {
  // ...

  // Affirm Android SDK
  implementation 'com.affirm:affirm-android-sdk:2.0.7'
}
```

#### *With Maven*

Add the [Affirm dependency](http://repo.maven.apache.org/maven2/com/affirm/affirm-android-sdk/) to your [pom.xml](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html) file:

```xml pom.xml
<dependency>
  <groupId>com.affirm</groupId>
  <artifactId>affirm-android-sdk</artifactId>
  <version>2.0.1</version>
</dependency>
```

> 🚧 SDK Releases
>
> For details on the latest SDK release and past versions, see the [Releases page](https://github.com/Affirm/affirm-merchant-sdk-android/releases) on GitHub. To receive notifications when a new release is published, watch [releases for the repository](https://help.github.com/en/github/receiving-notifications-about-activity-on-github/watching-and-unwatching-releases-for-a-repository#watching-releases-for-a-repository).

<br />

### 2. Initialize Affirm

Configure the SDK with your Affirm **public** API key so that it can make requests to the Affirm server:

```java
Affirm.initialize(new Affirm.Configuration.Builder("public key")
      .setEnvironment(Affirm.Environment.SANDBOX)
      .setName("merchant name")
      .setUseVcn("true")
      .setReceiveReasonCodes("true")
      .setLogLevel(Affirm.LOG_LEVEL_DEBUG)
      .setCheckoutRequestCode(8001)
      .setVcnCheckoutRequestCode(8002)
      .setPrequalRequestCode(8003)
      .build()
```

<br />

### 3. Render Affirm Checkout

Checkout creation is the process by which a customer uses Affirm to pay for an in-app purchase. Create a `checkout` object and launch the Affirm checkout using this `Checkout` function:

```java
final Checkout checkout = Checkout.builder()
        .setOrderId("order id")
        .setItems(items)
        .setBilling(shipping)
        .setShipping(shipping)
        .setShippingAmount(0f)
        .setTaxAmount(100f)
        .setTotal(1100f)
        .build();
 
Affirm.startCheckout(this, checkout, false);
```

> 🚧 Floats
>
> The checkout object contains details about the order. Amounts should be dollar amounts represented as Floats.

<br />

### 4. Handle Callbacks

Override `onActivityResult` and then call the handleCheckoutData method. This returns the `CardDetails` object, which contains the Affirm card details. If you have PCI concerns, you can also decide to only retrieve [card details](https://docs.affirm.com/payments/docs/retrieve-card-details) from your server-side via the `checkout_id`.

```java
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (Affirm.handleVcnCheckoutData(this, requestCode, resultCode, data)) {
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
```

#### Additional handler functions available:

```java
@Override
public void onAffirmVcnCheckoutCancelled() {
    Toast.makeText(this, "Vcn Checkout Cancelled", Toast.LENGTH_LONG).show();
}

@Override
public void onAffirmVcnCheckoutError(@Nullable String message) {
    Toast.makeText(this, "Vcn Checkout Error: " + message, Toast.LENGTH_LONG).show();
}

@Override
public void onAffirmVcnCheckoutSuccess(@NonNull CardDetails cardDetails) {
    Toast.makeText(this, "Vcn Checkout Card: " + cardDetails.toString(), Toast.LENGTH_LONG).show();
}
```

<Callout icon="👍" theme="okay">
  Once the checkout has been successfully confirmed by the user, the `AffirmCheckoutDelegate` object receives a `CardDetails` object. The card details are then forwarded to your server to be used with your existing card payment rails.
</Callout>

<br />

## What's next?

* [Set Up Virtual Card for iOS](https://docs.affirm.com/payments/docs/vcn-ios)
* [Set Up Virtual Card for Web](https://docs.affirm.com/payments/docs/vcn-web)
* <Anchor label="About Express Checkout" target="_blank" href="https://docs.affirm.com/developers/docs/express-checkout">About Express Checkout</Anchor>
* <Anchor label="Checkout Button" target="_blank" href="https://docs.affirm.com/developers/docs/pre-styled-checkout-button">Checkout Button</Anchor>

# Sibling pages

* [Set Up Virtual Card on the Web](https://docs.affirm.com/payments/docs/vcn-web.md)
* [Set Up Virtual Card on iOS](https://docs.affirm.com/payments/docs/vcn-ios.md)