public DonateControl(StoreProductQueryResult queryResult = null)
        {
            this.InitializeComponent();
            //m_Popup = new Popup();

            m_Popup = (Application.Current as App).gPopup;
            MeasurePopupSize();
            m_Popup.Child  = this;
            this.Loaded   += MessagePopupWindow_Loaded;
            this.Unloaded += MessagePopupWindow_Unloaded;
            _queryResult   = queryResult;

            //List<Product> lProducts = new List<Product>();
            //foreach (KeyValuePair<string, StoreProduct> item in _queryResult.Products)
            //{
            //    // Access the Store product info for the add-on.
            //    StoreProduct product = item.Value;

            //    // Use members of the product object to access listing info for the add-on...
            //    Product pd = new Product()
            //    {
            //        StoreId = product.StoreId,
            //        Title = product.Title,
            //        Price = product.Price.FormattedPrice,
            //        Description = product.Description,
            //        ProductImage = product.Images[0].Uri.OriginalString
            //    };

            //    lProducts.Add(pd);
            //}

            //listProducts.ItemsSource = lProducts;
        }
Example #2
0
        private async Task <StoreProduct> GetSubscriptionProductAsync()
        {
            // Load the sellable add-ons for this app and check if the trial is still
            // available for this customer. If they previously acquired a trial they won't
            // be able to get a trial again, and the StoreProduct.Skus property will
            // only contain one SKU.

            StoreProductQueryResult result =
                await context.GetAssociatedStoreProductsAsync(new string[] { "Durable" });

            if (result.ExtendedError != null)
            {
                System.Diagnostics.Debug.WriteLine("Something went wrong while getting the add-ons. " +
                                                   "ExtendedError:" + result.ExtendedError);

                return(null);
            }

            // Look for the product that represents the subscription.

            foreach (var item in result.Products)
            {
                StoreProduct product = item.Value;
                if (product.StoreId == subscriptionStoreId)
                {
                    return(product);
                }
            }

            System.Diagnostics.Debug.WriteLine("The subscription was not found.");
            return(null);
        }
        // Has the user purchased this collection?
        private async Task <bool> IsPurchased()
        {
            if (_Context == null)
            {
                _Context = StoreContext.GetDefault();
            }

            // Specify the kinds of add-ons to retrieve.
            var filterList = new List <string>(new[] { "Durable" });
            var idList     = new List <string>(new[] { _StoreId });

            StoreProductQueryResult queryResult = await _Context.GetStoreProductsAsync(filterList, idList);

            if (queryResult.ExtendedError != null)
            {
                // The user may be offline or there might be some other server failure.
                Debug.WriteLine($"ExtendedError: {queryResult.ExtendedError.Message}");
                return(false);
            }


            foreach (var item in queryResult.Products)
            {
                StoreProduct product = item.Value;
                return(product.IsInUserCollection);
            }

            return(false);
        }
Example #4
0
        private async Task <StoreProduct> GetAdFreeSubscriptionProductAsync()
        {
            // Load the sellable add-ons for this app and check if the trial is still
            // available for this customer. If they previously acquired a trial they won't
            // be able to get a trial again, and the StoreProduct.Skus property will
            // only contain one SKU.
            StoreProductQueryResult result =
                await storeContext.GetAssociatedStoreProductsAsync(new string[] { "Durable" });

            if (result.ExtendedError != null)
            {
                await Helpers.ShowDialog(ResourceStringNames.errorGettingAddOnsFormat.GetResourceString().FormatString(result.ExtendedError));

                return(null);
            }

            // Look for the product that represents the subscription.
            foreach (var item in result.Products)
            {
                StoreProduct product = item.Value;
                if (product.StoreId == adFreeSubscriptionStoreId)
                {
                    return(product);
                }
            }

            await Helpers.ShowDialog(ResourceStringNames.subscriptionToPurchaseNotFound.GetResourceString());

            return(null);
        }
        CreateProductListFromQueryResult(StoreProductQueryResult addOns, string description)
        {
            var productList = new ObservableCollection <ItemDetails>();

            if (addOns.ExtendedError != null)
            {
                ReportExtendedError(addOns.ExtendedError);
            }
            else if (addOns.Products.Count == 0)
            {
                MessageDialog dialog = new MessageDialog("No Add-Ons found for this App...");
                await dialog.ShowAsync();
            }
            else
            {
                foreach (StoreProduct product in addOns.Products.Values)
                {
                    if (product.StoreId == "9PPLX2HDLV2L")
                    {
                        productList.Add(new ItemDetails(product));
                    }
                }
            }
            return(productList);
        }
