// Has the user purchased this collection? private async Task <bool> IsPurchased() { if (_Context == null) { _Context = StoreContext.GetDefault(); } // Specify the kinds of add-ons to retrieve. var filterList = new List <string>(new[] { "Durable" }); var idList = new List <string>(new[] { _StoreId }); StoreProductQueryResult queryResult = await _Context.GetStoreProductsAsync(filterList, idList); if (queryResult.ExtendedError != null) { // The user may be offline or there might be some other server failure. Debug.WriteLine($"ExtendedError: {queryResult.ExtendedError.Message}"); return(false); } foreach (var item in queryResult.Products) { StoreProduct product = item.Value; return(product.IsInUserCollection); } return(false); }
public async Task InitProductInfoAsync() { if (Products.Count > 0) { return; } // Specify the kinds of add-ons to retrieve. var filterList = new List <string> { "Durable", "Consumable", "UnmanagedConsumable" }; // Specify the Store IDs of the products to retrieve. var storeIds = new[] { "9nrgs6r2grsz", // Regular Coffee "9p3vls5wtft6", // Loose Change "9msxrvnlnlj7", // Small Coffee "9pnsd6hskwpk" // Large Coffee }; var results = await _storeContext.GetStoreProductsAsync(filterList, storeIds); Products.AddRange(results.Products); }
public static async Task <ProductSituationReturn> GetProductSituationAsync(StoreContext context, string id, string filter = "Durable") { if (context == null) { context = StoreContext.GetDefault(); } var filterList = new string[] { filter }; var storeIds = new string[] { id }; var queryResult = await context.GetStoreProductsAsync(filterList, storeIds); if (queryResult.ExtendedError != null) { System.Diagnostics.Debug.WriteLine($"ExtendedError: {queryResult.ExtendedError.Message}"); return(ProductSituationReturn.Error); } if (queryResult.Products.Count == 0) { return(ProductSituationReturn.MicrosoftError); } bool have = false; queryResult.Products.Values.ToList().ForEach(item => have = item.IsInUserCollection); return(have ? ProductSituationReturn.Have : ProductSituationReturn.Without); }
public async Task <List <KeyValuePair <string, StoreProduct> > > GetProductInfoAsync() { var list = new List <KeyValuePair <string, StoreProduct> >(); // Specify the kinds of add-ons to retrieve. var filterList = new List <string> { "Durable", "Consumable", "UnmanagedConsumable" }; // Specify the Store IDs of the products to retrieve. var storeIds = new[] { "9nrgs6r2grsz", // Regular Coffee "9p3vls5wtft6", // Loose Change "9msxrvnlnlj7", // Small Coffee "9pnsd6hskwpk" // Large Coffee }; var results = await _storeContext.GetStoreProductsAsync(filterList, storeIds); if (results.ExtendedError != null) { await new MessageDialog(results.ExtendedError.Message).ShowAsync(); return(list); } list.AddRange(results.Products); return(list); }
async Task <ReadOnlyCollection <ConsumableAddOn> > PlatformGetConsumableAddOns(params string[] keys) { if (context == null) { context = StoreContext.GetDefault(); } var consumables = new Collection <ConsumableAddOn>(); // Specify the kinds of add-ons to retrieve. if (keys.Length == 0) { consumables.AddRange(_addOnsByKey.Values.OfType <ConsumableAddOn>()); } else { foreach (var key in keys) { if (_addOnsByKey[key] is ConsumableAddOn cao) { consumables.Add(cao); } } } var queryResult = await context.GetStoreProductsAsync(new List <string>() { "Consumable" }, consumables.Select(c => c.Id)); if (queryResult.ExtendedError == null) { foreach (var consumable in consumables) { var product = queryResult.Products[consumable.Id]; var balanceResult = await context.GetConsumableBalanceRemainingAsync(product.StoreId); consumable.Title = product.Title; consumable.Description = product.Description; consumable.Price = product.Price.FormattedPrice; consumable.CustomData = product.Skus[0].CustomDeveloperData; consumable.Balance = balanceResult.Status == StoreConsumableStatus.Succeeded ? balanceResult.BalanceRemaining : 0; } } return(new ReadOnlyCollection <ConsumableAddOn>(consumables)); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); var response = await _storeContext.GetStoreProductsAsync(new List <string> { "Durable" }, new List <string> { "9NKFZRCQRZ3H" }); if (response.Products.Count > 0) { //foreach(var product in response.Products) { } //var product = response.Products[0]; } }
public async void GetProductInfo() { 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" }; List <String> filterList = new List <string>(productKinds); // Specify the Store IDs of the products to retrieve. string[] storeIds = new string[] { "9NBLGGH4TNMP", "9NBLGGH4TNMN" }; workingProgressRing.IsActive = true; StoreProductQueryResult queryResult = await context.GetStoreProductsAsync(filterList, storeIds); 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 info for the product. StoreProduct product = item.Value; // Use members of the product object to access info for the product... } }
public async void PurchaseSubscription(string storeId) { 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. } // First, get the StoreProduct object for the subscription add-on. This example // assumes you already know the Store ID for the add-on and you have passed // it to this method. string[] productKinds = { "Durable" }; List <String> filterList = new List <string>(productKinds); string[] storeIds = new string[] { storeId }; workingProgressRing.IsActive = true; StoreProductQueryResult queryResult = await context.GetStoreProductsAsync(filterList, storeIds); workingProgressRing.IsActive = false; StoreProduct mySubscription = queryResult.Products.FirstOrDefault().Value; // Make sure the user has not already acquired the subscription add-on, then // offer it for purchase to the user. if (!mySubscription.IsInUserCollection) { workingProgressRing.IsActive = true; StorePurchaseResult result = await mySubscription.RequestPurchaseAsync(); workingProgressRing.IsActive = false; // Capture the error message for the operation, if any. string extendedError = string.Empty; if (result.ExtendedError != null) { extendedError = result.ExtendedError.Message; } switch (result.Status) { case StorePurchaseStatus.Succeeded: textBlock.Text = "The purchase was successful."; break; case StorePurchaseStatus.NotPurchased: textBlock.Text = "The purchase did not complete. " + "The user may have cancelled the purchase. ExtendedError: " + extendedError; break; case StorePurchaseStatus.NetworkError: textBlock.Text = "The purchase was unsuccessful due to a network error. " + "ExtendedError: " + extendedError; break; case StorePurchaseStatus.ServerError: textBlock.Text = "The purchase was unsuccessful due to a server error. " + "ExtendedError: " + extendedError; break; default: textBlock.Text = "The purchase was unsuccessful due to an unknown error. " + "ExtendedError: " + extendedError; break; } } }
public async Task InitializeAsync() { return; // TODO: Remove try { // Clear Product List _products.Clear(); // Specify the kinds of add-ons to retrieve. var filterList = new List <string> { "Durable", "Subscription", "Consumable" }; // Specify the Store IDs of the products to retrieve. var storeIds = new[] { "9PHZ0ZS2V06Z", // Subscription "9NZW466C1857", // One Time "9P3VLS5WTFT6", // Donate Loose Change "9MSXRVNLNLJ7", // Donate Small Coffee "9PNSD6HSKWPK", // Donate Large Coffee "9NRGS6R2GRSZ" // Donate regular coffee }; // Get all the products and add them to the product list var results = await _storeContext.GetStoreProductsAsync(filterList, storeIds); _products.AddRange(results.Products); var donateItemExists = _products.Any(x => x.Key == "9P3VLS5WTFT6" || x.Key == "9MSXRVNLNLJ7" || x.Key == "9PNSD6HSKWPK" || x.Key == "9NRGS6R2GRSZ"); var hasUserDonated = donateItemExists && ((_products.First(x => x.Key == "9P3VLS5WTFT6").Value?.IsInUserCollection ?? false) || (_products.First(x => x.Key == "9MSXRVNLNLJ7").Value?.IsInUserCollection ?? false) || (_products.First(x => x.Key == "9PNSD6HSKWPK").Value?.IsInUserCollection ?? false) || (_products.First(x => x.Key == "9NRGS6R2GRSZ").Value?.IsInUserCollection ?? false)); // If the user has donated before, we unlock the app via donation if (hasUserDonated) { _hasPremium = true; return; } var subscriptionExists = _products.Any(x => x.Key == "9PHZ0ZS2V06Z"); var hasUserSubscribed = subscriptionExists && (_products.FirstOrDefault(x => x.Key == "9PHZ0ZS2V06Z").Value?.IsInUserCollection ?? false); // The user has purchased a subscription if (hasUserSubscribed) { _hasPremium = true; return; } var oneTimeExists = _products.Any(x => x.Key == "9NZW466C1857"); var hasUserPurchasedOneTime = oneTimeExists && (_products.FirstOrDefault(x => x.Key == "9NZW466C1857").Value?.IsInUserCollection ?? false); // The user bought the app if (hasUserPurchasedOneTime) { _hasPremium = true; return; } // By default the user has not purchased the app _hasPremium = false; } catch (Exception ex) { // Something went wrong, not sure what, default to no _hasPremium = false; _telemetryService.TrackException(ex); } }