Skip to main content

Merchant Help

 

Affirm Merchant Help

Android SDK

Overview

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 https://sandbox.affirm.com/dashboard/#/apikeys 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 https://affirm.com/dashboard/#/apikeys.

1. Install the Android SDK

  1. Download the Android SDK
  2. Include affirm-android-sdk in your build.gradle
repositories {
  jcenter()
  maven {
    url 'https://github.com/Affirm/affirm-android-sdk/raw/master/snapshots'
  }
}
  1. Add dependencies in build.gradle
dependencies {
  final String ANDROID_SUPPORT_VERSION = '25.2.0'
  compile "com.android.support:appcompat-v7:$ANDROID_SUPPORT_VERSION"
  compile "com.affirm:affirm-android-sdk:0.2.0"
}
  1. Create an affirm instance (set to Affirm.Environment.SANDBOX and add your Public API key)
affirm = Affirm.builder()
        .setEnvironment(Affirm.Environment.SANDBOX)
        .setMerchantPublicKey("YOUR_PUBLIC_API_KEY")
        .build();

2. Configure Affirm as a payment method

  1. Create a checkout object to launch the affirm checkout
...
final Checkout checkout = Checkout.builder()
        .setItems(items)
        .setBilling(shipping)
        .setShipping(shipping)
        .setShippingAmount(0f)
        .setTaxAmount(100f)
        .setTotal(1100f)
        .build();

affirm.launchCheckout(this, checkout);
  1. Override onActivityResult so that the SDK can handle the results
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (!affirm.onActivityResult(this, requestCode, resultCode, data)) {
    super.onActivityResult(requestCode, resultCode, data);
  }
}
  1. Add Checkout callback functions to handle successful, cancelled or error events
@Override public void onAffirmCheckoutSuccess(String token) {
    Toast.makeText(this, "Checkout token: " + token, Toast.LENGTH_LONG).show();
  }
  
@Override public void onAffirmCheckoutCancelled() {
  Toast.makeText(this, "Checkout Cancelled", Toast.LENGTH_LONG).show();
}

@Override 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

The checkout token will be sent to the AffirmCheckoutDelegate object. Forward this token to your server to authorize the charge. Click here for more information on authorizing a charge.

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

Display monthly payment messaging by creating a TextView in your layout, and then passing its ID to the affirm.writePromoToTextView() method along with other configuration details.

affirm.writePromoToTextView(promo, promoId, amount, logoType, affirmColor, promoCallback)
  • Promo: The ID used when displaying payment pricing
  • promoId: Affirm provides this Promo ID
  • amount: The price of the product or cart
  • logoType: Set as either AffirmDisplayTypeLogo, AffirmDisplayTypeText, AffirmDisplayTypeSymbol, or AffirmDisplayTypeSymbolHollow
  • affirmColor: Set as either AffirmColorTypeBlue, AffirmColorTypeBlack, or AffirmColorTypeWhite

Note that monthly payment messaging only displays when amount is greater than 50.

Add a product modal

Display a product modal by passing a valid Modal ID and amount in the affirm.launchProductModal() method using an onClickListener.

affirm.launchProductModal(MainActivity.this, amount, modalId);
  • amount: The price of the product or cart
  • modalID: Affirm provides this ID

Add a site modal

Display a product modal by passing a valid Modal ID in affirm.launchSiteModal() method using an onClickListener.

affirm.launchSiteModal(MainActivity.this, modalId);
  • modalID: Affirm provides this ID

5. 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.

6. 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 Client Success Manager to coordinate this test.

Connect to the live Affirm environment

  1. Retrieve your live API keys at https://affirm.com/dashboard/#/apikeys
  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.