Some purchases are used to indicate additional features that are not initially available to the user. Other products are consumable products and only provide a once-off feature, which will have to be re-purchased to be re-used. These products are consumable products and only provide a once-off feature.
Some products are meant to be consumed, or exhausted, when used; the user is required to purchase them again before they can be reused:
ConsumePurchase()
method:var success = billing.ConsumePurchase(purchase);
Purchase
instance but rather just the purchase token. When a product is purchased, we can just store the purchase token and use that:var token = purchase.PurchaseToken; var success = billing.ConsumePurchase(token);
OnPurchaseConsumed
event:billing.OnPurchaseConsumed += (token) => { // consumed product };
OnPurchaseConsumedError
event:billing.OnPurchaseConsumedError += (code, token) => { // error consuming the purchase };
Besides subscriptions, there are two main types of products: consumables and nonconsumables. Consumable products are meant to be purchased and then used once. To make use of the product again, they have to be repurchased. Nonconsumable products are only bought once and can be reused without having to be repurchased. If we want the user to repurchase the product, we have to first consume it.
A nonconsumable product is a product that is bought once and never expires. An example of this type of product would be a feature, such as the removal of ads. Although it is possible to consume this product, we wouldn't.
Product consumption can be done after a period from the time of being bought or directly after the purchase. An example of a consumable purchase would be in-game money, where we would want the user to be able to buy the same amount multiple times.
In the case of money, we would actually consume the purchase immediately but track the total amount separately. Then, as the player uses the money, we would subtract from the local wallet. To protect against data loss, we would also backup or sync the wallet to an online storage. This will also allow the user to resume the game from a new device.
To consume a purchase, we can either pass the Purchase
instance or the purchase token to the ConsumePurchase()
method. This method will return true
if the purchase is successful, or false
if there is an error.
In addition to the return value, the OnPurchaseConsumed
event will be raised when the consumption is successful. If there is an error, the OnPurchaseConsumedError
will be raised.