Introduction: Support Android Google Play and Amazon in-app billing (IAP) payments with one API
More: Author   ReportBugs   

Circle CI Release GitHub license

Support both Google Play and Amazon Kindle Fire in-app purchase payments with a single API

Handy for small apps with in-app purchase (IAP) items that need both Google Play store and Amazon App Store support - i.e. regular Android devices and Amazon Kindle Fire. We developed this as a convenient way to keep multiple apps updated with the latest IAP code for Play and Amazon.


A simple wrapper library that provides sample Google and Amazon in-app purchase APIs in a single API.


Not supported:

  • receipt validation (either local or server)
  • consumable items

Similar Libraries

This library is in the same category as OpenIAB (supports many more stores), OPFLab (replacement for OpenIAB). If you do not need Amazon support, there are several libraries that support just the Play store (see the ).

Installation Instructions

Add the repository to your root build.gradle:

allprojects {
    repositories {
        maven { url "" }

Add a dependency to your application related build.gradle

dependencies {
    compile 'com.github.eggheadgames:android-in-app-payments:<actual version>'



The following code snippet initializes the billing module:, IAPManager.BUILD_TARGET_GOOGLE, skuList /*can be ignored for Google traget*/);
    IAPManager.addPurchaseListener(new PurchaseServiceListener() {
            public void onPricesUpdated(Map<String, String> map) {
                // list of available products will be received here, so you can update UI with prices if needed

            public void onProductPurchased(String sku) {
                // will be triggered whenever purchase succeeded 

            public void onProductRestored(String sku) {
                // will be triggered fetching owned products using IAPManager.init();
    IAPManager.init(googleIapKey /*can be ignored for Amazon target*/);
  1. Setup billing module. context, int buildTarget, List<String> skuList)

int buildTarget can be either IAPManager.BUILD_TARGET_GOOGLE or IAPManager.BUILD_TARGET_AMAZON List<String> skuList - a list of products to fetch information about (relevant only for IAPManager.BUILD_TARGET_AMAZON)

  1. Request info about available and owned products
    IAPManager.init(String rot13LicenseKey)

String rot13LicenseKey is relevant only for IAPManager.BUILD_TARGET_GOOGLE, and can be ignored for IAPManager.BUILD_TARGET_AMAZON. Note that this is the required Google License Key obtained from the app's Google Play console, after applying the ROT 13 algorithm. You might choose to store the key as ROT-13 in your app to avoid casual decoding of the strings, however, this is not really secure, so you are advised to follow Google's advice and then ROT-13 the key before passing it to the API:

Security Recommendation: Google highly recommends that you do not hard-code the exact public license key string value as provided by Google Play. Instead, construct the whole public license key string at runtime from substrings or retrieve it from an encrypted store before passing it to the constructor. This approach makes it more difficult for malicious third parties to modify the public license key string in your APK file.

Buying a product

To buy a product use the following method: activity, String sku, int requestCode);

PurchaseServiceListener will notify application about the operation result


The following listener can be used to obtain owned subscriptions and to get notification about subscription operation result

    IAPManager.addSubscriptionListener(new SubscriptionServiceListener() {
        public void onSubscriptionRestored(String s) {
            // will be triggered upon fetching owned subscription using IAPManager.init();

        public void onSubscriptionPurchased(String s) {
            // will be triggered whenever subscription succeeded

        public void onPricesUpdated(Map<String, String> map) {
            // list of available products will be received here, so you can update UI with prices if needed            

To start a subscription use the following method:

IAPManager.subscribe(Activity activity, String sku, int requestCode);

String sku - a subscription ID int requestCode - a unique request code to be used to deliver result through onActivityResult SubscriptionServiceListener.onSubscriptionPurchased() will notify application about successful operation result

Use the following method to remove subscription

IAPManager.unsubscribe(Activity activity, String sku, int requestCode);

Please keep in mind that for Google In App Billing it will just lead user to the Google Pay Account Settings page where user may cancel subscription manually.


When you are integrating Google In App Billing Subscriptions into your application please pay attention for the subscription cancellation handling. As long as currently subscription can be cancelled only through Google Play Account settings - application won't be notified about this event. Thus you have to query for the owned subscriptions each time you open the application (if needed), which is done via IAPManager.init() method.

Support Me
About Me
Google+: Trinea trinea
GitHub: Trinea