Skip to main content

Merchant Help

 

Affirm Merchant Help

Android SDK

Affirm offers an Android SDK that can be added to your application. The SDK currently supports:

Please contact merchanthelp@affirm.com, or your Affirm contacts, if you have any questions or problems implementing the Android SDK.

Installation

You can add affirm-android-sdk from our Github repository. Affirm SDK supports Android API Level 15 and above.

1. Include affirm-android-sdk - https://github.com/Affirm/affirm-and...ster/snapshots in your build.gradle.

repositories {
  jcenter()
  maven {
    url 'https://github.com/Affirm/affirm-android-sdk/raw/master/snapshots'
  }
}

2. 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"
}

3. Start by creating an affirm instance:

affirm = Affirm.builder()
        .setEnvironment(Affirm.Environment.SANDBOX)
        .setMerchantPublicKey("XXXXXXXXXXXXXXXX")
        .build();
  • setEnvironment - Affirm.Environment.SANDBOX or Affirm.Environment.PRODUCTION 
  • setMerchantPublicKey - Affirm Public API Key (refer Merchant Account Setup)

Promotional Messaging

Monthly Payment Pricing

Monthly Payment Pricing enables you to promote financing options in your app. This messaging is a critical tool to inform customers about the availability of financing and the specific financing terms being offered through Affirm. It can be included on your product category layout, product layout, and cart layout.

Monthly Payment Pricing is shown by creating a TextView in your layout, then passing that id to the affirm.writePromoToTextView() method along with other configuration details.

affirm.writePromoToTextView(promo, promoId, amount, logoType, affirmColor, promoCallback)
  • promo: Id to be used when displaying the payment pricing. 
  • amount: Representation of the price of the product (or cart).
  • promoId: Provided to you by Affirm.
  • logoType: Can be one of (AffirmDisplayTypeLogo | AffirmDisplayTypeText | AffirmDisplayTypeSymbol | AffirmDisplayTypeSymbolHollow).
  • affirmColor: Can be one of (AffirmColorTypeBlue | AffirmColorTypeBlack | AffirmColorTypeWhite). This is only required if affirmType is AffirmDisplayTypeText.

Note: Monthly Payment Pricing is displayed for amount that is $50 or above.

Product Modal

The Product Modal is shown by passing a valid Modal ID and amount in affirm.launchProductModal method using a onClickListener.

affirm.launchProductModal(MainActivity.this, amount, modalId);
  • modalId: Provided to you by Affirm (optional).
  • amount: Representation of the price of the product (or cart).
Site-Wide Modal

The Site-Wide Modal is shown by a valid Modal ID in affirm.launchSiteModal method using a onClickListener .

affirm.launchSiteModal(MainActivity.this, modalId);
  • modalId: Provided to you by Affirm (optional).

Affirm Checkout

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

2. Override onActivityResult so that affirm 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);
  }
}

3. Implement Checkout callbacks to handle successful, cancelled or error scenarios.

@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();
}

Authorization

Once the checkout has been successfully confirmed by the user,  onAffirmCheckoutSuccess 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.

Sample Application

A simple demo app which integrates Affirm can be found in the Affirm GitHub repository.