private async void FulfillPreviousPurchase(object sender, RoutedEventArgs e) { try { IReadOnlyList <UnfulfilledConsumable> consumables = await CurrentAppSimulator.GetUnfulfilledConsumablesAsync(); string logMessage = "Number of unfulfilled consumables: " + consumables.Count; foreach (UnfulfilledConsumable consumable in consumables) { logMessage += "\nProduct Id: " + consumable.ProductId + " Transaction Id: " + consumable.TransactionId; // This is where you would grant the user their consumable content and call currentApp.reportConsumableFulfillment // For demonstration purposes, we leave the purchase unfulfilled. if (!IsLocallyFulfilled(consumable.TransactionId)) { GrantFeatureLocally(consumable.TransactionId); } FulfillProduct(consumable.TransactionId); } //NotifyUser("product1 was fulfilled.You are now able to buy another one"); //tb2.Text = logMessage.ToString(); } catch (Exception) { //rootPage.NotifyUser("GetUnfulfilledConsumablesAsync API call failed", NotifyType.ErrorMessage); } }
private async void GetUnfulfilledConsumables() { try { IReadOnlyList <UnfulfilledConsumable> products = await CurrentAppSimulator.GetUnfulfilledConsumablesAsync(); string logMessage = "List of unfulfilled consumables:"; foreach (UnfulfilledConsumable product in products) { logMessage += "\nProduct Id: " + product.ProductId + " Transaction Id: " + product.TransactionId; // This is where you would grant the user their consumable content and call currentApp.reportConsumableFulfillment } if (products.Count == 0) { logMessage = "There are no consumable purchases awaiting fulfillment."; } Log(logMessage, NotifyType.StatusMessage, products.Count); } catch (Exception) { Log("GetUnfulfilledConsumablesAsync API call failed", NotifyType.ErrorMessage); } }
private IAsyncOperation <IReadOnlyList <UnfulfilledConsumable> > GetUnfulfilledConsumablesAsync() { if (_useSimulator) { return(CurrentAppSimulator.GetUnfulfilledConsumablesAsync()); } else { return(CurrentApp.GetUnfulfilledConsumablesAsync()); } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { await MainPage.ConfigureSimulatorAsync("in-app-purchase-consumables-advanced.xml"); try { ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); // Initialize the UI for our consumables. foreach (ProductPurchaseInfo info in purchaseInfos) { var product = listing.ProductListings[info.productId]; info.nameRun.Text = product.Name; info.priceRun.Text = product.FormattedPrice; } rootPage.NotifyUser("", NotifyType.StatusMessage); } catch (Exception) { rootPage.NotifyUser("LoadListingInformationAsync API call failed", NotifyType.ErrorMessage); } // recover any unfulfilled consumables try { IReadOnlyList <UnfulfilledConsumable> consumables = await CurrentAppSimulator.GetUnfulfilledConsumablesAsync(); foreach (UnfulfilledConsumable consumable in consumables) { foreach (ProductPurchaseInfo info in purchaseInfos) { if (info.productId == consumable.ProductId) { // This is a consumable which the user purchased but which has not yet been fulfilled. // Update our statistics so we know that there is a purchase pending. info.numPurchases++; // This is where you would normally grant the user their consumable content and call currentApp.reportConsumableFulfillment. // For demonstration purposes, we leave the purchase unfulfilled. info.tempTransactionId = consumable.TransactionId; } } } } catch (Exception) { rootPage.NotifyUser("GetUnfulfilledConsumablesAsync API call failed", NotifyType.ErrorMessage); } UpdateStatistics(); }
public static IAsyncOperation <IReadOnlyList <UnfulfilledConsumable> > GetUnfulfilledConsumablesAsync() { if (testmode == null) { throw new NotSupportedException(); } else if (testmode.Value) { return(CurrentAppSimulator.GetUnfulfilledConsumablesAsync()); } else { return(CurrentApp.GetUnfulfilledConsumablesAsync()); } }
private async Task LoadInAppPurchaseConsumablesProxyFileAsync() { StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data"); StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase-consumables-advanced.xml"); await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile); // setup application upsell message try { ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); ProductListing product1 = listing.ProductListings["product1"]; Product1SellMessage.Text = "You can buy " + product1.Name + " for: " + product1.FormattedPrice + "."; ProductListing product2 = listing.ProductListings["product2"]; Product2SellMessage.Text = "You can buy " + product2.Name + " for: " + product2.FormattedPrice + "."; Log("", NotifyType.StatusMessage); } catch (Exception) { rootPage.NotifyUser("LoadListingInformationAsync API call failed", NotifyType.ErrorMessage); } // recover any unfulfilled consumables try { IReadOnlyList <UnfulfilledConsumable> products = await CurrentAppSimulator.GetUnfulfilledConsumablesAsync(); foreach (UnfulfilledConsumable product in products) { if (product.ProductId == "product1") { product1TempTransactionId = product.TransactionId; } else if (product.ProductId == "product2") { product2TempTransactionId = product.TransactionId; } } } catch (Exception) { rootPage.NotifyUser("GetUnfulfilledConsumablesAsync API call failed", NotifyType.ErrorMessage); } }
/// <summary> /// Gets a list of unfulfilled consumable products /// </summary> /// <param name="response">A callback containing the found unfulfilled consumable products</param> public static void GetUnfulfilledConsumableProducts(Action <List <WSAUnfulfilledConsumable> > response) { #if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0) if (_isTest) { UnityEngine.WSA.Application.InvokeOnUIThread(async() => { IReadOnlyList <UnfulfilledConsumable> products = await CurrentAppSimulator.GetUnfulfilledConsumablesAsync(); List <WSAUnfulfilledConsumable> unfulfilled = products.Select(x => new WSAUnfulfilledConsumable() { OfferId = x.OfferId, ProductId = x.ProductId, TransactionId = x.TransactionId }).ToList(); UnityEngine.WSA.Application.InvokeOnAppThread(() => { if (response != null) { response(unfulfilled != null ? unfulfilled : new List <WSAUnfulfilledConsumable>()); } }, true); }, false); } else { UnityEngine.WSA.Application.InvokeOnUIThread(async() => { IReadOnlyList <UnfulfilledConsumable> products = await CurrentApp.GetUnfulfilledConsumablesAsync(); List <WSAUnfulfilledConsumable> unfulfilled = products.Select(x => new WSAUnfulfilledConsumable() { OfferId = x.OfferId, ProductId = x.ProductId, TransactionId = x.TransactionId }).ToList(); UnityEngine.WSA.Application.InvokeOnAppThread(() => { if (response != null) { response(unfulfilled != null ? unfulfilled : new List <WSAUnfulfilledConsumable>()); } }, true); }, false); } #endif }
public static void LoadUnfulfilledConsumables(Action <CallbackResponse <List <UnfulfilledConsumable> > > OnLoadUnfulfilledConsumablesFinished) { Utils.RunOnWindowsUIThread(async() => { IReadOnlyList <Windows.ApplicationModel.Store.UnfulfilledConsumable> unfulfilledConsumables = null; List <UnfulfilledConsumable> deliveryFormatUnfulfilledConsumables = new List <UnfulfilledConsumable>(); try { if (_isLicenseSimulationOn) { unfulfilledConsumables = await CurrentAppSimulator.GetUnfulfilledConsumablesAsync(); } else { unfulfilledConsumables = await CurrentApp.GetUnfulfilledConsumablesAsync(); } foreach (var oneUnfConsumable in unfulfilledConsumables) { deliveryFormatUnfulfilledConsumables.Add(new UnfulfilledConsumable(oneUnfConsumable)); } } catch (Exception ex) { DebugLog.Log(LogLevel.Error, "Error while reporting consumable fulfillment " + ex.ToString()); Utils.RunOnUnityAppThread(() => { OnLoadUnfulfilledConsumablesFinished(new CallbackResponse <List <UnfulfilledConsumable> > { Status = CallbackStatus.Failure, Exception = ex, Result = null }); }); return; } // deliver all the unfulfilled consumables at once Utils.RunOnUnityAppThread(() => { if (OnLoadUnfulfilledConsumablesFinished != null) { OnLoadUnfulfilledConsumablesFinished(new CallbackResponse <List <UnfulfilledConsumable> > { Status = CallbackStatus.Success, Result = deliveryFormatUnfulfilledConsumables, Exception = null }); } }); }); }
private async void ShowUnfulfilledConsumables() { try { IReadOnlyList <UnfulfilledConsumable> consumables = await CurrentAppSimulator.GetUnfulfilledConsumablesAsync(); string logMessage = "Number of unfulfilled consumables: " + consumables.Count; foreach (UnfulfilledConsumable consumable in consumables) { logMessage += "\nProduct Id: " + consumable.ProductId + " Transaction Id: " + consumable.TransactionId; // This is where you would grant the user their consumable content and call currentApp.reportConsumableFulfillment // For demonstration purposes, we leave the purchase unfulfilled. } rootPage.NotifyUser(logMessage, NotifyType.StatusMessage); } catch (Exception) { rootPage.NotifyUser("GetUnfulfilledConsumablesAsync API call failed", NotifyType.ErrorMessage); } }
public static async Task <IEnumerable <UnfulfilledConsumable> > GetAvailableConsumables(bool isTestingMode) { return(isTestingMode ? await CurrentAppSimulator.GetUnfulfilledConsumablesAsync() : await CurrentApp.GetUnfulfilledConsumablesAsync()); }
public IAsyncOperation <IReadOnlyList <UnfulfilledConsumable> > GetUnfulfilledConsumablesAsync() { return(CurrentAppSimulator.GetUnfulfilledConsumablesAsync()); }
/// <summary> /// Returns a list of purchased consumable in-app products /// that have not been reported to the Windows Store as fulfilled. /// </summary> /// <returns> /// When the operation completes, a list of consumable /// in-app products not yet reported as fulfilled is returned /// (UnfulfilledConsumable objects). /// </returns> public static IAsyncOperation <IReadOnlyList <UnfulfilledConsumable> > GetUnfulfilledConsumablesAsync() { return(IsMockEnabled ? CurrentAppSimulator.GetUnfulfilledConsumablesAsync() : CurrentApp.GetUnfulfilledConsumablesAsync()); }