Offer Affirm as a payment option on Android applications.


Starting a payment with Affirm on an Android client consists of the following: creating a checkout form, tokenizing customer information to transmit it securely to your server, and using that checkout_token to initiate a transaction.

This guide walks you through setting up the Android client on your checkout pages.

The Android SDK is available on Github.

1. Set up Affirm on Android

With Gradle

To install the SDK, add affirm-merchant-sdk-android to the dependencies block of your app/build.gradle file:

apply plugin: ''

android { ... }

dependencies {
  // ...

  // Affirm Android SDK
  implementation 'com.affirm:affirm-android-sdk:2.0.19'

With Maven

Add the Affirm dependency to your pom.xml file:



For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.

2. Initialize Affirm

Configure the SDK with your Affirm public API key to send requests to the Affirm server.

Affirm.initialize(Affirm.Configuration.Builder("public key")
			.setMerchantName("merchant name")

3. Render Affirm Checkout

Checkout creation is the process in which a customer uses Affirm to pay for a purchase in your app. You can create a checkout object and launch the Affirm checkout using the Checkout function.

final Checkout checkout = Checkout.builder()
        .setOrderId("order id")
Affirm.startCheckout(this, checkout, false);


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

4. Add Affirm promotional messaging

Affirm promotional messaging components---monthly payment messaging and educational modals---show customers how they can use Affirm to finance their purchases. Properly placed promotional messaging helps drive increased AOV and conversion.

Add monthly payment messaging

To display promotional messaging, our SDK provides a AffirmPromotionButton class. To implement the AffirmPromotionButton:


Use one of the following implementation methods: 

// Option1 - Load via findViewById
AffirmPromotionButton affirmPromotionButton1 = findViewById(;
Affirm.configureWithAmount(affirmPromotionButton1, null, PromoPageType.PRODUCT, 1100, true);
// Option2 - Initialize by new
AffirmPromotionButton affirmPromotionButton2 = new AffirmPromotionButton(this);
Affirm.configureWithAmount(affirmPromotionButton2, null, PromoPageType.PRODUCT, 1100, true);

To style the promotional messaging button we have two options:

Option 1: Use configWithLocalStyling to use the local styles on the string within the button

// You can custom with the AffirmColor, AffirmLogoType, Typeface, TextSize, TextColor
                ResourcesCompat.getFont(this, R.font.apercu_bold),

Option 2: configWithHtmlStyling will use html style from Affirm server. You can add fonts by following the steps below, so you can customize the fonts in html.

1. Add a font file in the /res/font/ directory. Such as lacquer_regular.ttf.
2. Add a declaration for the font file. You can check the detail in typeface.
3. Use the font in the css file. You can check the detail in remote_promo.css.

// If you want to custom the style of promo message, should pass the local or remote url and the file of typeface declaration
affirmPromotionButton2.configWithHtmlStyling("file:///android_asset/remote_promo.css", typefaceDeclaration);

Tapping on the AffirmPromotionButton automatically starts the prequalification flow. If you want to handle errors, override onActivityResult so that Affirm can handle the result.

protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (Affirm.handlePrequalData(this, requestCode, resultCode, data)) {
    super.onActivityResult(requestCode, resultCode, data);

public void onAffirmPrequalError(String message) {
    Toast.makeText(this, "Prequal Error: " + message, Toast.LENGTH_LONG).show();

Fetch promotional message, then display it with your own TextView.

  • You can get the promotional message via fetchPromotion, a SpannableString object is returned after the request is successful.
  • onPromotionClick:  This method handles events that click on the promotional message
TextView promotionTextView = findViewById(;
    Affirm.PromoRequestData requestData = new Affirm.PromoRequestData.Builder(PRICE, true)

    promoRequest = Affirm.fetchPromotion(requestData, promotionTextView.getTextSize(), this, new PromotionCallback() {
        public void onSuccess(@Nullable SpannableString spannableString, boolean showPrequal) {
            promotionTextView.setOnClickListener(v -> Affirm.onPromotionClick(MainActivity.this, requestData, showPrequal));
        public void onFailure(@NonNull AffirmException exception) {
                   Toast.makeText(getBaseContext(), "Failed to get promo message, reason: " + exception.toString(), Toast.LENGTH_SHORT).show();

Calling the create method will initiate the request, and call cancel method to cancel the request.

    protected void onStart() {

    protected void onStop() {

Track Order Confirmed

The trackOrderConfirmed event triggers when a customer completes their purchase. Our SDK provides the AffirmTrack object to trigger the tracking.

final AffirmTrack affirmTrack = AffirmTrack.builder()

Affirm.trackOrderConfirmed(MainActivity.this, trackModel());
  • Since there is no callback, it will return success after a 10 second timeout.
  • We will replace it using the HTTP API after the API is done.

5. Handle callbacks

Be sure to override onActivityResult, then call the handleCheckoutData method. It will return the checkout_token required to initiate the transaction on your server.

protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (Affirm.handleCheckoutData(this, requestCode, resultCode, data)) {
    super.onActivityResult(requestCode, resultCode, data);

We also have some additional handler functions available:

public void onAffirmCheckoutSuccess(@NonNull String token) {
    Toast.makeText(this, "Checkout token: " + token, Toast.LENGTH_LONG).show();
public void onAffirmCheckoutCancelled() {
    Toast.makeText(this, "Checkout Cancelled", Toast.LENGTH_LONG).show();
public void onAffirmCheckoutError(String message) {
    Toast.makeText(this, "Checkout Error: " + message, Toast.LENGTH_LONG).show();


Once the checkout has been successfully confirmed by the user, the AffirmCheckoutDelegate object will receive a checkout_token. This token should be forwarded to your server, which should be used to authorize a charge on the user's account.

6. Create a charge

When a customer successfully completes a checkout, it is recorded as a new purchase attempt. This needs to be handled on your server-side to be fulfilled via our Charges API.