Android Interface Definition Language (AIDL)

print

Purchasing Products

Figure 1. The basic sequence for a purchase request.

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

 

Consuming In-app Products

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

Figure 2. The basic sequence for a consumption request.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.