Migrate from Google Play IAB v3.0 to Amazon IAP v2.0

This page discusses the differences between Google Play's In-App Billing (IAB) and Amazon's In-app Purchasing (IAP) and gives a high-level description of how to adapt your app to use both API sets.

What are IAB and IAP?

Google Play's In-App Billing feature allows users to make purchases of virtual items directly from your app. For example, a user can purchase additional levels to a game that he or she is playing. Amazon's In-App Purchasing is the equivalent feature for Amazon APIs. If you have an app that uses Google Play's In-App Billing feature, you can easily modify your code to use Amazon's equivalent In-App Purchasing feature. Both API sets have similar functionality with some differences in naming and terminology.

Requirements for the Amazon Appstore and Amazon devices

If you will be submitting an app that implement's Google Play's IAB to the Amazon Appstore to be made available to run on Amazon devices, such as Fire tablets, your app will need to implement Amazon's IAP for in-app purchases. Google Play's IAB will not work on Amazon devices.

Amazon IAP v2.0 vs. Google Play IAB v3.0

This section discusses the similarities and differences between Google Play's IAB v3.0 and Amazon's IAP v2.0.

Feature Comparison

The table below shows a comparison between Amazon's IAP API and Google Play's IAB API.

Feature IAP v2.0 (Amazon) IAB v3.0 (Google Play) Comments
Intents handled by API. Y N
Framework of simple API calls provided. Y N
Individual consumables may be purchased multiple times. Y Y
Purchased once. Users notified if they try to purchase an entitlement they already own. Y Y
Variety of options for time period that a subscription runs. Y Y Amazon's options: Weekly, Bi-weekly, Monthly, Bi-monthly, Quarterly, Semi-annually, Annually Google Play's options: Monthly, Annually, Seasonal (custom)
Supports free trial periods. Y Y
Auto-renew option. Y Y
Deferred billing option. N Y
Receipt verification
Receipt verification service for purchases Y Y Although Google Play does provide receipt verification, Google Play's receipt verification process is not automated.

Google Play's Managed Objects vs. Amazon's Consumables and Entitlements

While Google Play's IAB and Amazon's IAP both let your customers make the same types of in-app purchases, Google Play and Amazon use different terminology for their purchase types. The following table notes the Google Play equivalent for each Amazon purchase type:

Amazon Description Google Play Equivalent Examples
Consumable Purchase that is made, then consumed within the app, typically a game. May be purchased multiple times. Managed In-app products Extra lives or moves (within a game), extra ammunition for an in-game character.
Entitlement One-time purchase to unlock access to features or content within an app or game. Managed In-app products Unlock extra levels within a game or "premium member only" features within an app.
Subscription Offers access to a premium set of content or features for a limited period of time. Subscription Online magazine subscription, fantasy football league access.

As you can see, Google Play's IAB treats all non-subscription purchases similarly; an item is purchased, then consumed by a user. Once an item has been consumed, the item is provisioned in the app and the consumption is recorded. For items that are likely to be one-time purchases, such as unlocking new game levels, you have the option as a developer of treating the item as a consumable or non-consumable and introducing logic to ensure that the purchase of that item only occurs once. With Amazon's IAP, these one-time purchases are separated by design from purchases, such as extra lives, that app users might purchase again and again.

Porting Your Code

This section will walk you through porting an App from Google Play's IAB API to the Amazon IAP API:

  1. Configure your AndroidManifest.xml file to support Amazon's IAP.
  2. In your app, implement logic to mediate between IAB and IAP.
  3. Add and implement the Amazon IAP API.
  4. Test your app.

Configuring Your AndroidManifest.xml File

Configure your AndroidManifest.xml file to define the IAP Response Receiver for your app. The IAP Response Receiver ensures that the intent communication from the Amazon Client is intercepted by your app. Note that if you are supporting both Google Play's IAB and Amazon's IAP, you do not need to remove elements related to IAB; they will simply be ignored by IAP.

In your AndroidManifest.xml file, add the appropriate <receiver> tag for the IAP ResponseReceiver:

    <receiver android:name="com.amazon.inapp.iap.ResponseReceiver">
            <action android:name="com.amazon.inapp.purchasing.NOTIFY" android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY">

Implementing Logic to Mediate Between IAB and IAP

You can use the same code base for your app, regardless of where your app is hosted. Just add logic to your app to determine whether the app was downloaded from the Amazon Appstore or from Google Play. Depending on where the user downloaded the app, execute the appropriate methods for either IAP or IAB.

The following example code determines whether a package was installed from Google Play or the Amazon Appstore:

PackageManager pkgManager = context.getPackageManager();

 String installerPackageName = pkgManager.getInstallerPackageName(context.getPackageName());

 if(installerPackageName.startsWith("com.amazon")) {
 // Amazon
 } else if ("com.android.vending".equals(installerPackageName)) {
 // Google Play

Adding and Implementing the Amazon IAP API

For the most part, Amazon's IAP works similarly to Google Play's IAB. When you create the path in your code to implement the IAP API, you should be able to use a similar logic flow to IAB, but will need to account for different class and method names.

The following table maps the most frequently used IAP methods to their IAB equivalents:

PurchasingService method PurchasingListener callback Response object Equivalent IAB call
getUserData() onUserDataResponse() UserDataResponse N/A
getPurchaseUpdates() onPurchaseUpdatesResponse() PurchaseUpdatesResponse getPurchases()
getProductData() onProductDataResponse() ProductDataResponse getSkuDetails()
purchase() onPurchaseResponse() PurchaseResponse getBuyIntent()
notifyFulfillment() N/A N/A consumePurchase()

Note that Amazon's notifyFulfillment() call and Google Play's consumePurchase() call correlate with each other somewhat. Calling consumePurchase()on a managed item for IAB will return the item's state to "unpurchased", essentially converting it to a consumable. After that, the receipt will no longer appear in the response from subsequent calls to getPurchases(). Amazon will return the receipts for consumable items in calls to getPurchaseUpdates() until the app calls notifyFulfillment().

For more information about the classes and methods of IAP, see the In-App Purchasing API Reference v2.0.

Testing Your App

Download and install the App Tester tool to test your IAP v2.0-integrated app. Follow the instructions and links in Testing In-App Purchasing (IAP) to install and use App Tester.

After testing your app locally, you can use the Live App Testing service to beta test your app in a live production environment with a select group of users.