Example #6
0
        public async void GetUserCollection()
        {
            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.
            }

            // Specify the kinds of add-ons to retrieve.
            string[]      productKinds = { "Durable" };
            List <String> filterList   = new List <string>(productKinds);

            workingProgressRing.IsActive = true;
            StoreProductQueryResult queryResult = await context.GetUserCollectionAsync(filterList);

            workingProgressRing.IsActive = false;

            if (queryResult.ExtendedError != null)
            {
                // The user may be offline or there might be some other server failure.
                textBlock.Text = $"ExtendedError: {queryResult.ExtendedError.Message}";
                return;
            }

            foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products)
            {
                StoreProduct product = item.Value;

                // Use members of the product object to access info for the product...
            }
        }
Example #7
0
        internal static async void CheckIfFullVersion()
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(new string[] { "Durable" });

            if (queryResult.ExtendedError != null)
            {
                TrialSettings.IsTrial = false;
                return;
            }

            foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products)
            {
                if (item.Value.InAppOfferToken == RemoveAdsAndSizeLimit_Token)
                {
                    if (item.Value.IsInUserCollection)
                    {
                        TrialSettings.IsTrial = false;
                    }
                    else
                    {
                        TrialSettings.IsTrial = true;
                    }
                }
            }
        }
Example #8
0
        //查找产品订阅信息
        private async Task <StoreProduct> GetSubscriptionProductAsync()
        {
            //加载此应用程序的可销售外接程序,并检查试用是否仍然存在
            //这个客户可以使用。如果他们以前获得过审判,他们就不会。
            //能够再次获得试用,Store..Skus属性将
            //仅包含一个SKU。
            StoreProductQueryResult result =
                await context.GetAssociatedStoreProductsAsync(new string[] { "Durable" });

            if (result.ExtendedError != null)
            {
                Loading.IsActive = false;
                var messageDig1 = new MessageDialog("获得此订阅时出现了一些问题。");
                //展示窗口,获取按钮是否退出  
                var result1 = await messageDig1.ShowAsync();

                return(null);
            }
            //查找表示订阅的产品。
            foreach (var item in result.Products)
            {
                StoreProduct product = item.Value;
                if (product.StoreId == productID)
                {
                    return(product);
                }
            }
            return(null);
        }
Example #9
0
        internal static async Task <List <PurchaseItem> > GetDonateItems()
        {
            List <PurchaseItem> items = new List <PurchaseItem>();

            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(new string[] { "UnmanagedConsumable" });

            if (queryResult.ExtendedError != null)
            {
                return(items);
            }

            foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products)
            {
                if ((item.Value.InAppOfferToken.Length >= (Donate_TokenBegin.Length + 1)) && (item.Value.InAppOfferToken.Substring(0, Donate_TokenBegin.Length) == Donate_TokenBegin))
                {
                    items.Add(new PurchaseItem
                    {
                        Price   = item.Value.Price,
                        StoreID = item.Value.StoreId,
                        Token   = item.Value.InAppOfferToken,
                    });
                }
            }

            return(items.OrderBy(x => GetPurchaseItemOrder(x)).ToList());
        }
Example #10
0
        private async Task GetAssociatedProductsButton_Click(object sender, RoutedEventArgs e)
        {
            // Create a filtered list of the product AddOns I care about
            string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" };

            // Get list of Add Ons this app can sell, filtering for the types we know about
            StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList);
        }
        private async void GetUnmanagedConsumablesButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            string[] filterList = new string[] { "UnmanagedConsumable" };

            // Get list of Add Ons this app can sell, filtering for the types we know about.
            StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList);

            ProductsListView.ItemsSource = Utils.CreateProductListFromQueryResult(addOns, "UnmanagedConsumable Add-Ons");
        }
