Listing purchased products
After the user has purchased products or subscriptions, we need to be able to adjust the app accordingly when the app is launched the next time.
How to do it...
We can access the list of purchased products through the GetPurchases()
method:
- We list purchased products by passing the
Product
item type to theGetPurchases()
method:var prods = billing.GetPurchases(ItemType.Product);
- To list purchased subscriptions, we pass the
Subscription
item type instead:var subs = billing.GetPurchases(ItemType.Subscription);
- The
GetPurchases()
method returns a collection ofPurchase
instances, each of which contain data that describe the purchase:Purchase purchase = prods[0]; string id = purchase.ProductId; string token = purchase.PurchaseToken; string payload = purchase.DeveloperPayload;
- If there are any errors processing the request, we can handle them in the error events:
billing.OnGetProductsError += (code, bundle) => { // error loading the purchased items }; billing.OnInvalidOwnedItemsBundleReturned...