This document explains how to implement functionality specific to one-time products.
Google Play Billing supports the following types of one-time products:
Non-consumable one-time products are products that provide a permanent effect, such as a premium upgrade. To avoid users from repurchasing these products, you shouldn't indicate them as being consumed.
Consumable one-time products are products that provide temporary benefits and can be repurchased, such as additional in-game currency or extra game lives. To make a consumable one-time product available for purchase again, you need to send a consumption request to Google Play.
Indicate a one-time product has been consumed
To indicate that a one-time product has been consumed, call
consumeAsync()
on your instance of
BillingClient
and include the purchase token that Google Play should make available for
repurchase. You must also pass an object that implements the
ConsumeResponseListener
interface. This object handles the result of the consumption operation. You can
override the
onConsumeResponse()
method of the
ConsumeResponseListener
interface, which the Google Play Billing Library calls when the operation is
complete.
Successful purchases generate a purchase token, which is a unique identifier
representing a single in-app product that a user has purchased. You can also
retrieve the token associated by calling
getPurchaseToken()
on a Purchase
object.
The following example illustrates consuming a product using the associated purchase token:
Kotlin
val consumeParams =
ConsumeParams.newBuilder()
.setPurchaseToken(/* token */)
.setDeveloperPayload(/* payload */)
.build()
billingClient.consumeAsync(consumeParams, { billingResult, outToken ->
if (billingResult.responseCode == BillingResponse.OK) {
// Handle the success of the consume operation.
// For example, increase the number of coins inside the user's basket.
}
})
Java
ConsumeParams consumeParams =
ConsumeParams.newBuilder()
.setPurchaseToken(/* token */)
.setDeveloperPayload(/* payload */)
.build();
ConsumeResponseListener listener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(BillingResult billingResult, String outToken) {
if (billingResult.getResponseCode() == BillingResponse.OK) {
// Handle the success of the consume operation.
// For example, increase the number of coins inside the user's basket.
}
};
billingClient.consumeAsync(consumeParams, listener);
Because consumption requests can occasionally fail, you must check your secure backend server to ensure that each purchase token hasn't been used. Alternatively, you can wait until you receive a successful consumption response from Google Play before you provision the item. If you choose to withhold purchases from the user until Google Play sends a successful consumption response, you must be very careful not to lose track of the purchase after the consumption request.
Implement a promotion for a one-time product
Promotions, or promo codes, let you give away one-time products or subscription trials free-of-charge to a limited number of users. To implement promo codes for one-time products, see Implement a promotion.
Next steps
After you have added one-time product-specific features, see Best Practices.