Example #12
0
        private async void GetUserCollectionButton_Click(object sender, RoutedEventArgs e)
        {
            // Create a filtered list of the product AddOns I care about
            string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" };

            // Get user collection for this product, filtering for the types we know about
            StoreProductQueryResult collection = await storeContext.GetUserCollectionAsync(filterList);

            ProductsListView.ItemsSource = Utils.CreateProductListFromQueryResult(collection, "collection items");
        }
Example #13
0
        public async void LoadStoreItems()
        {
            // Create a filtered list of the product AddOns I care about
            string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" };

            // Get list of Add Ons this app can sell, filtering for the types we know about
            StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList);

            ProductsListView.ItemsSource = await CreateProductListFromQueryResult(addOns, "Add-Ons");
        }
Example #14
0
        // Check License status
        public static async Task <bool> CheckPurchaseStatus()
        {
            StoreContext store = StoreContext.GetDefault();

            // Donation status is false by default
            bool purchased = false;

            // Check for donation
            // Permanent Ad-free
            string[]                productKinds = { "Durable" };
            List <string>           filterList   = new List <string>(productKinds);
            StoreProductQueryResult result       = await store.GetUserCollectionAsync(filterList);

            if (result != null)
            {
                List <StoreProduct> products = new List <StoreProduct>();
                foreach (var item in result.Products)
                {
                    StoreProduct prod = item.Value;
                    products.Add(prod);
                }

                foreach (var item in products)
                {
                    if (item.IsInUserCollection == true)
                    {
                        purchased = true;
                        Debug.WriteLine("LicenseHelper - Ad-free active");
                    }
                }
            }
            //if (store.GetAssociatedStoreProductsAsync().)
            //if (licenseInformation.ProductLicenses[adfreePermanent].IsActive)
            //{
            //
            //    purchased = true;
            //}
            //// Ad-free Tier 1
            //else if (licenseInformation.ProductLicenses[adfreeTier1].IsActive)
            //{
            //    Debug.WriteLine("IAP: Ad-free T1 active");
            //    purchased = true;
            //}

            return(purchased);
        }
        public async void GetSubscriptionsInfo()
        {
            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.
            }

            // Subscription add-ons are Durable products.
            string[]      productKinds = { "Durable" };
            List <String> filterList   = new List <string>(productKinds);

            workingProgressRing.IsActive = true;
            StoreProductQueryResult queryResult =
                await context.GetAssociatedStoreProductsAsync(productKinds);

            workingProgressRing.IsActive = false;

            if (queryResult.ExtendedError != null)
            {
                // The user may be offline or there might be some other server failure.
                textBlock.Text = $"ExtendedError: {queryResult.ExtendedError.Message}";
                return;
            }

            foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products)
            {
                // Access the Store product info for the add-on.
                StoreProduct product = item.Value;

                // For each add-on, the subscription info is available in the SKU objects in the add-on.
                foreach (StoreSku sku in product.Skus)
                {
                    if (sku.IsSubscription)
                    {
                        // Use the sku.SubscriptionInfo property to get info about the subscription.
                        // For example, the following code gets the units and duration of the
                        // subscription billing period.
                        StoreDurationUnit billingPeriodUnit = sku.SubscriptionInfo.BillingPeriodUnit;
                        uint billingPeriod = sku.SubscriptionInfo.BillingPeriod;
                    }
                }
            }
        }
        public async override Task <IEnumerable <InAppBillingProduct> > GetProductInfoAsync(ItemType itemType, params string[] productIds)
        {
            // Create a filtered list of the product AddOns I care about
            string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" };

            // Get list of Add Ons this app can sell, filtering for the types we know about
            StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList);

            if (addOns.ExtendedError != null)
            {
                Debug.WriteLine("GetProductInfoAsync Extended Error:" + addOns.ExtendedError.ToString());
                throw new InAppBillingPurchaseException(PurchaseError.GeneralError, addOns.ExtendedError);
            }

            StoreProduct product;

            var products = new List <InAppBillingProduct>();

            foreach (KeyValuePair <string, StoreProduct> kvp in addOns.Products)
            {
                Debug.WriteLine("Store Product: key" + kvp.Key + " Product:" + kvp.Value.InAppOfferToken + " " + kvp.Value.StoreId + " " + kvp.Value.ToString());


                foreach (string pid in productIds)
                {
                    if (pid.CompareTo(kvp.Value.InAppOfferToken) == 0)
                    {
                        product = kvp.Value;
                        products.Add(new InAppBillingProduct
                        {
                            Name           = product.Title,
                            Description    = product.Description,
                            ProductId      = kvp.Value.InAppOfferToken,
                            LocalizedPrice = product.Price.FormattedPrice,
                            CurrencyCode   = product.Price.CurrencyCode
                                             //CurrencyCode = product.CurrencyCode // Does not work at the moment, as UWP throws an InvalidCastException when getting CurrencyCode
                        });
                    }
                }
            }

            lastListOfProducts = addOns.Products.Values;

            return(products);
        }
