/// <summary> /// Returns product info for the specified Ids /// </summary> /// <param name="productIds">Product Ids</param> /// <param name="productType">Product Type (either BillingClient.SkuType.Inapp or BillingClient.SkuType.Subs)</param> /// <returns></returns> public async Task <IEnumerable <Product> > LoadProductsAsync(string[] productIds, ProductType productType) { string skuType = GetBillingSkuType(productType); // Build the Sku Params SkuDetailsParams skuParams = SkuDetailsParams.NewBuilder() .SetSkusList(productIds) .SetType(skuType) .Build(); // Query the Play store QuerySkuDetailsResult queryResult = await _billingClient.QuerySkuDetailsAsync(skuParams); BillingResult result = queryResult?.Result; if (result == null) { // Failed to get products. Set the Exception to the Task, so the caller can react to the issue throw new InAppPurchaseException(PurchaseError.Unknown, "BillingResult is null"); } if (result.ResponseCode != BillingResponseCode.Ok) { PurchaseError purchaseError = result.ResponseCode.ToPurchaseError(); // Failed to get products. Set the Exception to the Task, so the caller can react to the issue throw new InAppPurchaseException(purchaseError, result.DebugMessage); } // Wait till the products are received in the callback IList <SkuDetails> skuDetails = queryResult?.SkuDetails; if (skuDetails == null) { skuDetails = new List <SkuDetails>(); } // Add more Skus to the Dictionary of SkuDetails // We need SkuDetails to initiate the Purchase foreach (SkuDetails sku in skuDetails) { _retrievedProducts.TryAdd(sku.Sku, sku); } // Return products return(skuDetails.Select(p => new Product { Name = p.Title, Description = p.Description, CurrencyCode = p.PriceCurrencyCode, FormattedPrice = p.Price, ProductId = p.Sku, MicrosPrice = p.PriceAmountMicros, LocalizedIntroductoryPrice = p.IntroductoryPrice, MicrosIntroductoryPrice = p.IntroductoryPriceAmountMicros })); }
public void OnBillingSetupFinished(BillingResult result) { Log.Debug(TAG, "OnBillingSetupFinished()"); if (result.ResponseCode != BillingResponseCode.Ok) { Log.Debug(TAG, "Billing setup failed with code " + result.ResponseCode.ToString()); } SkuDetailsParams.Builder details_builder = SkuDetailsParams.NewBuilder(); details_builder.SetSkusList(skuList).SetType(BillingClient.SkuType.Inapp); billingClient.QuerySkuDetails(details_builder.Build(), this); }
/// <summary> /// Get All purchases regardless of status /// </summary> /// <param name="itemType"></param> /// <param name="verifyPurchase"></param> /// <returns></returns> public async Task <List <PurchaseResult> > GetPurchasesAsync(ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null, string verifyOnlyProductId = null) { if (BillingClient == null || !BillingClient.IsReady) { await ConnectAsync(); } var prms = SkuDetailsParams.NewBuilder(); var type = itemType == ItemType.InAppPurchase ? BillingClient.SkuType.Inapp : BillingClient.SkuType.Subs; var purchaseResult = BillingClient.QueryPurchases(type); var purchases = await GetPurchasesAsync(purchaseResult.PurchasesList); return(purchases); }
public Task <QuerySkuDetailsResult> QuerySkuDetailsAsync(SkuDetailsParams skuDetailsParams) { var tcs = new TaskCompletionSource <QuerySkuDetailsResult>(); var listener = new InternalSkuDetailsResponseListener { SkuDetailsResponseHandler = (r, s) => tcs.TrySetResult(new QuerySkuDetailsResult { Result = r, SkuDetails = s }) }; QuerySkuDetails(skuDetailsParams, listener); return(tcs.Task); }
/// <summary> /// Get Product Information with Prices /// </summary> /// <param name="productIds">Skus of products</param> /// <param name="itemType">Subscription or iap product</param> /// <returns></returns> public async Task <List <InAppBillingProduct> > GetProductsAsync(List <string> productIds, ItemType itemType = ItemType.InAppPurchase) { if (BillingClient == null || !BillingClient.IsReady) { await ConnectAsync(); } _tcsProducts = new TaskCompletionSource <List <InAppBillingProduct> >(); var prms = SkuDetailsParams.NewBuilder(); var type = itemType == ItemType.InAppPurchase ? BillingClient.SkuType.Inapp : BillingClient.SkuType.Subs; prms.SetSkusList(productIds).SetType(type); BillingClient.QuerySkuDetailsAsync(prms.Build(), this); return(await _tcsProducts?.Task ?? default); }