private async void GetConsumableBalanceButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { var item = (ItemDetails)ProductsListView.SelectedItem; StoreConsumableResult result = await storeContext.GetConsumableBalanceRemainingAsync(item.StoreId); if (result.ExtendedError != null) { Utils.ReportExtendedError(result.ExtendedError); return; } switch (result.Status) { case StoreConsumableStatus.InsufficentQuantity: // should never get this... rootPage.NotifyUser($"Insufficient Quantity! Balance Remaining: {result.BalanceRemaining}", NotifyType.ErrorMessage); break; case StoreConsumableStatus.Succeeded: rootPage.NotifyUser($"Balance Remaining: {result.BalanceRemaining}", NotifyType.StatusMessage); break; case StoreConsumableStatus.NetworkError: rootPage.NotifyUser("Network error retrieving consumable balance.", NotifyType.ErrorMessage); break; case StoreConsumableStatus.ServerError: rootPage.NotifyUser("Server error retrieving consumable balance.", NotifyType.ErrorMessage); break; default: rootPage.NotifyUser("Unknown error retrieving consumable balance.", NotifyType.ErrorMessage); break; } }
/// <summary> /// Retrieve the base price value of unconsumed store-managed consumables. /// </summary> /// <returns>double</returns> public async Task <double> GetConsumableBalance() { double unconsumedBalance = 0.0; foreach (StoreProduct product in Consumables) { var result = await storeContext.GetConsumableBalanceRemainingAsync(product.StoreId); switch (result.Status) { case StoreConsumableStatus.Succeeded: unconsumedBalance += result.BalanceRemaining * product.Price.FormattedBasePrice.AsDouble(); break; case StoreConsumableStatus.NetworkError: throw new Exception("Network error retrieving consumable balance."); case StoreConsumableStatus.ServerError: throw new Exception("Server error retrieving consumable balance."); default: throw new Exception($"Unknown error retrieving consumable balance for product {product.StoreId}: {product.Title}"); } } return(unconsumedBalance); }
private async void btnExport_Click(object sender, RoutedEventArgs e) { StoreConsumableResult singles = await context.GetConsumableBalanceRemainingAsync("9PPLX2HDLV2L"); if (singles.BalanceRemaining >= Export.Count) { bool NoError = true; foreach (Scan Scan in Export) { StoreConsumableResult result = await context.ReportConsumableFulfillmentAsync("9PPLX2HDLV2L", Convert.ToUInt32(1), new Guid()); if (result.Status != StoreConsumableStatus.Succeeded || result.ExtendedError != null) { NoError = false; MessageDialog dialog = new MessageDialog(result.ExtendedError.Message); await dialog.ShowAsync(); break; } } if (NoError) { await ExportExcelAsync(); } else { MessageDialog msgDialog = new MessageDialog("Something went wrong when trying to subtract the Credits.", "Ooops."); await msgDialog.ShowAsync(); } } else { MessageDialog msgDialog = new MessageDialog("Do you want to buy more?", "You don't have enough Scans."); UICommand yesCmd = new UICommand("Yes"); msgDialog.Commands.Add(yesCmd); UICommand noCmd = new UICommand("No"); msgDialog.Commands.Add(noCmd); IUICommand cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // TODO: Better Navigation from frmMain Frame.Navigate(typeof(StorePage)); } } }
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)); }
public async void GetRemainingBalance(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. } string addOnStoreId = "9NBLGGH4TNNR"; workingProgressRing.IsActive = true; StoreConsumableResult result = await context.GetConsumableBalanceRemainingAsync(addOnStoreId); 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 StoreConsumableStatus.Succeeded: textBlock.Text = "Remaining balance: " + result.BalanceRemaining; break; case StoreConsumableStatus.NetworkError: textBlock.Text = "Could not retrieve balance due to a network error. " + "ExtendedError: " + extendedError; break; case StoreConsumableStatus.ServerError: textBlock.Text = "Could not retrieve balance due to a server error. " + "ExtendedError: " + extendedError; break; default: textBlock.Text = "Could not retrieve balance due to an unknown error. " + "ExtendedError: " + extendedError; break; } }