private async Task ShowStoreContextControlAsync(StoreAppLicense appLicense) { var storeContextViewModel = new StoreContextViewModel(appLicense); do { await Messenger.Default.SendAsync(storeContextViewModel); if (storeContextViewModel.Result == ContentDialogResult.Primary) { var productResult = await storeContext.GetStoreProductForCurrentAppAsync(); if (productResult.ExtendedError == null) { var puchaseResult = await productResult.Product.RequestPurchaseAsync(); if (puchaseResult.ExtendedError == null) { if (puchaseResult.Status == StorePurchaseStatus.Succeeded || puchaseResult.Status == StorePurchaseStatus.AlreadyPurchased) { break; } } } } } while (storeContextViewModel.IsExpired); }
private static async Task <bool> PurchaseAsync() { StoreContext Store = StoreContext.GetDefault(); StoreProductResult ProductResult = await Store.GetStoreProductForCurrentAppAsync(); if (ProductResult.ExtendedError == null) { if (ProductResult.Product != null) { if ((await ProductResult.Product.RequestPurchaseAsync()).Status == StorePurchaseStatus.Succeeded) { return(true); } else { return(false); } } else { return(false); } } else { throw new NetworkException("Network error"); } }
public void PreLoadStoreData() { PreLoadTask = Task.Factory.StartNew(() => { try { Store = StoreContext.GetDefault(); Store.OfflineLicensesChanged += Store_OfflineLicensesChanged; if (ApplicationData.Current.LocalSettings.Values.TryGetValue("LicenseGrant", out object GrantState)) { if (!Convert.ToBoolean(GrantState)) { License = Store.GetAppLicenseAsync().AsTask().Result; } } else { License = Store.GetAppLicenseAsync().AsTask().Result; } ProductResult = Store.GetStoreProductForCurrentAppAsync().AsTask().Result; } catch (Exception ex) { LogTracer.Log(ex, "Could not load MSStore data"); } }, TaskCreationOptions.LongRunning); }
public async void GetAppInfo() { 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. } // Get app store product details. Because this might take several moments, // display a ProgressRing during the operation. workingProgressRing.IsActive = true; StoreProductResult queryResult = await context.GetStoreProductForCurrentAppAsync(); workingProgressRing.IsActive = false; if (queryResult.Product == null) { // The Store catalog returned an unexpected result. textBlock.Text = "Something went wrong, and the product was not returned."; // Show additional error info if it is available. if (queryResult.ExtendedError != null) { textBlock.Text += $"\nExtendedError: {queryResult.ExtendedError.Message}"; } return; } // Display the price of the app. textBlock.Text = $"The price of this app is: {queryResult.Product.Price.FormattedBasePrice}"; }
private async void PurchaseLicense() { StoreProductResult productResult = await storeContext.GetStoreProductForCurrentAppAsync(); if (productResult.ExtendedError != null) { // An error has occurred return; } StoreAppLicense appLicense = await storeContext.GetAppLicenseAsync(); if (appLicense.IsTrial) { StorePurchaseResult purchaseResult = await productResult.Product.RequestPurchaseAsync(); if (purchaseResult.Status == StorePurchaseStatus.Succeeded) { // Show Gratitude message ThanksForPurchasingDialog dialog = new ThanksForPurchasingDialog(); await dialog.ShowAsync(); } await GetLicense(); } }
/// <summary> /// Invoked when the user asks purchase the app. /// </summary> private async void PurchaseFullLicense() { // Get app store product details StoreProductResult productResult = await storeContext.GetStoreProductForCurrentAppAsync(); if (productResult.ExtendedError != null) { // The user may be offline or there might be some other server failure rootPage.NotifyUser($"ExtendedError: {productResult.ExtendedError.Message}", NotifyType.ErrorMessage); return; } rootPage.NotifyUser("Buying the full license...", NotifyType.StatusMessage); StoreAppLicense license = await storeContext.GetAppLicenseAsync(); if (license.IsTrial) { StorePurchaseResult result = await productResult.Product.RequestPurchaseAsync(); if (result.ExtendedError != null) { rootPage.NotifyUser($"Purchase failed: ExtendedError: {result.ExtendedError.Message}", NotifyType.ErrorMessage); return; } switch (result.Status) { case StorePurchaseStatus.AlreadyPurchased: rootPage.NotifyUser($"You already bought this app and have a fully-licensed version.", NotifyType.ErrorMessage); break; case StorePurchaseStatus.Succeeded: // License will refresh automatically using the StoreContext.OfflineLicensesChanged event break; case StorePurchaseStatus.NotPurchased: rootPage.NotifyUser("Product was not purchased, it may have been canceled.", NotifyType.ErrorMessage); break; case StorePurchaseStatus.NetworkError: rootPage.NotifyUser("Product was not purchased due to a Network Error.", NotifyType.ErrorMessage); break; case StorePurchaseStatus.ServerError: rootPage.NotifyUser("Product was not purchased due to a Server Error.", NotifyType.ErrorMessage); break; default: rootPage.NotifyUser("Product was not purchased due to an Unknown Error.", NotifyType.ErrorMessage); break; } } else { rootPage.NotifyUser("You already bought this app and have a fully-licensed version.", NotifyType.ErrorMessage); } }
private async void DisplayLink() { StoreProductResult result = await storeContext.GetStoreProductForCurrentAppAsync(); if (result.ExtendedError != null) { Utils.ReportExtendedError(result.ExtendedError); return; } await Windows.System.Launcher.LaunchUriAsync(result.Product.LinkUri); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { storeContext = StoreContext.GetDefault(); storeContext.OfflineLicensesChanged += OfflineLicensesChanged; StoreProductResult result = await storeContext.GetStoreProductForCurrentAppAsync(); if (result.ExtendedError == null) { PurchasePrice.Text = result.Product.Price.FormattedPrice; } await GetLicenseState(); }
public async Task <StorePurchaseStatus> PurchaseAsync() { try { await Task.Run(() => { InitLocker.WaitOne(); }); StoreProductResult ProductResult = await Store.GetStoreProductForCurrentAppAsync(); if (ProductResult.ExtendedError == null) { if (ProductResult.Product != null) { StorePurchaseResult Result = await ProductResult.Product.RequestPurchaseAsync(); switch (Result.Status) { case StorePurchaseStatus.AlreadyPurchased: case StorePurchaseStatus.Succeeded: { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = true; break; } } return(Result.Status); } else { return(StorePurchaseStatus.NetworkError); } } else { return(StorePurchaseStatus.NetworkError); } } catch (Exception ex) { LogTracer.Log(ex, $"{nameof(PurchaseAsync)} threw an exception"); return(StorePurchaseStatus.NetworkError); } }
public void PreLoadStoreData() { PreLoadTask = Task.Factory.StartNew(() => { try { Store = StoreContext.GetDefault(); Store.OfflineLicensesChanged += Store_OfflineLicensesChanged; License = Store.GetAppLicenseAsync().AsTask().Result; ProductResult = Store.GetStoreProductForCurrentAppAsync().AsTask().Result; Updates = Store.GetAppAndOptionalStorePackageUpdatesAsync().AsTask().Result; } catch (Exception ex) { LogTracer.Log(ex, "Could not load MSStore data"); } }, TaskCreationOptions.LongRunning); }
private async void InitializeLicense() { try { 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. } appLicense = await context.GetAppLicenseAsync(); if (appLicense.IsActive) { if (appLicense.IsTrial) { int remainingTrialTime = (appLicense.ExpirationDate - DateTime.Now).Days; trial.Visibility = Visibility.Visible; StoreProductResult result = await context.GetStoreProductForCurrentAppAsync(); if (result.ExtendedError == null) { if (result.Product.Price.IsOnSale) { PurchasePrice.Text = "Sale " + result.Product.Price.FormattedPrice; } else { PurchasePrice.Text = "Price " + result.Product.Price.FormattedBasePrice; } } //Debug.WriteLine($"This is the trial version. Expiration date: {appLicense.ExpirationDate}"); textlic.Text = $"You can use this app for {remainingTrialTime} more days before the trial period ends."; // StoreServicesCustomEventLogger logger = StoreServicesCustomEventLogger.GetDefault(); // logger.Log("isTrialEvent"); // textBlock.Text = $"This is the trial version. Expiration date: {appLicense.ExpirationDate}"; // Show the features that are available during trial only. } else { textlic.Text = "You have a full license."; appLicense = await context.GetAppLicenseAsync(); StoreProductResult result = await context.GetStoreProductForCurrentAppAsync(); if (result.ExtendedError == null) { if (result.Product.Price.IsOnSale) { PurchasePrice.Text = "Sale " + result.Product.Price.FormattedPrice; } else { PurchasePrice.Text = "Price " + result.Product.Price.FormattedBasePrice; } //PurchasePrice.Text = "Price " + result.Product.Price.FormattedPrice; } trial.Visibility = Visibility.Collapsed; // StoreServicesCustomEventLogger logger = StoreServicesCustomEventLogger.GetDefault(); // logger.Log("NotTrialEvent"); // Show the features that are available only with a full license. } } else { trial.Visibility = Visibility.Collapsed; //textlic.Text = "You don't have a license. The trial time can't be determined."; //StoreServicesCustomEventLogger logger = StoreServicesCustomEventLogger.GetDefault(); // logger.Log("NotActiveEvent"); } // Register for the licenced changed event. context.OfflineLicensesChanged += context_OfflineLicensesChanged; } catch (Exception ex) { trial.Visibility = Visibility.Collapsed; } }
private async Task PurchaseApplicationAsync() { if (ApplicationData.Current.LocalSettings.Values["IsDonated"] is bool Donated) { if (Donated && !await CheckPurchaseStatusAsync().ConfigureAwait(true)) { await Task.Delay(30000).ConfigureAwait(true); PurchaseTip.ActionButtonClick += async(s, e) => { s.IsOpen = false; StoreContext Store = StoreContext.GetDefault(); StoreProductResult ProductResult = await Store.GetStoreProductForCurrentAppAsync(); if (ProductResult.ExtendedError == null) { if (ProductResult.Product != null) { switch ((await ProductResult.Product.RequestPurchaseAsync()).Status) { case StorePurchaseStatus.Succeeded: { QueueContentDialog QueueContenDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_Store_PurchaseSuccess_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await QueueContenDialog.ShowAsync().ConfigureAwait(true); break; } case StorePurchaseStatus.AlreadyPurchased: { QueueContentDialog QueueContenDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_Store_AlreadyPurchase_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await QueueContenDialog.ShowAsync().ConfigureAwait(true); break; } case StorePurchaseStatus.NotPurchased: { QueueContentDialog QueueContenDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_Store_NotPurchase_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await QueueContenDialog.ShowAsync().ConfigureAwait(true); break; } default: { QueueContentDialog QueueContenDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_Store_NetworkError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await QueueContenDialog.ShowAsync().ConfigureAwait(true); break; } } } } else { QueueContentDialog QueueContenDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_Store_NetworkError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await QueueContenDialog.ShowAsync().ConfigureAwait(true); } }; PurchaseTip.Subtitle = Globalization.GetString("TeachingTip_PurchaseTip_Subtitle"); PurchaseTip.IsOpen = true; ApplicationData.Current.LocalSettings.Values["IsDonated"] = false; } } else { ApplicationData.Current.LocalSettings.Values["IsDonated"] = true; } }