buyConsumable method
Buy a consumable product.
Consumable items can be "consumed" to mark that they've been used and then bought additional times. For example, a health potion.
To restore consumable purchases across devices, you should keep track of those purchase on your own server and restore the purchase for your users. Consumed products are no longer considered to be "owned" by payment platforms and will not be delivered by calling restorePurchases.
Consumable items are defined differently by the different underlying
payment platforms, and there's no way to query for whether or not the
ProductDetail is a consumable at runtime.
autoConsume is provided as a utility and will instruct the plugin to
automatically consume the product after a succesful purchase.
autoConsume is true by default.
This method does not return the result of the purchase. Instead, after
triggering this method, purchase updates will be sent to
purchaseStream. You should Stream.listen to
purchaseStream to get PurchaseDetails objects in different
PurchaseDetails.status and update your UI accordingly. When the
PurchaseDetails.status is PurchaseStatus.purchased or
PurchaseStatus.error, you should deliver the content or handle the
error, then call completePurchase to finish the purchasing process.
This method does return whether or not the purchase request was initially sent succesfully.
See also:
- buyNonConsumable, for buying a non consumable product or subscription.
- restorePurchases, for restoring non consumable products.
Calling this method for non consumable items will cause unwanted behaviors!
Implementation
@override
Future<bool> buyConsumable({
required PurchaseParam purchaseParam,
bool autoConsume = true,
}) {
if (autoConsume) {
_productIdsToConsume.add(purchaseParam.productDetails.id);
}
return buyNonConsumable(purchaseParam: purchaseParam);
}