internal async void GetPrice() { try { #if DEBUG ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); #else ListingInformation listing = await CurrentApp.LoadListingInformationAsync(); #endif List <string> ps = new List <string>(); foreach (var item in DonationPack) { var product = listing.ProductListings[item]; ps.Add(product.FormattedPrice); } Price = ps.ToArray(); licenseChangeHandler = new LicenseChangedEventHandler(licenseChangedEventHandler); #if DEBUG CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler; #else CurrentApp.LicenseInformation.LicenseChanged += licenseChangeHandler; #endif } catch (Exception) { Price = null; } }
private async void BuyButton_Click(object sender, RoutedEventArgs e) { var proxyFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets"); var proxyFile = await proxyFolder.GetFileAsync("WindowsStoreProxy.xml"); await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile); try { var listing = await CurrentAppSimulator.LoadListingInformationAsync(); var product = listing.ProductListings["product1"]; var results = await CurrentAppSimulator.RequestProductPurchaseAsync("product1"); if (results.Status == ProductPurchaseStatus.Succeeded) { VKAppPlatform.Instance.ReportInAppPurchase(new VKAppPlatform.InAppPurchaseData(results.ReceiptXml, product.FormattedPrice)); } } catch (Exception exc) { /* Handle exception */ } }
private async Task LoadInAppPurchaseProxyFileAsync() { StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data"); StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml"); licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario); CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler; await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile); // setup application upsell message try { ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); var product1 = listing.ProductListings["product1"]; var product2 = listing.ProductListings["product2"]; Product1SellMessage.Text = "You can buy " + product1.Name + " for: " + product1.FormattedPrice + "."; Product2SellMessage.Text = "You can buy " + product2.Name + " for: " + product2.FormattedPrice + "."; } catch (Exception) { rootPage.NotifyUser("LoadListingInformationAsync API call failed", NotifyType.ErrorMessage); } }
public async Task <InAppPurchaseHelper> Setup() { // license if (Simulate) { #if DEBUG await SetupSimulation(); m_License = CurrentAppSimulator.LicenseInformation; m_Listing = await CurrentAppSimulator.LoadListingInformationAsync(); CanPurchase = true; #endif } else { try { m_License = CurrentApp.LicenseInformation; m_Listing = await CurrentApp.LoadListingInformationAsync(); CanPurchase = true; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(string.Format("Setup/License [{0}, {1}, {2}]", this.Key, this.Simulate, e.Message)); CanPurchase = false; } } if (!CanPurchase) { return(this); // :( } try { // test setup m_License.LicenseChanged += () => { RaiseLicenseChanged(IsPurchased); }; IReadOnlyDictionary <string, ProductLicense> _Licenses = m_License.ProductLicenses; if (!_Licenses.Any(x => x.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase))) { throw new KeyNotFoundException(Key); } IReadOnlyDictionary <string, ProductListing> _Products = m_Listing.ProductListings; if (!_Products.Any(x => x.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase))) { throw new KeyNotFoundException(Key); } // product m_Product = _Products[Key]; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(string.Format("Setup/Tests [{0}, {1}, {2}]", this.Key, this.Simulate, e.Message)); CanPurchase = false; } return(this); }
/// <summary> /// Gets the formatted price of the app /// </summary> /// <returns>an async task with the formatted price of the app as a string</returns> internal static async Task <string> GetPriceAsync() { #if DEBUG var listingInformation = await CurrentAppSimulator.LoadListingInformationAsync(); #else var listingInformation = await CurrentApp.LoadListingInformationAsync(); #endif return(listingInformation.FormattedPrice); }
public static async Task <string> getProductPrice() { #if DEBUG ListingInformation information = await CurrentAppSimulator.LoadListingInformationAsync(); #else ListingInformation information = await CurrentApp.LoadListingInformationAsync(); #endif List <ProductListing> products = information.ProductListings.Values.ToList(); ProductListing product = products.Single(x => x.ProductId == prodotto); return(product.FormattedPrice); }
private async void ReportFulfillment() { ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); var product1 = listing.ProductListings["product1"]; string product1ListingName = string.Empty; string productId = product1.ProductId; Guid transactionId = new Guid(); //<ReportFulfillment> string offerId = "1234"; product1ListingName = product1.Name; string displayPropertiesName = "MusicOffer1"; if (String.IsNullOrEmpty(displayPropertiesName)) { displayPropertiesName = product1ListingName; } var offerIdMsg = " with offer id " + offerId; if (String.IsNullOrEmpty(offerId)) { offerIdMsg = " with no offer id"; } FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId); switch (result) { case FulfillmentResult.Succeeded: Log("You bought and fulfilled " + displayPropertiesName + offerIdMsg); break; case FulfillmentResult.NothingToFulfill: Log("There is no purchased product 1 to fulfill."); break; case FulfillmentResult.PurchasePending: Log("You bought product 1. The purchase is pending so we cannot fulfill the product."); break; case FulfillmentResult.PurchaseReverted: Log("You bought product 1. But your purchase has been reverted."); // Since the user' s purchase was revoked, they got their money back. // You may want to revoke the user' s access to the consumable content that was granted. break; case FulfillmentResult.ServerError: Log("You bought product 1. There was an error when fulfilling."); break; } //</ReportFulfillment> }
private async Task <List <Product> > RetrieveProductsAsync() { ListingInformation listing; LicenseInformation license; if (_useSimulator) { listing = await CurrentAppSimulator.LoadListingInformationAsync(); license = CurrentAppSimulator.LicenseInformation; } else { listing = await CurrentApp.LoadListingInformationAsync(); license = CurrentApp.LicenseInformation; } if (listing != null) { var products = listing.ProductListings; var results = new List <Product>(); foreach (var p in products.Values) { var product = new Product(); product.ProductID = p.ProductId; product.Name = p.Name; product.FormattedPrice = p.FormattedPrice; // Determine license status product.Purchased = license.ProductLicenses[product.ProductID].IsActive; if (product.Purchased) { product.Expires = license.ProductLicenses[product.ProductID].ExpirationDate.DateTime; } switch (p.ProductType) { case Windows.ApplicationModel.Store.ProductType.Consumable: product.Type = MarkerMetro.Unity.WinIntegration.Store.ProductType.Consumable; break; case Windows.ApplicationModel.Store.ProductType.Durable: product.Type = MarkerMetro.Unity.WinIntegration.Store.ProductType.Durable; break; } results.Add(product); } return(results); } return(null); }
/// <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(); }
private async void shield2_Click(object sender, RoutedEventArgs e) { var listing = await CurrentAppSimulator.LoadListingInformationAsync(); listing.ToString(); // LicenseInformation listing = await CurrentApp.LoadListingInformationAsync(); var superweapon = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "1"); String message1 = superweapon.Value.Name; // var dialog = new MessageDialog(listing.ToString()); //await dialog.ShowAsync(); // CurrentApp.AppId.ToString(); try { if (CurrentAppSimulator.LicenseInformation.ProductLicenses["1"].IsActive) { PurchaseResults result = await CurrentAppSimulator.RequestProductPurchaseAsync("1"); var dialog1 = new MessageDialog("you buy super shield"); await dialog1.ShowAsync(); } else { try { // var receipt = await CurrentApp.RequestProductPurchaseAsync("shield", false); PurchaseResults receipt = await CurrentAppSimulator.RequestProductPurchaseAsync("shield"); message.Visibility = Windows.UI.Xaml.Visibility.Visible; message.Text = CurrentApp.AppId.ToString(); var dialo2 = new MessageDialog(message.Text); await dialo2.ShowAsync(); } catch (Exception ex) { String message = ex.ToString(); // var dialog3 = new MessageDialog(message); // await dialog3.ShowAsync(); } } } catch (Exception ex) { String message = ex.ToString(); // var dialog3 = new MessageDialog(message); // await dialog3.ShowAsync(); } //MessageBox.Show(sb.ToString(), "List all products", MessageBoxButton.OK); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); LoadData(); DonationText = "Donate"; Task.Run(async() => { try { #if DEBUG var productLicense = CurrentAppSimulator.LicenseInformation.ProductLicenses[DonationProductId]; #else var productLicense = CurrentApp.LicenseInformation.ProductLicenses[DonationProductId]; #endif if (productLicense != null) { ApplicationData.Current.RoamingSettings.Values["HasDonated"] = productLicense.IsActive; HasDonated = productLicense.IsActive; } #if DEBUG var listingInformation = await CurrentAppSimulator.LoadListingInformationAsync(); #else var listingInformation = await CurrentApp.LoadListingInformationAsync(); #endif if (listingInformation != null) { var productListing = listingInformation.ProductListings[DonationProductId]; if (productListing != null) { await Execute.OnUIThread(() => { DonationAmount = productListing.FormattedPrice; DonationText = "Donate " + DonationAmount; }); } } } catch (Exception ex) { // Do Nothing Debug.WriteLine(ex.ToString()); } }); //AnimateHowToRepeat(); }
private async Task LoadTrialModeProxyFileAsync() { StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data"); StorageFile proxyFile = await proxyDataFolder.GetFileAsync("trial-mode.xml"); licenseChangeHandler = new LicenseChangedEventHandler(TrialModeRefreshScenario); CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler; await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile); // setup application upsell message ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); PurchasePrice.Text = "You can buy the full app for: " + listing.FormattedPrice + "."; }
private async void btnDetails_Click(object sender, RoutedEventArgs e) { //Khai bao doi tuong LicenseInformation de lay thong tin License LicenseInformation l = CurrentAppSimulator.LicenseInformation; //Neu ung dung chua active if (l.IsActive == false) { //Lay thong tin ten san pham va phi su dung ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); var pro = listing.ProductListings["P001"]; txtDetails.Text = "You can buy " + pro.Name + " for: " + pro.FormattedPrice + "."; } }
public static IAsyncOperation <ListingInformation> LoadListingInformationAsync() { if (testmode == null) { throw new NotSupportedException(); } else if (testmode.Value) { return(CurrentAppSimulator.LoadListingInformationAsync()); } else { return(CurrentApp.LoadListingInformationAsync()); } }
/// <summary> /// Current listing information retrieved from the Windows Store /// </summary> /// <returns>Current Windows Store listing information</returns> public static async Task <ListingInformation> GetListingInformationAsync() { try { #if DEBUG return(await CurrentAppSimulator.LoadListingInformationAsync()); #else return(await CurrentApp.LoadListingInformationAsync()); #endif } catch (Exception e) { LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Failure retrieving Windows Store listing information", e); return(null); } }
/// <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) { CurrentAppSimulator.LicenseInformation.LicenseChanged += OnLicenseInformationChanged; await MainPage.ConfigureSimulatorAsync("trial-mode.xml"); try { ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); PurchasePrice.Text = listing.FormattedPrice; } catch (Exception) { rootPage.NotifyUser("LoadListingInformationAsync API call failed", NotifyType.ErrorMessage); } }
public async Task LoadLicenses() { if (_loaded) { return; } var installedFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("data"); var installedFile = await installedFolder.GetFileAsync("license.xml"); await Windows.ApplicationModel.Store.CurrentAppSimulator.ReloadSimulatorAsync(installedFile); _listingInformation = await CurrentAppSimulator.LoadListingInformationAsync(); _loaded = true; }
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); } }
public async Task LoadLicenseData() { if (_loaded) { return; } var installedFolder = await Package.Current.InstalledLocation.GetFolderAsync("data"); var simulatorSettingsFile = await installedFolder.GetFileAsync("license.xml"); await CurrentAppSimulator.ReloadSimulatorAsync(simulatorSettingsFile); // TODO: Module 12: Exercise 2: Task 1.2: Store the license information _listingInformation = await CurrentAppSimulator.LoadListingInformationAsync(); _loaded = true; }
public async Task <ListingInformation> GetListingInformationAsync() { try { if (DebugHelpers.DebugMode) { return(await CurrentAppSimulator.LoadListingInformationAsync()); } return(await CurrentApp.LoadListingInformationAsync()); } catch (Exception ex) { ExceptionHelpers.PrintOutException(ex, "License Load failed"); return(null); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { string PurchasePrice; CurrentAppSimulator.LicenseInformation.LicenseChanged += OnLicenseInformationChanged; await ConfigureSimulatorAsync("trial-mode.xml"); try { ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); PurchasePrice = listing.FormattedPrice; } catch (Exception) { DisplayFailDialog(); } }
/// <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.xml"); try { ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); var product1 = listing.ProductListings["product1"]; Product1Name.Text = product1.Name; Product1Price.Text = product1.FormattedPrice; rootPage.NotifyUser("", NotifyType.StatusMessage); } catch (Exception) { rootPage.NotifyUser("LoadListingInformationAsync API call failed", NotifyType.ErrorMessage); } }
private static async void GetProductListingsAsync(Action <List <WSAProduct> > response) { ListingInformation listings = null; try { if (_isTest) { listings = await CurrentAppSimulator.LoadListingInformationAsync(); } else { listings = await CurrentApp.LoadListingInformationAsync(); } } catch { } List <WSAProduct> products = new List <WSAProduct>(); if (listings != null) { foreach (ProductListing product in listings.ProductListings.Values) { products.Add(new WSAProduct() { Id = product.ProductId, Name = product.Name, #if (UNITY_WSA_10_0 || UNITY_WP8_1) Description = product.Description, ImageUri = product.ImageUri, #endif FormattedPrice = product.FormattedPrice, ProductType = Enum.GetName(typeof(ProductType), product.ProductType) }); } } if (response != null) { response(products); } }
private async Task LoadInAppPurchaseConsumablesProxyFileAsync() { StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data"); StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase-consumables.xml"); await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile); // setup application upsell message try { ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); var product1 = listing.ProductListings["product1"]; Product1SellMessage.Text = "You can buy " + product1.Name + " for: " + product1.FormattedPrice + "."; Log("", NotifyType.StatusMessage); } catch (Exception) { rootPage.NotifyUser("LoadListingInformationAsync API call failed", NotifyType.ErrorMessage); } }
public async static Task InitializeLicensingAsync() { var local = ApplicationData.Current.LocalFolder; var install_location = Windows.ApplicationModel.Package.Current.InstalledLocation; var proxyFolder = await local.CreateFolderAsync("Microsoft\\Windows Store\\ApiData", CreationCollisionOption.OpenIfExists); var installLocation = await install_location.GetFolderAsync("storeproxy"); // open the proxy file StorageFile proxyFile = await installLocation.GetFileAsync("trialmanagement.xml"); // create proxy file in application data var simulator_settings = await proxyFolder.CreateFileAsync("WindowsStoreProxy.xml", CreationCollisionOption.ReplaceExisting); // replace the contents await proxyFile.CopyAndReplaceAsync(simulator_settings); //load the listing information read from the file. The currentproductsimulator seems //to expect a file in the location where i put it. It reads it and uses it as if it is //coming from the marketplace. License = CurrentAppSimulator.LicenseInformation; ListingInfo = await CurrentAppSimulator.LoadListingInformationAsync(); }
public static void LoadListingInformation(Action <CallbackResponse <ListingInformation> > OnLoadListingFinished) { Utils.RunOnWindowsUIThread(async() => { try { if (_isLicenseSimulationOn) { _listingInformation = new ListingInformation(await CurrentAppSimulator.LoadListingInformationAsync()); } else { _listingInformation = new ListingInformation(await CurrentApp.LoadListingInformationAsync()); } } catch (Exception ex) { if (OnLoadListingFinished != null) { Utils.RunOnUnityAppThread(() => { OnLoadListingFinished(new CallbackResponse <ListingInformation> { Result = null, Status = CallbackStatus.Failure, Exception = ex }); }); return; } } // This must get invoked on the Unity thread. // On successful completion, invoke the OnLoadListingFinished event handler if (OnLoadListingFinished != null && _listingInformation != null) { Utils.RunOnUnityAppThread(() => { OnLoadListingFinished(new CallbackResponse <ListingInformation> { Result = _listingInformation, Status = CallbackStatus.Success, Exception = null }); }); } }); }
public IAsyncOperation <ListingInformation> LoadListingInformationAsync() { return(CurrentAppSimulator.LoadListingInformationAsync()); }
/// <summary> /// Loads the app's listing information asynchronously. /// </summary> /// <returns> /// The apps' listing information. If the method fails, /// it returns an HRESULT error code. /// </returns> public static IAsyncOperation <ListingInformation> LoadListingInformationAsync() { return(IsMockEnabled ? CurrentAppSimulator.LoadListingInformationAsync() : CurrentApp.LoadListingInformationAsync()); }
public static async Task <ListingInformation> LoadListingInformationAsync(bool isTestingMode) { return(isTestingMode ? await CurrentAppSimulator.LoadListingInformationAsync() : await CurrentApp.LoadListingInformationAsync()); }
private async void GetListingInformationAsync() { var listing = await CurrentAppSimulator.LoadListingInformationAsync(); _price = listing.FormattedPrice; }