Example #17
0
        public async void DemonstrateTargetedOffers()
        {
            // Get the Microsoft Account token for the current user.
            string msaToken = await GetMicrosoftAccountTokenAsync();

            if (string.IsNullOrEmpty(msaToken))
            {
                System.Diagnostics.Debug.WriteLine("Microsoft Account token could not be retrieved.");
                return;
            }

            // Get the targeted Store offers for the current user.
            List <TargetedOfferData> availableOfferData =
                await GetTargetedOffersForUserAsync(msaToken);

            if (availableOfferData == null || availableOfferData.Count == 0)
            {
                System.Diagnostics.Debug.WriteLine("There was an error retrieving targeted offers," +
                                                   "or there are no targeted offers available for the current user.");
                return;
            }

            // Get the product ID of the add-on that is associated with the first available offer
            // in the response data.
            TargetedOfferData offerData = availableOfferData[0];
            string            productId = offerData.Offers[0];

            // Get the Store ID of the add-on that has the matching product ID, and then purchase the add-on.
            List <String>           filterList  = new List <string>(productKinds);
            StoreProductQueryResult queryResult = await storeContext.GetAssociatedStoreProductsAsync(filterList);

            foreach (KeyValuePair <string, StoreProduct> result in queryResult.Products)
            {
                if (result.Value.InAppOfferToken == productId)
                {
                    await PurchaseOfferAsync(result.Value.StoreId);

                    return;
                }
            }

            System.Diagnostics.Debug.WriteLine("No add-on with the specified product ID could be found " +
                                               "for the current app.");
            return;
        }
Example #18
0
        public async Task <bool> HasAlreadyDonated()
        {
            try
            {
                if (SettingsService.Get <bool>(SettingsKeys.HasUserDonated))
                {
                    return(true);
                }
                else
                {
                    StoreContext WindowsStore = StoreContext.GetDefault();

                    string[]      productKinds = { "Durable" };
                    List <String> filterList   = new List <string>(productKinds);

                    StoreProductQueryResult queryResult = await WindowsStore.GetUserCollectionAsync(filterList);

                    if (queryResult.ExtendedError != null)
                    {
                        return(false);
                    }

                    foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products)
                    {
                        if (item.Value != null)
                        {
                            if (item.Value.IsInUserCollection)
                            {
                                SettingsService.Save(SettingsKeys.HasUserDonated, true, true);
                                return(true);
                            }
                        }
                        return(false);
                    }
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }
Example #19
0
        /// <summary>
        /// Gets all the purchased products for current user and app
        /// </summary>
        /// <param name="itemType">not used for UWP</param>
        /// <returns></returns>
        public async Task <List <PurchaseResult> > GetPurchaseHistoryAsync(ItemType itemType = ItemType.InAppPurchase)
        {
            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.
            }

            // Specify the kinds of add-ons to retrieve.
            string[] productKinds = { "Durable", "Subscription" };
            var      filterList   = new List <string>(productKinds);

            StoreProductQueryResult queryResult = await context.GetUserCollectionAsync(filterList);

            if (queryResult.ExtendedError != null)
            {
                // The user may be offline or there might be some other server failure.
                throw new Exception(queryResult.ExtendedError.Message, queryResult.ExtendedError.InnerException);
            }
            var purchaseHistoryResult = new List <PurchaseResult>();

            if (queryResult?.Products?.Count > 0)
            {
                foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products)
                {
                    StoreProduct product = item.Value;

                    var purchaseHistory = new PurchaseResult();

                    purchaseHistory.Sku           = product.InAppOfferToken;
                    purchaseHistory.PurchaseToken = null;

                    purchaseHistory.DeveloperPayload = product.Skus?[0].CustomDeveloperData;

                    purchaseHistoryResult.Add(purchaseHistory);
                    // Use members of the product object to access info for the product...
                }
            }

            return(purchaseHistoryResult);
        }
