private static async Task <bool> CheckPurchaseStatusAsync() { try { StoreContext Store = StoreContext.GetDefault(); StoreAppLicense License = await Store.GetAppLicenseAsync(); if (License.AddOnLicenses.Any((Item) => Item.Value.InAppOfferToken == "Donation")) { return(true); } if (License.IsActive) { if (License.IsTrial) { return(false); } else { return(true); } } else { return(false); } } catch { throw new NetworkException("Network Exception"); } }
public async Task <bool> CheckIfUserHasAdFreeSubscriptionAsync() { if (storeContext == null) { storeContext = StoreContext.GetDefault(); //IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext; //initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); } StoreAppLicense appLicense = await storeContext.GetAppLicenseAsync(); // Check if the customer has the rights to the subscription. foreach (var addOnLicense in appLicense.AddOnLicenses) { StoreLicense license = addOnLicense.Value; if (license.SkuStoreId.StartsWith(adFreeSubscriptionStoreId)) { if (license.IsActive) { // The expiration date is available in the license.ExpirationDate property. return(true); } } } // The customer does not have a license to the subscription. return(false); }
public string getName() { StoreContext storeContext = StoreContext.GetDefault(); StoreAppLicense license = storeContext.GetAppLicenseAsync().AsTask().Result; if (license == null) { return(LocaleFactory.localizedString("Unknown")); } if (license.IsActive) { if (license.IsTrial) { return(LocaleFactory.localizedString("Trial Version", "License")); } else { return((string)storeContext.User?.GetPropertyAsync(KnownUserProperties.DisplayName).AsTask().Result ?? LocaleFactory.localizedString("Unknown")); } } else { return(LocaleFactory.localizedString("Unknown")); } }
public async void GetLicenseInfo() { if (context == null) { context = StoreContext.GetDefault(); } StoreAppLicense appLicense = await context.GetAppLicenseAsync(); if (appLicense == null) { // textBlock.Text = "An error occurred while retrieving the license."; return; } // Access the add on licenses for add-ons for this app. foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses) { StoreLicense addOnLicense = item.Value; // Use members of the addOnLicense object to access license info // for the add-on... //addOnLicense. if (addOnLicense.IsActive) { AdGrid.Visibility = Visibility.Collapsed; } } }
public bool verify(LicenseVerifierCallback callback) { StoreContext storeContext = StoreContext.GetDefault(); StoreAppLicense license = storeContext.GetAppLicenseAsync().AsTask().Result; return(true || (license?.IsActive ?? true)); // HACK Windows Store Submission Process }
/// <summary> /// Get All Purchases /// </summary> /// <param name="itemType">not used for UWP</param> /// <returns></returns> public async Task <List <PurchaseResult> > GetPurchasesAsync(ItemType itemType = ItemType.InAppPurchase, IInAppBillingVerifyPurchase verifyPurchase = null, string verifyOnlyProductId = null) { if (context == null) { context = StoreContext.GetDefault(); } var PurchaseHistoryResult = new List <PurchaseResult>(); StoreAppLicense appLicense = await context.GetAppLicenseAsync(); if (appLicense?.AddOnLicenses?.Count > 0) { foreach (var addOnLicense in appLicense.AddOnLicenses) { StoreLicense license = addOnLicense.Value; var purchaseHistory = new PurchaseResult(); purchaseHistory.Sku = license.InAppOfferToken; //UWP SkuStoreId is different than Product ID, InAppOfferToken is the product ID purchaseHistory.PurchaseToken = license.SkuStoreId; purchaseHistory.ExpirationDate = license.ExpirationDate; if (!license.IsActive) { purchaseHistory.PurchaseState = PurchaseState.Cancelled; } else { purchaseHistory.PurchaseState = PurchaseState.Purchased; } PurchaseHistoryResult.Add(purchaseHistory); } } // The customer does not have a license to the subscription. return(PurchaseHistoryResult); }
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); }
/// <inheritdoc/> public async Task <bool> IsOwnedAsync(string iapId) { if (!NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable) { return(false); } if (_context == null) { _context = StoreContext.GetDefault(); } StoreAppLicense appLicense = await _context.GetAppLicenseAsync(); if (appLicense == null) { return(false); } /// Check if user has an active license for given add-on id. foreach (var addOnLicense in appLicense.AddOnLicenses) { var license = addOnLicense.Value; if (license.InAppOfferToken == iapId && license.IsActive) { return(true); } } return(false); }
public async void GetLicenseInfo() { 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. } workingProgressRing.IsActive = true; StoreAppLicense appLicense = await context.GetAppLicenseAsync(); workingProgressRing.IsActive = false; if (appLicense == null) { textBlock.Text = "An error occurred while retrieving the license."; return; } // Use members of the appLicense object to access license info... // Access the valid licenses for durable add-ons for this app. foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses) { StoreLicense addOnLicense = item.Value; // Use members of the addOnLicense object to access license info // for the add-on. } }
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 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(); } }
private async void context_OfflineLicensesChanged(StoreContext sender, object args) { // Reload the license. try { appLicense = await context.GetAppLicenseAsync(); if (appLicense.IsActive) { if (appLicense.IsTrial) { Debug.WriteLine($"This is the trial version. Expiration date: {appLicense.ExpirationDate}"); // textBlock.Text = $"This is the trial version. Expiration date: {appLicense.ExpirationDate}"; // Show the features that are available during trial only. } else { Debug.WriteLine("rff"); // Show the features that are available only with a full license. } } } catch (Exception ex) { } }
private static async Task <bool> CheckIfUserHasSubscriptionAsync(string msProductId) { if (context == null) { context = StoreContext.GetDefault(); } StoreAppLicense appLicense = await context.GetAppLicenseAsync(); // Check if the customer has the rights to the subscription. foreach (var addOnLicense in appLicense.AddOnLicenses) { StoreLicense license = addOnLicense.Value; if (license.SkuStoreId.StartsWith(msProductId)) { if (license.IsActive) { // The expiration date is available in the license.ExpirationDate property. accountType = "starter"; updateCloureAccount(license.ExpirationDate); return(true); } } } // The customer does not have a license to the subscription. return(false); }
private async Task InitializeAppLicenceAsync() { #if !DEBUG_TRAIL var storeContext = StoreContext.GetDefault(); AppLicense = await storeContext.GetAppLicenseAsync(); #endif D("Application license obtained"); }
private void CheckLicense(StoreAppLicense license) { if (license.IsActive && license.IsTrial) { isTrial = true; VisualStateManager.GoToState(this, "TrialState", true); } }
/// <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 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; //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."; 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; } }
public async Task <IReadOnlyDictionary <string, StoreLicense> > GetAddOnLicenses() { StoreContext storeContext = StoreContext.GetDefault(); StoreAppLicense appLicense = await storeContext.GetAppLicenseAsync(); if (appLicense == null) { return(null); } return(appLicense.AddOnLicenses); }
/// <summary> /// Checks if user has active subscription and durables. it doesnt include consumeables /// </summary> /// <param name="subscriptionStoreId">if it is not provided, checks if there is an active licence.</param> /// <returns></returns> public async Task <bool> CheckIfUserHasActiveSubscriptionAsync(string subscriptionStoreId, ItemType itemType = ItemType.InAppPurchase) { if (context == null) { context = StoreContext.GetDefault(); } StoreAppLicense appLicense = await context.GetAppLicenseAsync(); return(appLicense.AddOnLicenses.Any(s => (s.Value.InAppOfferToken.StartsWith("sub_") || s.Value.SkuStoreId.StartsWith("sub_")) && s.Value.ExpirationDate > DateTime.Now)); }
public async Task <bool> CheckPurchaseStatusAsync() { try { if (ApplicationData.Current.LocalSettings.Values.TryGetValue("LicenseGrant", out object GrantState) && Convert.ToBoolean(GrantState)) { return(true); } if (HasVerifiedLicense && ApplicationData.Current.LocalSettings.Values.ContainsKey("LicenseGrant")) { return(Convert.ToBoolean(ApplicationData.Current.LocalSettings.Values["LicenseGrant"])); } else { HasVerifiedLicense = true; StoreAppLicense License = GetLicenseTask == null ? await Store.GetAppLicenseAsync() : await GetLicenseTask.ConfigureAwait(false); if (License.AddOnLicenses.Any((Item) => Item.Value.InAppOfferToken == "Donation")) { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = true; return(true); } else { if (License.IsActive) { if (License.IsTrial) { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = false; return(false); } else { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = true; return(true); } } else { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = false; return(false); } } } } catch (Exception ex) { LogTracer.Log(ex, $"{nameof(CheckPurchaseStatusAsync)} threw an exception"); return(false); } }
public async Task <bool> HasLicense() { if (storeContext == null) { storeContext = StoreContext.GetDefault(); //IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext; //initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); } StoreAppLicense license = await storeContext.GetAppLicenseAsync(); return(license != null && license.IsActive); }
public StoreContextViewModel(StoreAppLicense appLicense) { this.appLicense = appLicense; if (IsNotExpired) { title = string.Format(Properties.Resources.Store_NotExipredTitle, (int)(appLicense.ExpirationDate - DateTime.Now).TotalDays); content = Properties.Resources.Store_NotExpiredContent; } else { title = Properties.Resources.Store_ExpiredTitle; content = Properties.Resources.Store_ExpiredContent; } }
private async void InitializeLicense() { if (context == null) { context = StoreContext.GetDefault(); } appLicense = await context.GetAppLicenseAsync(); // register changed event, in case license change during app session context.OfflineLicensesChanged += Context_OfflineLicensesChanged; CheckLicense(appLicense); }
private async void Store_OfflineLicensesChanged(StoreContext sender, object args) { try { StoreAppLicense License = await sender.GetAppLicenseAsync(); if (License.IsActive && !License.IsTrial) { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = true; } } catch (Exception ex) { LogTracer.Log(ex, $"{nameof(Store_OfflineLicensesChanged)} threw an exception"); } }
// Call this while your app is initializing. private async void InitializeLicense() { 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. } workingProgressRing.IsActive = true; appLicense = await context.GetAppLicenseAsync(); workingProgressRing.IsActive = false; // Register for the licenced changed event. context.OfflineLicensesChanged += context_OfflineLicensesChanged; }
public async void InitializeLicenseAsync() { if (storeContext == null) { storeContext = StoreContext.GetDefault(); storeContext.As <IInitializeWithWindow>().Initialize(new WindowInteropHelper(this).Handle); } ProgressRing.IsActive = true; appLicense = await storeContext.GetAppLicenseAsync(); ProgressRing.IsActive = false; if (appLicense.IsTrial) { await ShowStoreContextControlAsync(appLicense); } storeContext.OfflineLicensesChanged += StoreContext_OfflineLicensesChanged; }
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 StoreContext_OfflineLicensesChanged(StoreContext sender, object args) { ProgressRing.IsActive = true; appLicense = await storeContext.GetAppLicenseAsync(); ProgressRing.IsActive = false; if (appLicense.IsActive) { if (appLicense.IsTrial) { // Trial period has been expired. await ShowStoreContextControlAsync(appLicense); } else { // Show the features that are available only with a full license. } } }
private async Task GetLicenseState() { StoreAppLicense license = await storeContext.GetAppLicenseAsync(); if (license.IsActive) { if (license.IsTrial) { LicenseMode.Text = "Trial license"; } else { LicenseMode.Text = "Full license"; } } else { LicenseMode.Text = "Inactive license"; } }
protected override void LicenseChanged(StoreAppLicense license) { if (license == null) { return; } if (license.IsActive) { if (license.IsTrial) { TrialPanel.Visibility = Visibility.Visible; ActivePanel.Visibility = Visibility.Collapsed; } else { TrialPanel.Visibility = Visibility.Collapsed; ActivePanel.Visibility = Visibility.Visible; } } }