Skip to content

Most visited

Recently visited


In-app Billing API

The In-app Billing API makes it easier for you to integrate In-app Billing into your applications. The In-app Billing API supports a synchronous purchase flow, APIs to let you easily track ownership of consumable goods, and local caching of in-app purchase data.

Product Types

You define your products using the Google Play Console, including product type, SKU, price, description, and so on. For more information, see Administering In-app Billing. The In-app Billing API supports managed products and subscriptions.

Managed Products

Google Play tracks and manages the ownership information of managed products. When a user purchases a managed product, Google Play stores the purchase information for each product on a per-user basis. This enables you to later query Google Play at any time to restore the state of the products a specific user has purchased. This information is persistent on the Google Play servers even if the user uninstalls the application or if they change devices.

If you are using the In-app Billing API, you can also consume managed products within your application. You would typically implement consumption for products that can be purchased multiple times (such as in-game currency, fuel, or magic spells). Once purchased, a managed product cannot be purchased again until you consume the product, by sending a consumption request to Google Play. To learn more about managed product consumption, see Consuming Managed Products.


A subscription is a product type offered in In-app Billing that lets you sell content, services, or features to users from inside your app with recurring monthly or annual billing. You can sell subscriptions to almost any type of digital content, from any type of app or game. To understand how subscriptions work, see In-app Billing Subscriptions.

With the In-app Billing API, you can use the same purchase flow for buying subscriptions and retrieving subscription purchase information as with in-app products. For a code example, see Implementing Subscriptions.

Important: Unlike managed products, subscriptions cannot be consumed.

Purchasing Products

Figure 1. The basic sequence for a purchase request.

A typical purchase flow with the In-app Billing API is as follows:

  1. Your application sends an isBillingSupported request to Google Play to determine that the target version of the In-app Billing API that you are using is supported. The request also verifies that Google Play supports billing in the user's country.
  2. When your application starts or user logs in, it's good practice to check with Google Play to determine what items are owned by the user. To query the user's in-app purchases, send a getPurchases request. If the request is successful, Google Play returns a Bundle containing a list of product IDs of the purchased items, a list of the individual purchase details, and a list of the signatures for the purchases.
  3. Usually, you'll want to inform the user of the products that are available for purchase. To query the details of the in-app products that you defined in Google Play, your application can send a getSkuDetails request. You must specify a list of product IDs in the query request. If the request is successful, Google Play returns a Bundle containing product details including the product’s price, title, description, and the purchase type.
  4. If an in-app product is not owned by the user, you can initiate a purchase for it. To start a purchase request, your application sends a getBuyIntent request, specifying the product ID of the item to purchase, along with other parameters. You should record the product ID when you create a new in-app product in the Play Console.
    1. Google Play returns a Bundle that contains a PendingIntent which your application uses to start the checkout UI for the purchase.
    2. Your application launches the pending intent by calling the startIntentSenderForResult method.
    3. When the checkout flow finishes (that is, the user successfully purchases the item or cancels the purchase), Google Play sends a response Intent to your onActivityResult method. The result code of the onActivityResult has a result code that indicates whether the purchase was successful or canceled. The response Intent contains information about the purchased item, including a purchaseToken String that is generated by Google Play to uniquely identify this purchase transaction. The Intent also contains the signature of the purchase, signed with your private developer key.

To learn more about the In-app Billing API calls and server responses, see In-app Billing Reference.

Consuming In-app Products

You can use the consumption mechanism to track the user's ownership of managed products.

All managed products are managed in the In-app Billing API. This means that the user's ownership of all managed product purchases is maintained by Google Play, and your application can query the user's purchase information when needed. When the user successfully purchases a managed product, that purchase is recorded in Google Play. Once a managed product is purchased, it is considered to be "owned". Managed products in the "owned" state cannot be purchased from Google Play. You must send a consumption request for the "owned" managed product before Google Play makes it available for purchase again. Consuming the managed product reverts it to the "unowned" state, and discards the previous purchase data.

Figure 2. The basic sequence for a consumption request.

To retrieve the list of products owned by the user, your application sends a getPurchases call to Google Play. Your application can make a consumption request by sending a consumePurchase call. In the request argument, you must specify the managed product's unique purchaseToken string that you obtained from Google Play when it was purchased. Google Play returns a status code indicating if the consumption was recorded successfully.

Non-consumable and Consumable Managed Products

It's up to you to decide if you want to handle your managed products as non-consumable or consumable items.

Non-consumable products
Typically, you would not implement consumption for managed products that can only be purchased once in your application and provide a permanent benefit. Once purchased, these products will be permanently associated to the user's Google account. An example of a non-consumable managed product is a premium upgrade or a level pack.
Consumable products
In contrast, you can implement consumption for products that can be made available for purchase multiple times. Typically, these products provide certain temporary effects. For example, the user's in-game character might gain life points or gain extra gold coins in their inventory. Dispensing the benefits or effects of the purchased product in your application is called provisioning the managed product. You are responsible for controlling and tracking how managed products are provisioned to the users.

Important: Before provisioning the consumable managed product in your application, you must send a consumption request to Google Play and receive a successful response indicating that the consumption was recorded.

Managing consumable purchases in your application

Here is the basic flow for purchasing a consumable managed product:

  1. Call the getBuyIntent method to launch a purchase flow.
  2. Inspect the returned Bundle from Google Play to determine whether the purchase completed successfully.
  3. If the purchase was successful, consume the purchase by calling the consumePurchase method.
  4. Inspect the response code from Google Play to determine whether the consumption completed successfully.
  5. If the consumption was successful, provision the product in your application.

Subsequently, when the user starts up or logs in to your application, you should check if the user owns any outstanding consumable in-app products; if so, make sure to consume and provision those items. Here's the recommended application startup flow if you implement consumable in-app products in your application:

  1. Send a getPurchases request to query the owned in-app products for the user.
  2. If there are any consumable in-app products, consume the items by calling consumePurchase. This step is necessary because the application might have completed the purchase order for the consumable product, but stopped or got disconnected before the application had the chance to send a consumption request.
  3. Inspect the response code from Google Play to determine whether the consumption completed successfully.
  4. If the consumption was successful, provision the product in your application.

Local Caching

Because the Google Play client now caches In-app Billing information locally on the device, you can use the In-app Billing API to query for this information more frequently. The following In-app Billing API calls are serviced through cache lookups instead of requiring a network connection, which significantly speeds up the API's response time:

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)