public async Task <bool> Initialize() { // Create a filtered list of the product add-ons that are consumable string[] filterList = new string[] { "Consumable" }; var addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList); if (addOns.ExtendedError != null) { if (addOns.ExtendedError.HResult == IAP_E_UNEXPECTED) { return(false); } } // Sort the list by price, lowest to highest foreach (StoreProduct product in addOns.Products.Values.OrderBy(x => x.Price.FormattedBasePrice.AsDouble())) { Consumables.Add(product); } // Get the current purchased balance from the Store Balance = await GetConsumableBalance(); return(true); }
public async void GetAddOnInfo() { if (context == null) { context = StoreContext.GetDefault(); // If your app is a desktop app that uses the Desktop Bridge, you // may need additional code to configure the StoreContext object. // For more info, see https://aka.ms/storecontext-for-desktop. } // Specify the kinds of add-ons to retrieve. string[] productKinds = { "Durable", "Consumable", "UnmanagedConsumable" }; List <String> filterList = new List <string>(productKinds); workingProgressRing.IsActive = true; StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(filterList); workingProgressRing.IsActive = false; if (queryResult.ExtendedError != null) { // The user may be offline or there might be some other server failure. textBlock.Text = $"ExtendedError: {queryResult.ExtendedError.Message}"; return; } foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products) { // Access the Store product info for the add-on. StoreProduct product = item.Value; BMBBT.Content = "赞助我" + item.Value.Price.FormattedPrice; // Use members of the product object to access listing info for the add-on... } }
private async Task <StorePurchaseResult> PurchaseAddOn(string InAppOfferToken) { string[] filterList = new string[] { "Durable" }; if (UtilityData.addOnCollection == null || UtilityData.addOnCollection.ExtendedError != null) { UtilityData.addOnCollection = await storeContext.GetUserCollectionAsync(filterList); } var isPurchasedList = UtilityData.addOnCollection.Products.Values.Where(p => p.InAppOfferToken.Equals(InAppOfferToken)).ToList(); if (isPurchasedList.Count == 0) { if (UtilityData.addOnsAssociatedStoreProducts == null) { UtilityData.addOnsAssociatedStoreProducts = await storeContext.GetAssociatedStoreProductsAsync(filterList); } var AddOnList = UtilityData.addOnsAssociatedStoreProducts.Products.Values.Where(p => p.InAppOfferToken.Equals(InAppOfferToken)).ToList(); StorePurchaseResult result = await storeContext.RequestPurchaseAsync(AddOnList[0].StoreId); return(result); } return(null); }
private async Task <StoreProduct> GetSubscriptionProductAsync() { // Load the sellable add-ons for this app and check if the trial is still // available for this customer. If they previously acquired a trial they won't // be able to get a trial again, and the StoreProduct.Skus property will // only contain one SKU. StoreProductQueryResult result = await context.GetAssociatedStoreProductsAsync(new string[] { "Durable" }); if (result.ExtendedError != null) { System.Diagnostics.Debug.WriteLine("Something went wrong while getting the add-ons. " + "ExtendedError:" + result.ExtendedError); return(null); } // Look for the product that represents the subscription. foreach (var item in result.Products) { StoreProduct product = item.Value; if (product.StoreId == subscriptionStoreId) { return(product); } } System.Diagnostics.Debug.WriteLine("The subscription was not found."); return(null); }
private async Task <StoreProduct> GetAdFreeSubscriptionProductAsync() { // Load the sellable add-ons for this app and check if the trial is still // available for this customer. If they previously acquired a trial they won't // be able to get a trial again, and the StoreProduct.Skus property will // only contain one SKU. StoreProductQueryResult result = await storeContext.GetAssociatedStoreProductsAsync(new string[] { "Durable" }); if (result.ExtendedError != null) { await Helpers.ShowDialog(ResourceStringNames.errorGettingAddOnsFormat.GetResourceString().FormatString(result.ExtendedError)); return(null); } // Look for the product that represents the subscription. foreach (var item in result.Products) { StoreProduct product = item.Value; if (product.StoreId == adFreeSubscriptionStoreId) { return(product); } } await Helpers.ShowDialog(ResourceStringNames.subscriptionToPurchaseNotFound.GetResourceString()); return(null); }
private async Task GetAssociatedProductsButton_Click(object sender, RoutedEventArgs e) { // Create a filtered list of the product AddOns I care about string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" }; // Get list of Add Ons this app can sell, filtering for the types we know about StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList); }
private async void GetUnmanagedConsumablesButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { string[] filterList = new string[] { "UnmanagedConsumable" }; // Get list of Add Ons this app can sell, filtering for the types we know about. StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList); ProductsListView.ItemsSource = Utils.CreateProductListFromQueryResult(addOns, "UnmanagedConsumable Add-Ons"); }
public async void LoadStoreItems() { // Create a filtered list of the product AddOns I care about string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" }; // Get list of Add Ons this app can sell, filtering for the types we know about StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList); ProductsListView.ItemsSource = await CreateProductListFromQueryResult(addOns, "Add-Ons"); }
public async void GetSubscriptionsInfo() { if (context == null) { context = StoreContext.GetDefault(); // If your app is a desktop app that uses the Desktop Bridge, you // may need additional code to configure the StoreContext object. // For more info, see https://aka.ms/storecontext-for-desktop. } // Subscription add-ons are Durable products. string[] productKinds = { "Durable" }; List <String> filterList = new List <string>(productKinds); workingProgressRing.IsActive = true; StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(productKinds); workingProgressRing.IsActive = false; if (queryResult.ExtendedError != null) { // The user may be offline or there might be some other server failure. textBlock.Text = $"ExtendedError: {queryResult.ExtendedError.Message}"; return; } foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products) { // Access the Store product info for the add-on. StoreProduct product = item.Value; // For each add-on, the subscription info is available in the SKU objects in the add-on. foreach (StoreSku sku in product.Skus) { if (sku.IsSubscription) { // Use the sku.SubscriptionInfo property to get info about the subscription. // For example, the following code gets the units and duration of the // subscription billing period. StoreDurationUnit billingPeriodUnit = sku.SubscriptionInfo.BillingPeriodUnit; uint billingPeriod = sku.SubscriptionInfo.BillingPeriod; } } } }
public async void DemonstrateTargetedOffers() { // Get the Microsoft Account token for the current user. string msaToken = await GetMicrosoftAccountTokenAsync(); if (string.IsNullOrEmpty(msaToken)) { System.Diagnostics.Debug.WriteLine("Microsoft Account token could not be retrieved."); return; } // Get the targeted Store offers for the current user. List <TargetedOfferData> availableOfferData = await GetTargetedOffersForUserAsync(msaToken); if (availableOfferData == null || availableOfferData.Count == 0) { System.Diagnostics.Debug.WriteLine("There was an error retrieving targeted offers," + "or there are no targeted offers available for the current user."); return; } // Get the product ID of the add-on that is associated with the first available offer // in the response data. TargetedOfferData offerData = availableOfferData[0]; string productId = offerData.Offers[0]; // Get the Store ID of the add-on that has the matching product ID, and then purchase the add-on. List <String> filterList = new List <string>(productKinds); StoreProductQueryResult queryResult = await storeContext.GetAssociatedStoreProductsAsync(filterList); foreach (KeyValuePair <string, StoreProduct> result in queryResult.Products) { if (result.Value.InAppOfferToken == productId) { await PurchaseOfferAsync(result.Value.StoreId); return; } } System.Diagnostics.Debug.WriteLine("No add-on with the specified product ID could be found " + "for the current app."); return; }
public async override Task <IEnumerable <InAppBillingProduct> > GetProductInfoAsync(ItemType itemType, params string[] productIds) { // Create a filtered list of the product AddOns I care about string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" }; // Get list of Add Ons this app can sell, filtering for the types we know about StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList); if (addOns.ExtendedError != null) { Debug.WriteLine("GetProductInfoAsync Extended Error:" + addOns.ExtendedError.ToString()); throw new InAppBillingPurchaseException(PurchaseError.GeneralError, addOns.ExtendedError); } StoreProduct product; var products = new List <InAppBillingProduct>(); foreach (KeyValuePair <string, StoreProduct> kvp in addOns.Products) { Debug.WriteLine("Store Product: key" + kvp.Key + " Product:" + kvp.Value.InAppOfferToken + " " + kvp.Value.StoreId + " " + kvp.Value.ToString()); foreach (string pid in productIds) { if (pid.CompareTo(kvp.Value.InAppOfferToken) == 0) { product = kvp.Value; products.Add(new InAppBillingProduct { Name = product.Title, Description = product.Description, ProductId = kvp.Value.InAppOfferToken, LocalizedPrice = product.Price.FormattedPrice, CurrencyCode = product.Price.CurrencyCode //CurrencyCode = product.CurrencyCode // Does not work at the moment, as UWP throws an InvalidCastException when getting CurrencyCode }); } } } lastListOfProducts = addOns.Products.Values; return(products); }
private async void Enumerate_Optional_Packages_From_Store(object sender, RoutedEventArgs e) { try { String[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" }; StoreProductQueryResult addOns = await context.GetAssociatedStoreProductsAsync(filterList); foreach (var addOn in addOns.Products) { StoreProductControl spc = new StoreProductControl(); spc.PackageName = addOn.Value.Title; spc.DataContext = addOn.Value; storeOptionalPackagesList.Add(spc); } } catch (Exception ex) { await new MessageDialog("Unable to enumerate store optional packages. {" + ex.Message + "}").ShowAsync(); } }
private static async Task <StoreProduct> GetAddOn(string id) { if (_productsCache.ContainsKey(id)) { return(_productsCache[id]); } if (!NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable) { return(null); } if (_context == null) { _context = StoreContext.GetDefault(); } /// Get all add-ons for this app. var result = await _context.GetAssociatedStoreProductsAsync(new string[] { "Durable", "Consumable" }); if (result.ExtendedError != null) { return(null); } foreach (var item in result.Products) { var product = item.Value; if (product.InAppOfferToken == id) { _productsCache.TryAdd(id, product); return(product); } } return(null); }
public async Task <Response <List <AddOnItem> > > GetAllAddOns() { if (IsStoreContextTypePresent) { StoreContext storeContext = StoreContext.GetDefault(); Response <List <AddOnItem> > response = new Response <List <AddOnItem> >(); string[] productKinds = { "Durable", "Consumable", "UnmanagedConsumable" }; StoreProductQueryResult queryResult = await storeContext.GetAssociatedStoreProductsAsync(productKinds); if (queryResult.ExtendedError != null) { response.IsError = true; response.Message = queryResult.ExtendedError.Message; response.Error = queryResult.ExtendedError; } else { List <AddOnItem> ret = new List <AddOnItem>(); IReadOnlyDictionary <string, StoreLicense> licenses = await GetAddOnLicenses(); foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products) { AddOnItem addOn = new AddOnItem(item.Value); var matchingPair = licenses.FirstOrDefault(p => p.Key.StartsWith(item.Key)); StoreLicense license = matchingPair.Value; addOn.IsActive = license?.IsActive ?? false; addOn.ExpiryDate = license?.ExpirationDate ?? default(DateTimeOffset); ret.Add(addOn); } response.Content = ret; } return(response); } else { return(new Response <List <AddOnItem> >()); } }
public async Task InitializationAsyn() { if (_isLoaded) { return; } string[] productKinds = { "UnmanagedConsumable" }; var queryResult = await _storeContext.GetAssociatedStoreProductsAsync(productKinds); foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products) { DonateItemViewModel donateItem = new DonateItemViewModel { Title = DonateUtility.GetValidurchaseName(item.Value.InAppOfferToken), StoreId = item.Key, Price = item.Value.Price.FormattedPrice }; Items.Add(donateItem); } _isLoaded = true; }
public async void GetAddOnInfo() { if (context == null) { context = StoreContext.GetDefault(); } string[] productKinds = { "Durable", "Consumable", "UnmanagedConsumable" }; List <String> filterList = new List <string>(productKinds); StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(filterList); if (queryResult.ExtendedError != null) { logger.Error("Could not get add-on info: " + queryResult.ExtendedError.Message); return; } foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products) { StoreProduct product = item.Value; } }
private async void GetAssociatedProducts() { if (context == null) { context = StoreContext.GetDefault(); // If your app is a desktop app that uses the Desktop Bridge, you // may need additional code to configure the StoreContext object. // For more info, see https://aka.ms/storecontext-for-desktop. } // Create a filtered list of the product AddOns I care about string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" }; StoreProductQueryResult addOns = null; try { // Get list of Add Ons this app can sell, filtering for the types we know about addOns = await context.GetAssociatedStoreProductsAsync(filterList); } catch { var dialog = new MessageDialog("Could not load Products..."); } ProductsListView.ItemsSource = await Utils.CreateProductListFromQueryResult(addOns, "Add-Ons"); }
public async void CheckTrialStatus() { string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" }; StoreAppLicense license = await storeContext.GetAppLicenseAsync(); StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList); if (license.IsActive) { if (license.IsTrial) { UpdateTile("Trial license"); } else { UpdateTile("Full license"); } } else { UpdateTile(license.ToString()); ShowToast(license.ToString()); } }
/// <summary> /// gets Iaps and Subs /// </summary> /// <param name="ProductIds"></param> /// <param name="itemType">not used for UWP</param> /// <returns></returns> public async Task <List <InAppBillingProduct> > GetProductsAsync(List <string> ProductIds, ItemType itemType = ItemType.InAppPurchase) { var Products = new List <InAppBillingProduct>(); if (context == null) { context = StoreContext.GetDefault(); // If your app is a desktop app that uses the Desktop Bridge, you // may need additional code to configure the StoreContext object. // For more info, see https://aka.ms/storecontext-for-desktop. } // Subscription add-ons are Durable products. string[] productKinds = { "Durable", "Subscription" }; var filterList = new List <string>(productKinds); StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(productKinds); if (queryResult.ExtendedError != null) { // The user may be offline or there might be some other server failure. throw new Exception(queryResult.ExtendedError.Message, queryResult.ExtendedError.InnerException); } if (queryResult?.Products?.Count > 0) { foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products) { // Access the Store product info for the add-on. if (item.Value != null) { StoreProduct product = item.Value; if (product.Skus != null) { // For each add-on, the subscription info is available in the SKU objects in the add-on. foreach (StoreSku sku in product.Skus) { if (sku.IsSubscription && sku.SubscriptionInfo != null) { // Use the sku.SubscriptionInfo property to get info about the subscription. // For example, the following code gets the units and duration of the // subscription billing period. StoreDurationUnit billingPeriodUnit = sku.SubscriptionInfo.BillingPeriodUnit; uint billingPeriod = sku.SubscriptionInfo.BillingPeriod; Products.Add(new InAppBillingProduct() { ProductId = product.InAppOfferToken, LocalizedPrice = product.Price.FormattedRecurrencePrice, Description = sku.Description, Name = product.Title, FreeTrialPeriod = sku.SubscriptionInfo.HasTrialPeriod ? sku.SubscriptionInfo.TrialPeriod + " " + sku.SubscriptionInfo.TrialPeriodUnit.ToString() : null }); } else if (ProductIds?.Count > 0 && ProductIds.Contains(product.InAppOfferToken)) { Products.Add(new InAppBillingProduct() { ProductId = product.InAppOfferToken, LocalizedPrice = product.Price.FormattedPrice, Description = sku.Description, Name = product.Title }); } } } } } } return(Products); }
private async Task PurchaseInAppPurchase(string Product, string strRoaming) { try { if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3)) { string[] filterList = new string[] { "Durable" }; if (UtilityData.addOnCollection == null || UtilityData.addOnCollection.ExtendedError != null) { UtilityData.addOnCollection = await storeContext.GetUserCollectionAsync(filterList); } var isPurchasedList = UtilityData.addOnCollection.Products.Values.Where(p => p.InAppOfferToken.Equals(Product)).ToList(); if (isPurchasedList.Count == 0) { if (UtilityData.addOnsAssociatedStoreProducts == null) { UtilityData.addOnsAssociatedStoreProducts = await storeContext.GetAssociatedStoreProductsAsync(filterList); } var AddOnList = UtilityData.addOnsAssociatedStoreProducts.Products.Values.Where(p => p.InAppOfferToken.Equals(Product)).ToList(); StorePurchaseResult result = await storeContext.RequestPurchaseAsync(AddOnList[0].StoreId); if (result != null) { switch (result.Status) { case StorePurchaseStatus.AlreadyPurchased: break; case StorePurchaseStatus.Succeeded: ApplicationData.Current.RoamingSettings.Values[strRoaming] = true; UtilityClass.MessageDialog("Thank You very much for Purchasing. We really appreciate your kind support!", "Thank You very much! :)"); break; case StorePurchaseStatus.NetworkError: case StorePurchaseStatus.ServerError: UtilityClass.MessageDialog("An Error Occured , Please Try Again!", "Error occured while purchasing."); break; } } } } else { if (UtilityData.AppLicenseInformation == null) { UtilityData.AppLicenseInformation = CurrentApp.LicenseInformation; } if (!UtilityData.AppLicenseInformation.ProductLicenses[Product].IsActive) { try { PurchaseResults results = await CurrentApp.RequestProductPurchaseAsync(Product); if (results.Status == ProductPurchaseStatus.Succeeded) { ApplicationData.Current.RoamingSettings.Values[strRoaming] = UtilityData.AppLicenseInformation.ProductLicenses[Product].IsActive; BlankPage4.ncSettings.setSettings = "IAP"; UtilityClass.MessageDialog("Thank You very much for Purchasing. We really appreciate your kind support!", "Thank You very much! :)"); } } catch (Exception) { UtilityClass.MessageDialog("An Error Occured, Please Try Again", "Error"); } } else { } } } catch (Exception) { UtilityClass.MessageDialog("An Error Occured, Please Try Again", "Error"); } }
public static async Task <bool> RequestPurchase(JsonObject priceObject) { bool response = false; selectedProductSubscription = priceObject; string storeProductId = priceObject.GetNamedString("ms_product_id"); System.Diagnostics.Debug.WriteLine("MS-Store product ID requested:" + storeProductId); try { if (context == null) { context = StoreContext.GetDefault(); } bool userOwnsSubscription = await CheckIfUserHasSubscriptionAsync(storeProductId); if (userOwnsSubscription) { // Unlock all the subscription add-on features here. return(true); } StoreProductQueryResult result = await context.GetAssociatedStoreProductsAsync(new string[] { "Durable" }); if (result.ExtendedError != null) { System.Diagnostics.Debug.WriteLine("Something went wrong while getting the add-ons. ExtendedError:" + result.ExtendedError); return(false); } // Look for the product that represents the subscription. foreach (var item in result.Products) { System.Diagnostics.Debug.WriteLine(item.Value); StoreProduct product = item.Value; if (product.StoreId == storeProductId) { subscriptionStoreProduct = product; } } if (subscriptionStoreProduct == null) { System.Diagnostics.Debug.WriteLine("The subscription was not found."); } else { response = await PromptUserToPurchaseAsync(); } return(response); } catch (Exception ex) { ShowDialog("An error occured: " + ex.Message); } return(response); }
private async void btpinIAP_Click(object sender, RoutedEventArgs e) { this.FindName("gdPurchasingAddon"); gdPurchasingAddon.Visibility = Visibility.Visible; try { if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3)) { string[] filterList = new string[] { "Durable" }; if (UtilityData.addOnCollection == null || UtilityData.addOnCollection.ExtendedError != null) { UtilityData.addOnCollection = await storeContext.GetUserCollectionAsync(filterList); } var isPurchasedList = UtilityData.addOnCollection.Products.Values.Where(p => p.InAppOfferToken.Equals(UtilityData.PinIAP)).ToList(); if (isPurchasedList.Count == 0) { if (UtilityData.addOnsAssociatedStoreProducts == null) { UtilityData.addOnsAssociatedStoreProducts = await storeContext.GetAssociatedStoreProductsAsync(filterList); } var AddOnList = UtilityData.addOnsAssociatedStoreProducts.Products.Values.Where(p => p.InAppOfferToken.Equals(UtilityData.PinIAP)).ToList(); StorePurchaseResult result = await storeContext.RequestPurchaseAsync(AddOnList[0].StoreId); if (result != null) { switch (result.Status) { case StorePurchaseStatus.AlreadyPurchased: PinLicense(); break; case StorePurchaseStatus.Succeeded: ApplicationData.Current.RoamingSettings.Values[UtilityData.UpPin] = true; PinLicense(); UtilityClass.MessageDialog("Thank You very much for Purchasing. We really appreciate your kind support!", "Thank You very much! :)"); break; case StorePurchaseStatus.NetworkError: case StorePurchaseStatus.ServerError: UtilityClass.MessageDialog("An Error Occured , Please Try Again!", "Error occured while purchasing."); break; } } } } else { if (UtilityData.AppLicenseInformation == null) { UtilityData.AppLicenseInformation = CurrentApp.LicenseInformation; } if (!UtilityData.AppLicenseInformation.ProductLicenses["PinIAP"].IsActive) { try { PurchaseResults results = await CurrentApp.RequestProductPurchaseAsync("PinIAP"); if (results.Status == ProductPurchaseStatus.Succeeded) { ApplicationData.Current.RoamingSettings.Values["UpPin"] = UtilityData.AppLicenseInformation.ProductLicenses["PinIAP"].IsActive; PinLicense(); UtilityClass.MessageDialog("Thank You very much for Purchasing. We really appreciate your kind support!", "Thank You very much! :)"); } } catch { UtilityClass.MessageDialog("Please Check your Internet Connection and then try again", "No Internet Connection."); } } else { } } } catch (Exception) { UtilityClass.MessageDialog("Please Check your Internet Connection and then try again", "No Internet Connection."); } finally { if (gdPurchasingAddon != null) { gdPurchasingAddon.Visibility = Visibility.Collapsed; } } }