Exemplo n.º 1
0
        private async Task <StorePurchaseResult> PurchaseAddOn(string InAppOfferToken)
        {
            string[] filterList = new string[] { "Durable" };

            if (UtilityData.addOnCollection == null || UtilityData.addOnCollection.ExtendedError != null)
            {
                UtilityData.addOnCollection = await storeContext.GetUserCollectionAsync(filterList);
            }

            var isPurchasedList = UtilityData.addOnCollection.Products.Values.Where(p => p.InAppOfferToken.Equals(InAppOfferToken)).ToList();

            if (isPurchasedList.Count == 0)
            {
                if (UtilityData.addOnsAssociatedStoreProducts == null)
                {
                    UtilityData.addOnsAssociatedStoreProducts = await storeContext.GetAssociatedStoreProductsAsync(filterList);
                }

                var AddOnList = UtilityData.addOnsAssociatedStoreProducts.Products.Values.Where(p => p.InAppOfferToken.Equals(InAppOfferToken)).ToList();

                StorePurchaseResult result = await storeContext.RequestPurchaseAsync(AddOnList[0].StoreId);

                return(result);
            }
            return(null);
        }
Exemplo n.º 2
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...
            }
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        public async Task UpdatePurchasesInfo()
        {
            if (StoreContext == null)
            {
                StoreContext = StoreContext.GetDefault();
            }

            var queryResult = await StoreContext.GetUserCollectionAsync(_productKinds);

            _userCollection = queryResult.Products;
            InitialCheck    = true;
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public async Task <bool> IsPremium()
        {
            // See if user has donated or purchased premium
            var result = await _storeContext.GetUserCollectionAsync(new[] { "Durable", "Consumable", "UnmanagedConsumable" });

            foreach (var item in result.Products)
            {
                var product = item.Value;

                if (string.Compare(product.StoreId, "", StringComparison.OrdinalIgnoreCase) == 0 && product.IsInUserCollection)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        private async void btpinIAP_Click(object sender, RoutedEventArgs e)
        {
            this.FindName("gdPurchasingAddon");
            gdPurchasingAddon.Visibility = Visibility.Visible;

            try
            {
                if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3))
                {
                    string[] filterList = new string[] { "Durable" };

                    if (UtilityData.addOnCollection == null || UtilityData.addOnCollection.ExtendedError != null)
                    {
                        UtilityData.addOnCollection = await storeContext.GetUserCollectionAsync(filterList);
                    }

                    var isPurchasedList = UtilityData.addOnCollection.Products.Values.Where(p => p.InAppOfferToken.Equals(UtilityData.PinIAP)).ToList();
                    if (isPurchasedList.Count == 0)
                    {
                        if (UtilityData.addOnsAssociatedStoreProducts == null)
                        {
                            UtilityData.addOnsAssociatedStoreProducts = await storeContext.GetAssociatedStoreProductsAsync(filterList);
                        }

                        var AddOnList = UtilityData.addOnsAssociatedStoreProducts.Products.Values.Where(p => p.InAppOfferToken.Equals(UtilityData.PinIAP)).ToList();

                        StorePurchaseResult result = await storeContext.RequestPurchaseAsync(AddOnList[0].StoreId);

                        if (result != null)
                        {
                            switch (result.Status)
                            {
                            case StorePurchaseStatus.AlreadyPurchased:
                                PinLicense();
                                break;

                            case StorePurchaseStatus.Succeeded:
                                ApplicationData.Current.RoamingSettings.Values[UtilityData.UpPin] = true;
                                PinLicense();
                                UtilityClass.MessageDialog("Thank You very much for Purchasing. We really appreciate your kind support!", "Thank You very much! :)");
                                break;

                            case StorePurchaseStatus.NetworkError:
                            case StorePurchaseStatus.ServerError:
                                UtilityClass.MessageDialog("An Error Occured , Please Try Again!", "Error occured while purchasing.");
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (UtilityData.AppLicenseInformation == null)
                    {
                        UtilityData.AppLicenseInformation = CurrentApp.LicenseInformation;
                    }
                    if (!UtilityData.AppLicenseInformation.ProductLicenses["PinIAP"].IsActive)
                    {
                        try
                        {
                            PurchaseResults results = await CurrentApp.RequestProductPurchaseAsync("PinIAP");

                            if (results.Status == ProductPurchaseStatus.Succeeded)
                            {
                                ApplicationData.Current.RoamingSettings.Values["UpPin"] = UtilityData.AppLicenseInformation.ProductLicenses["PinIAP"].IsActive;
                                PinLicense();
                                UtilityClass.MessageDialog("Thank You very much for Purchasing. We really appreciate your kind support!", "Thank You very much! :)");
                            }
                        }
                        catch
                        {
                            UtilityClass.MessageDialog("Please Check your Internet Connection and then try again", "No Internet Connection.");
                        }
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception)
            {
                UtilityClass.MessageDialog("Please Check your Internet Connection and then try again", "No Internet Connection.");
            }
            finally
            {
                if (gdPurchasingAddon != null)
                {
                    gdPurchasingAddon.Visibility = Visibility.Collapsed;
                }
            }
        }
Exemplo n.º 10
0
        //</GetTargetedOffers>

        // This method uses the Windows.Services.Store APIs to purchase and claim a targeted offer.
        // Only call this method if the app is running on Windows 10, version 1607, or later.
        //<ClaimOfferOnWindows1607AndLater>
        private async Task ClaimOfferOnWindows1607AndLaterAsync(
            string productId, TargetedOfferData offerData, string msaToken)
        {
            if (string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(msaToken))
            {
                System.Diagnostics.Debug.WriteLine("Product ID or Microsoft Account token is null or empty.");
                return;
            }

            // Purchase the add-on for the current user. Typically, a game or app would first show
            // a UI that prompts the user to buy the add-on; for simplicity, this example
            // simply purchases the add-on.
            StorePurchaseResult result = await storeContext.RequestPurchaseAsync(productId);

            if (result.Status == StorePurchaseStatus.Succeeded)
            {
                // Get the StoreProduct in the user's collection that matches the targeted offer.
                List <String>           filterList  = new List <string>(productKinds);
                StoreProductQueryResult queryResult = await storeContext.GetUserCollectionAsync(filterList);

                KeyValuePair <string, StoreProduct> offer =
                    queryResult.Products.Where(p => p.Key == productId).SingleOrDefault();

                if (offer == null)
                {
                    System.Diagnostics.Debug.WriteLine("No StoreProduct with the specified product ID could be found.");
                    return;
                }

                StoreProduct product = offer.Value;

                // Parse the JSON string returned by StoreProduct.ExtendedJsonData to get the order ID.
                string extendedJsonData = product.ExtendedJsonData;
                string skuAvailability  =
                    JObject.Parse(extendedJsonData)["DisplaySkuAvailabilities"].FirstOrDefault().ToString();
                string sku            = JObject.Parse(skuAvailability)["Sku"].ToString();
                string collectionData = JObject.Parse(sku)["CollectionData"].ToString();
                string orderId        = JObject.Parse(collectionData)["orderId"].ToString();

                var claim = new TargetedOfferClaim
                {
                    StoreOffer = offerData,
                    Receipt    = orderId
                };

                // Submit a request to claim the offer by sending a POST message to the
                // Store endpoint for targeted offers.
                using (var httpClientClaimOffer = new HttpClient())
                {
                    var uri = new Uri(storeOffersUri, UriKind.Absolute);

                    using (var request = new HttpRequestMessage(HttpMethod.Post, uri))
                    {
                        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", msaToken);

                        request.Content = new StringContent(
                            JsonConvert.SerializeObject(claim),
                            Encoding.UTF8,
                            jsonMediaType);

                        using (var response = await httpClientClaimOffer.SendAsync(request))
                        {
                            response.EnsureSuccessStatusCode();
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        private async Task PurchaseInAppPurchase(string Product, string strRoaming)
        {
            try
            {
                if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3))
                {
                    string[] filterList = new string[] { "Durable" };

                    if (UtilityData.addOnCollection == null || UtilityData.addOnCollection.ExtendedError != null)
                    {
                        UtilityData.addOnCollection = await storeContext.GetUserCollectionAsync(filterList);
                    }

                    var isPurchasedList = UtilityData.addOnCollection.Products.Values.Where(p => p.InAppOfferToken.Equals(Product)).ToList();
                    if (isPurchasedList.Count == 0)
                    {
                        if (UtilityData.addOnsAssociatedStoreProducts == null)
                        {
                            UtilityData.addOnsAssociatedStoreProducts = await storeContext.GetAssociatedStoreProductsAsync(filterList);
                        }

                        var AddOnList = UtilityData.addOnsAssociatedStoreProducts.Products.Values.Where(p => p.InAppOfferToken.Equals(Product)).ToList();

                        StorePurchaseResult result = await storeContext.RequestPurchaseAsync(AddOnList[0].StoreId);

                        if (result != null)
                        {
                            switch (result.Status)
                            {
                            case StorePurchaseStatus.AlreadyPurchased:
                                break;

                            case StorePurchaseStatus.Succeeded:
                                ApplicationData.Current.RoamingSettings.Values[strRoaming] = true;
                                UtilityClass.MessageDialog("Thank You very much for Purchasing. We really appreciate your kind support!", "Thank You very much! :)");
                                break;

                            case StorePurchaseStatus.NetworkError:
                            case StorePurchaseStatus.ServerError:
                                UtilityClass.MessageDialog("An Error Occured , Please Try Again!", "Error occured while purchasing.");
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (UtilityData.AppLicenseInformation == null)
                    {
                        UtilityData.AppLicenseInformation = CurrentApp.LicenseInformation;
                    }
                    if (!UtilityData.AppLicenseInformation.ProductLicenses[Product].IsActive)
                    {
                        try
                        {
                            PurchaseResults results = await CurrentApp.RequestProductPurchaseAsync(Product);

                            if (results.Status == ProductPurchaseStatus.Succeeded)
                            {
                                ApplicationData.Current.RoamingSettings.Values[strRoaming] = UtilityData.AppLicenseInformation.ProductLicenses[Product].IsActive;
                                BlankPage4.ncSettings.setSettings = "IAP";
                                UtilityClass.MessageDialog("Thank You very much for Purchasing. We really appreciate your kind support!", "Thank You very much! :)");
                            }
                        }
                        catch (Exception)
                        {
                            UtilityClass.MessageDialog("An Error Occured, Please Try Again", "Error");
                        }
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception)
            {
                UtilityClass.MessageDialog("An Error Occured, Please Try Again", "Error");
            }
        }