Example #20
0
        public async Task CheckLicence(bool force = false)
        {
            if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
            {
                Constants.IAP_HIDEADS = true;
                return;
            }

            if (SettingsModel.Instance.START_COUNT % 5 == 0 || force)
            {
                try
                {
                    StoreProductQueryResult AddOns = await StoreContext.GetDefault().GetUserCollectionAsync(Constants.IAP_STORE_LIST_ADDON_TYPES);

                    Constants.IAP_HIDEADS =
                        AddOns.Products.ContainsKey(Constants.IAP_FEATUREID_ADFREE) ||
                        AddOns.Products.ContainsKey(Constants.IAP_FEATUREID_ADFREE_365);
                }
                catch (Exception ex)
                {
                    Log.Write("Could not Get IAP", ex, logType: LogType.Error);
                    Constants.IAP_HIDEADS = false;
                }
                SettingsModel.Instance.IAP_HIDEADS = Constants.IAP_HIDEADS;
            }
            else if (SettingsModel.Instance.IAP_HIDEADS)
            {
                Constants.IAP_HIDEADS = true;
            }
            if (!Constants.IAP_HIDEADS)
            {
                bool b = new FileInfo(SharedIO.CurrentIO.GetCompleteInternPath(Place.Local) + @"noads\").Exists;
                if (b)
                {
                    Constants.IAP_HIDEADS = true;
                }
                //var Info = await SharedIO.CurrentIO.GetFolderInfo(new FileInfo(Place.Local, "", SharedIO.CurrentIO.GetCompleteInternPath(Place.Local) + @"noads\"), UserDecision.ThrowError);
                //if (Info != null)
                //{
                //    Constants.IAP_HIDEADS = true;
                //}
            }
        }
            CreateProductListFromQueryResult(StoreProductQueryResult addOns, string description)
        {
            var productList = new ObservableCollection<ItemDetails>();

            if (addOns.ExtendedError != null)
            {
                ReportExtendedError(addOns.ExtendedError);
            }
            else if (addOns.Products.Count == 0)
            {
                MainPage.Current.NotifyUser($"No configured {description} found for this Store Product.", NotifyType.ErrorMessage);
            }
            else
            {
                foreach (StoreProduct product in addOns.Products.Values)
                {
                    productList.Add(new ItemDetails(product));
                }
            }
            return productList;
        }
        CreateProductListFromQueryResult(StoreProductQueryResult addOns, string description)
        {
            var productList = new ObservableCollection <ItemDetails>();

            if (addOns.ExtendedError != null)
            {
                ReportExtendedError(addOns.ExtendedError);
            }
            else if (addOns.Products.Count == 0)
            {
                MainPage.Current.NotifyUser($"No configured {description} found for this Store Product.", NotifyType.ErrorMessage);
            }
            else
            {
                foreach (StoreProduct product in addOns.Products.Values)
                {
                    productList.Add(new ItemDetails(product));
                }
            }
            return(productList);
        }
Example #23
0
        private async void Enumerate_Optional_Packages_From_Store(object sender, RoutedEventArgs e)
        {
            try
            {
                String[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" };

                StoreProductQueryResult addOns = await context.GetAssociatedStoreProductsAsync(filterList);

                foreach (var addOn in addOns.Products)
                {
                    StoreProductControl spc = new StoreProductControl();
                    spc.PackageName = addOn.Value.Title;
                    spc.DataContext = addOn.Value;

                    storeOptionalPackagesList.Add(spc);
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog("Unable to enumerate store optional packages. {" + ex.Message + "}").ShowAsync();
            }
        }
Example #24
0
        private static async void GetAddOnsAsync(Action <WSAStoreProductQueryResult> response)
        {
            string[] productKinds = { "Durable", "Consumable", "UnmanagedConsumable" };

            StoreProductQueryResult result = await StoreContext.GetDefault().GetAssociatedStoreProductsAsync(productKinds.ToList());

            WSAStoreProductQueryResult wsaStoreProductQuery = new WSAStoreProductQueryResult()
            {
                Products = result.Products.ToDictionary(x => x.Key, y => new WSAStoreProduct()
                {
                    Description        = y.Value.Description,
                    FormattedPrice     = y.Value.Price.FormattedPrice,
                    Images             = y.Value.Images.Select(x => x.Uri).ToList(),
                    InAppOfferToken    = y.Value.InAppOfferToken,
                    IsInUserCollection = y.Value.IsInUserCollection,
                    Language           = y.Value.Language,
                    LinkUri            = y.Value.LinkUri,
                    ProductKind        = y.Value.ProductKind,
                    StoreId            = y.Value.StoreId,
                    Title            = y.Value.Title,
                    Videos           = y.Value.Videos.Select(x => x.Uri).ToList(),
                    SubscriptionInfo = y.Value.Skus.First().SubscriptionInfo != null ? new WSAStoreSubscriptionInfo()
                    {
                        BillingPeriod     = (int)y.Value.Skus.First().SubscriptionInfo.BillingPeriod,
                        BillingPeriodUnit = (WSAStoreDurationUnit)y.Value.Skus.First().SubscriptionInfo.BillingPeriodUnit,
                        HasTrialPeriod    = y.Value.Skus.First().SubscriptionInfo.HasTrialPeriod,
                        TrialPeriod       = (int)y.Value.Skus.First().SubscriptionInfo.TrialPeriod,
                        TrialPeriodUnit   = (WSAStoreDurationUnit)y.Value.Skus.First().SubscriptionInfo.TrialPeriodUnit
                    } : null
                }),
                Error = result.ExtendedError
            };

            if (response != null)
            {
                response(wsaStoreProductQuery);
            }
        }
Example #25
0
        public async Task <Response <List <AddOnItem> > > GetAllAddOns()
        {
            if (IsStoreContextTypePresent)
            {
                StoreContext storeContext             = StoreContext.GetDefault();
                Response <List <AddOnItem> > response = new Response <List <AddOnItem> >();
                string[] productKinds = { "Durable", "Consumable", "UnmanagedConsumable" };
                StoreProductQueryResult queryResult = await storeContext.GetAssociatedStoreProductsAsync(productKinds);

                if (queryResult.ExtendedError != null)
                {
                    response.IsError = true;
                    response.Message = queryResult.ExtendedError.Message;
                    response.Error   = queryResult.ExtendedError;
                }
                else
                {
                    List <AddOnItem> ret = new List <AddOnItem>();
                    IReadOnlyDictionary <string, StoreLicense> licenses = await GetAddOnLicenses();

                    foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products)
                    {
                        AddOnItem    addOn        = new AddOnItem(item.Value);
                        var          matchingPair = licenses.FirstOrDefault(p => p.Key.StartsWith(item.Key));
                        StoreLicense license      = matchingPair.Value;
                        addOn.IsActive   = license?.IsActive ?? false;
                        addOn.ExpiryDate = license?.ExpirationDate ?? default(DateTimeOffset);
                        ret.Add(addOn);
                    }
                    response.Content = ret;
                }
                return(response);
            }
            else
            {
                return(new Response <List <AddOnItem> >());
            }
        }
Example #26
0
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--


        #endregion
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        public static async Task <List <StoreProduct> > RequestConsumablesAsync()
        {
            List <StoreProduct> products = new List <StoreProduct>();

            string[]      productKinds = { UNMANAGED_CONSUMABLE };
            List <string> filterList   = new List <string>(productKinds);

            try
            {
                StoreProductQueryResult queryResult = await StoreContext.GetDefault().GetAssociatedStoreProductsAsync(filterList);

                if (queryResult != null)
                {
                    products.AddRange(queryResult.Products.Values);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error during requesting consumable products.", e);
            }

            return(products);
        }
        public async void GetAddOnInfo()
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            string[]      productKinds = { "Durable", "Consumable", "UnmanagedConsumable" };
            List <String> filterList   = new List <string>(productKinds);

            StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(filterList);

            if (queryResult.ExtendedError != null)
            {
                logger.Error("Could not get add-on info: " + queryResult.ExtendedError.Message);
                return;
            }

            foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products)
            {
                StoreProduct product = item.Value;
            }
        }
        public async void CheckTrialStatus()
        {
            string[]        filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" };
            StoreAppLicense license    = await storeContext.GetAppLicenseAsync();

            StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList);

            if (license.IsActive)
            {
                if (license.IsTrial)
                {
                    UpdateTile("Trial license");
                }
                else
                {
                    UpdateTile("Full license");
                }
            }
            else
            {
                UpdateTile(license.ToString());
                ShowToast(license.ToString());
            }
        }
