Skip to main content


Affirm Merchant Help

Android SDK

Upgrade (from 1.x.x to 2.0.5)

If you are using an older version of the SDK, you can refer to this upgrade document. We recommend that you install the latest version to access the most up-to-date features and experience.

  • Refactored code
  • HTTP Networking
  • Debug logging
  • Event tracker
  • SDK configuration and init
  • Prequalify Flow
  • Checkout Flow (direct + vcn)
  • Exceptional Flows
  • Activity indicator
  • Track order confirmed
  • Support for Kotlin
  • Added Affirm page types for updated messaging
  • Added session cookies
  • Ability to customize the promotional messaging styling
  • Shipping/Billing requirements consistent with direct API requirements


You can use the Affirm Android SDK to add the Affirm payment option to your Android application. The SDK allows you to:

  • Offer Affirm as a payment option at checkout
  • Display Affirm promotional messaging

The process to add Affirm to your Android app is:

  1. Install the Android SDK
  2. Add Affirm promotional messaging
  3. Configure Affirm as a payment method
  4. Authorize a test charge
  5. Test your integration
  6. Deploy to production

The Affirm SDK supports Android API Level 15 and above. Please contact us using this form or through your Affirm contacts if you have any questions or problems implementing the Android SDK.

Sandbox development

You should have received an email inviting you to create an Affirm account. Click here for information about accessing your account.

Develop and test the Affirm integration in your development environment connected to our sandbox. To use our sandbox, retrieve your sandbox API keys at for use during integration.

After development and testing, you'll need to update your integration to use your live API keys, which you can find at

1. Install the Android SDK


  1. Download via Gradle:

    implementation "com.affirm:affirm-android-sdk:2.0.1"

    or Maven:


    Snapshots of the development version are available in Sonatype's snapshots repository.

    Usage Overview

    Before you can start the initialization of Affirm SDK, you must first set the AffirmSDK with your public API key from your sandbox Merchant Dashboard. You must set this key as follows:

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

2. Configure Affirm as a payment method

  1. 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.
    • Note: Amounts should be dollar amounts represented as Floats.
final Checkout checkout = Checkout.builder()
        .setOrderId("order id")

Affirm.startCheckout(this, checkout, false);
  1. Checkout object contains details about the order

  2. UseVCN (boolean) determines whether the checkout flow should use virtual card network to handle the checkout

    • If true, it will return card info from VcnCheckoutCallbacks. Be sure to override onActivityResult, then call the handleVcnCheckoutData method. Please check out the example project for more information.
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (Affirm.handleVcnCheckoutData(this, requestCode, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    public void onAffirmVcnCheckoutCancelled() {
        Toast.makeText(this, "Vcn Checkout Cancelled", Toast.LENGTH_LONG).show();
    public void onAffirmVcnCheckoutError(@Nullable String message) {
        Toast.makeText(this, "Vcn Checkout Error: " + message, Toast.LENGTH_LONG).show();
    public void onAffirmVcnCheckoutSuccess(@NonNull CardDetails cardDetails) {
        Toast.makeText(this, "Vcn Checkout Card: " + cardDetails.toString(), Toast.LENGTH_LONG).show();
    • if false, it will return checkout token from CheckoutCallbacks. Be sure to override onActivityResult, then call the handleCheckoutData method. Please refer to the example project for more information.
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (Affirm.handleCheckoutData(this, requestCode, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    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();

3. Authorize a test charge

Follow these steps to get the checkout token during development:

  1. Initiate checkout to access the account creation screen
  2. If you have an existing account, click Sign In
  3. If you don’t have an existing account, create one with the following:
  • Any first and last name
  • An email address with a valid format
  • A valid US cell phone number (you do not need access to this number) that you will use in all subsequent checkout attempts
  • A birth date older than 18 years old
  • Any four digits
  1. Enter 1234 for the verification code
  2. Click Confirm

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 then use the token to authorize a charge on the user's account. For more details about the server integration, see our API documentation.

Note - For VCN Checkout, all actions should be done using your existing payment gateway and debit card processor using the virtual card number returned after a successful checkout.

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, SDK provides a AffirmPromotionButton class. AffirmPromotionButton is implemented as follows:


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:

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),


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 start prequalification flow.

(Optional) 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 promotional message via fetchPromotion, a SpannableString object is returned after the request is successful
  • onPromotionClick This method handle 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();
  • Call 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. SDK provides 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 10 seconds timeout
  • We will replace using the HTTP API after the API is done

5. Example

  1. Copy the content of the to affirm/ This step is optional. There is a step inside affirm/build.gradle to do this automatically.
  2. Run the samples-java or samples-kotlin within Android Studio.

6. Test your integration

After completing your integration, do a thorough testing of both your front-end and order management functions in our sandbox to ensure that everything works as expected. Click here for our recommended test plan. However, you’ll need to tailor your testing plan to your specific systems, processes, and integration.

7. Deploy to production

Coordinate testing with Affirm

Before deploying the Affirm integration to your production site, Affirm will need to test it in your development or staging environment connected to our live environment. Contact your Integration Consultant or to coordinate this test.

Connect to the live Affirm environment

  1. Retrieve your live API keys at
  2. Update the Affirm instance and set setMerchantPublicKey to your live API key and set setEnvironment to Affirm.Environment.PRODUCTION

Launch to production

After you have connected your integration to our live environment and we have tested it, you are ready to release your application in your production environment and offer Affirm as a payment option to your customers.

  • Was this article helpful?