Example #29
0
        private async void GetAssociatedProducts()
        {
            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.
            }
            // Create a filtered list of the product AddOns I care about
            string[] filterList            = new string[] { "Consumable", "Durable", "UnmanagedConsumable" };
            StoreProductQueryResult addOns = null;

            try
            {
                // Get list of Add Ons this app can sell, filtering for the types we know about
                addOns = await context.GetAssociatedStoreProductsAsync(filterList);
            }
            catch
            {
                var dialog = new MessageDialog("Could not load Products...");
            }
            ProductsListView.ItemsSource = await Utils.CreateProductListFromQueryResult(addOns, "Add-Ons");
        }
Example #30
0
        private async Task <InAppBillingProduct> GetSubscriptionProductAsync(string subscriptionStoreId)
        {
            var Products = new List <InAppBillingProduct>();
            // Load the sellable add-ons for this app and check if the trial is still
            // available for this customer. If they previously acquired a trial they won't
            // be able to get a trial again, and the StoreProduct.Skus property will
            // only contain one SKU.
            StoreProductQueryResult result =
                await context.GetAssociatedStoreProductsAsync(new string[] { "Durable" });

            if (result.ExtendedError != null)
            {
                throw new Exception(result.ExtendedError.Message, result.ExtendedError.InnerException);
            }

            // Look for the product that represents the subscription.
            foreach (var item in result.Products)
            {
                StoreProduct product = item.Value;
                if (product.InAppOfferToken == subscriptionStoreId)
                {
                    var sku = product.Skus[0];
                    storeProduct = product;
                    return(new InAppBillingProduct()
                    {
                        ProductId = product.InAppOfferToken,
                        LocalizedPrice = product.Price.FormattedPrice,
                        Description = product.Description,
                        Name = product.Title
                    });
                }
            }


            return(null);
        }
Example #31
0
        public async void PurchaseSubscription(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.
            }

            // First, get the StoreProduct object for the subscription add-on. This example
            // assumes you already know the Store ID for the add-on and you have passed
            // it to this method.
            string[]      productKinds = { "Durable" };
            List <String> filterList   = new List <string>(productKinds);

            string[] storeIds = new string[] { storeId };

            workingProgressRing.IsActive = true;
            StoreProductQueryResult queryResult =
                await context.GetStoreProductsAsync(filterList, storeIds);

            workingProgressRing.IsActive = false;

            StoreProduct mySubscription = queryResult.Products.FirstOrDefault().Value;

            // Make sure the user has not already acquired the subscription add-on, then
            // offer it for purchase to the user.
            if (!mySubscription.IsInUserCollection)
            {
                workingProgressRing.IsActive = true;
                StorePurchaseResult result = await mySubscription.RequestPurchaseAsync();

                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 StorePurchaseStatus.Succeeded:
                    textBlock.Text = "The purchase was successful.";
                    break;

                case StorePurchaseStatus.NotPurchased:
                    textBlock.Text = "The purchase did not complete. " +
                                     "The user may have cancelled the purchase. ExtendedError: " + extendedError;
                    break;

                case StorePurchaseStatus.NetworkError:
                    textBlock.Text = "The purchase was unsuccessful due to a network error. " +
                                     "ExtendedError: " + extendedError;
                    break;

                case StorePurchaseStatus.ServerError:
                    textBlock.Text = "The purchase was unsuccessful due to a server error. " +
                                     "ExtendedError: " + extendedError;
                    break;

                default:
                    textBlock.Text = "The purchase was unsuccessful due to an unknown error. " +
                                     "ExtendedError: " + extendedError;
                    break;
                }
            }
        }