Inheritance: IListingInformation
Beispiel #1
0
        private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            prods = await CurrentApp.LoadListingInformationAsync();
            products.ItemsSource = prods.ProductListings.Values.Select(x => new { x.Name, Status = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? "Purchased" : x.FormattedPrice, x.ImageUri, x.ProductId, BuyNowButtonVisible = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible });
            progressRing.IsActive = false;

        }
        private static async Task<string> GetListingInfoAsync()
        {
            //Load associated product listings
            try
            {
                mListingInformation = await CurrentApp.LoadListingInformationAsync();
            }
            catch (Exception e)
            {
                return e.Message;
                //Debug.Assert(false, "StoreManager::GetListingInfo: " + e.Message + ", " + e.StackTrace);
            }

            return "";
        }
Beispiel #3
0
        public static ListingInformation Create(Windows.ApplicationModel.Store.ListingInformation source)
        {
            var listingInformation = new ListingInformation()
            {
#if !WINDOWS_PHONE //Not supported on WP8
                AgeRating     = source.AgeRating,
                CurrentMarket = source.CurrentMarket,
#else
                /*
                 * On Windows Phone 8, the CurrentRegion set for your phone dictates which market a user will
                 * have access to. See: http://stackoverflow.com/questions/14141404/how-to-get-the-currency-of-an-in-app-purchase-product-on-windows-phone-8
                 */
                CurrentMarket = System.Globalization.RegionInfo.CurrentRegion.TwoLetterISORegionName,
#endif
                Description     = source.Description,
                FormattedPrice  = source.FormattedPrice,
                Name            = source.Name,
                ProductListings = source.ProductListings.ToDictionary(key => key.Key, value => ProductListing.Create(value.Value))
            };


            return(listingInformation);
        }
		private async Task GetInformationFromStore()
		{
			try
			{
				_listings = await CurrentApp.LoadListingInformationAsync();
			}
			catch( Exception ex )
			{
				throw;
			}
		    if (_listings.ProductListings != null)
		    {
		        foreach (var productListing in _listings.ProductListings.Values)
		        {
		            int price = 0;

		            if (int.TryParse(productListing.Tag, out price))
		            {
		                _priceToListing.Add(((double) price)/100, productListing);
		            }
		        }
		    }
		}
        public async Task<InAppPurchaseHelper> Setup()
        {
            // license
            if (Simulate)
            {
#if DEBUG
                await SetupSimulation();
                m_License = CurrentAppSimulator.LicenseInformation;
                m_Listing = await CurrentAppSimulator.LoadListingInformationAsync();
                CanPurchase = true;
#endif
            }
            else
            {
                try
                {
                    m_License = CurrentApp.LicenseInformation;
                    m_Listing = await CurrentApp.LoadListingInformationAsync();
                    CanPurchase = true;
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("Setup/License [{0}, {1}, {2}]", this.Key, this.Simulate, e.Message));
                    CanPurchase = false;
                }
            }

            if (!CanPurchase)
                return this; // :(

            try
            {
                // test setup
                m_License.LicenseChanged += () => { RaiseLicenseChanged(IsPurchased); };
                IReadOnlyDictionary<string, ProductLicense> _Licenses = m_License.ProductLicenses;
                if (!_Licenses.Any(x => x.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase)))
                    throw new KeyNotFoundException(Key);

                IReadOnlyDictionary<string, ProductListing> _Products = m_Listing.ProductListings;
                if (!_Products.Any(x => x.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase)))
                    throw new KeyNotFoundException(Key);

                // product
                m_Product = _Products[Key];
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Setup/Tests [{0}, {1}, {2}]", this.Key, this.Simulate, e.Message));
                CanPurchase = false;
            }
            return this;
        }
Beispiel #6
0
        /// <summary>   Loads Windows Store IAP informations. </summary>
        public async void LoadListingInfo()
        {
            StoreEvents.GetInstance().PostMarketItemsRefreshStartedEvent();
            try
            {
                if (StoreConfig.STORE_TEST_MODE)
                {
                    listingInfosMock = await MockStore.CurrentApp.LoadListingInformationAsync();

                    marketProductInfos.Clear();
                    if (listingInfosMock.ProductListings.Count > 0)
                    {
                        foreach (KeyValuePair <string, MockStore.ProductListing> pair in listingInfosMock.ProductListings)
                        {
                            MarketProductInfos marketProduct = new MarketProductInfos();
                            marketProduct.Name           = pair.Value.Name;
                            marketProduct.Description    = pair.Value.Description;
                            marketProduct.FormattedPrice = pair.Value.FormattedPrice;
                            marketProduct.ImageUri       = pair.Value.ImageUri;
                            marketProduct.Keywords       = pair.Value.Keywords;
                            marketProduct.ProductId      = pair.Value.ProductId;

                            switch (pair.Value.ProductType)
                            {
                            case Windows.ApplicationModel.Store.ProductType.Consumable:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.CONSUMABLE;
                                break;

                            case Windows.ApplicationModel.Store.ProductType.Durable:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.DURABLE;
                                break;

                            case Windows.ApplicationModel.Store.ProductType.Unknown:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.UNKNOWN;
                                break;
                            }
                            marketProduct.Tag = pair.Value.Tag;
                            marketProductInfos.Add(pair.Key, marketProduct);
                        }
                    }
                }
                else
                {
                    listingInfos = await Store.CurrentApp.LoadListingInformationAsync();

                    IReadOnlyDictionary <string, Store.ProductListing> productListing;
                    productListing = listingInfos.ProductListings;

                    marketProductInfos.Clear();
                    if (productListing.Count > 0)
                    {
                        foreach (KeyValuePair <string, Store.ProductListing> pair in listingInfos.ProductListings)
                        {
                            MarketProductInfos marketProduct = new MarketProductInfos();
                            marketProduct.Name           = pair.Value.Name;
                            marketProduct.Description    = pair.Value.Description;
                            marketProduct.FormattedPrice = pair.Value.FormattedPrice;
                            marketProduct.ImageUri       = pair.Value.ImageUri;
                            marketProduct.Keywords       = pair.Value.Keywords;
                            marketProduct.ProductId      = pair.Value.ProductId;

                            switch (pair.Value.ProductType)
                            {
                            case Windows.ApplicationModel.Store.ProductType.Consumable:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.CONSUMABLE;
                                break;

                            case Windows.ApplicationModel.Store.ProductType.Durable:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.DURABLE;
                                break;

                            case Windows.ApplicationModel.Store.ProductType.Unknown:
                                marketProduct.ProductType = MarketProductInfos.MarketProductType.UNKNOWN;
                                break;
                            }
                            marketProduct.Tag = pair.Value.Tag;
                            marketProductInfos.Add(pair.Key, marketProduct);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SoomlaUtils.LogDebug(TAG, e.Message);
            }

            OnListingLoadedCB(marketProductInfos);
        }
Beispiel #7
0
        /// <summary>   Loads Windows Store IAP informations. </summary>
        public async void LoadListingInfo()
        {
            StoreEvents.GetInstance().PostMarketItemsRefreshStartedEvent();
            try
            {

                
                if (StoreConfig.STORE_TEST_MODE)
                {
                    listingInfosMock = await MockStore.CurrentApp.LoadListingInformationAsync();

                    marketProductInfos.Clear();
                    if (listingInfosMock.ProductListings.Count > 0)
                    {
                        foreach (KeyValuePair<string, MockStore.ProductListing> pair in listingInfosMock.ProductListings)
                        {
                            MarketProductInfos marketProduct = new MarketProductInfos();
                            marketProduct.Name = pair.Value.Name;
                            marketProduct.Description = pair.Value.Description;
                            marketProduct.FormattedPrice = pair.Value.FormattedPrice;
                            marketProduct.ImageUri = pair.Value.ImageUri;
                            marketProduct.Keywords = pair.Value.Keywords;
                            marketProduct.ProductId = pair.Value.ProductId;

                            switch (pair.Value.ProductType)
                            {
                                case Windows.ApplicationModel.Store.ProductType.Consumable:
                                    marketProduct.ProductType = MarketProductInfos.MarketProductType.CONSUMABLE;
                                    break;
                                case Windows.ApplicationModel.Store.ProductType.Durable:
                                    marketProduct.ProductType = MarketProductInfos.MarketProductType.DURABLE;
                                    break;
                                case Windows.ApplicationModel.Store.ProductType.Unknown:
                                    marketProduct.ProductType = MarketProductInfos.MarketProductType.UNKNOWN;
                                    break;
                            }
                            marketProduct.Tag = pair.Value.Tag;
                            marketProductInfos.Add(pair.Key, marketProduct);
                        }
                    }
                }
                else
                {
                    listingInfos = await Store.CurrentApp.LoadListingInformationAsync();
                    IReadOnlyDictionary<string, Store.ProductListing> productListing;
                    productListing = listingInfos.ProductListings;

                    marketProductInfos.Clear();
                    if (productListing.Count > 0)
                    {
                        foreach (KeyValuePair<string, Store.ProductListing> pair in listingInfos.ProductListings)
                        {
                            MarketProductInfos marketProduct = new MarketProductInfos();
                            marketProduct.Name = pair.Value.Name;
                            marketProduct.Description = pair.Value.Description;
                            marketProduct.FormattedPrice = pair.Value.FormattedPrice;
                            marketProduct.ImageUri = pair.Value.ImageUri;
                            marketProduct.Keywords = pair.Value.Keywords;
                            marketProduct.ProductId = pair.Value.ProductId;

                            switch (pair.Value.ProductType)
                            {
                                case Windows.ApplicationModel.Store.ProductType.Consumable:
                                    marketProduct.ProductType = MarketProductInfos.MarketProductType.CONSUMABLE;
                                    break;
                                case Windows.ApplicationModel.Store.ProductType.Durable:
                                    marketProduct.ProductType = MarketProductInfos.MarketProductType.DURABLE;
                                    break;
                                case Windows.ApplicationModel.Store.ProductType.Unknown:
                                    marketProduct.ProductType = MarketProductInfos.MarketProductType.UNKNOWN;
                                    break;
                            }
                            marketProduct.Tag = pair.Value.Tag;
                            marketProductInfos.Add(pair.Key, marketProduct);
                        }
                    }
                }

            }
            catch (Exception e)
            {
                SoomlaUtils.LogDebug(TAG,e.Message);
            }

            OnListingLoadedCB(marketProductInfos);
        }
			public CurrentApp()
			{
				ListingInformation = new ListingInformation();
				LicenseInformation = new LicenseInformation();
			}
        private async Task LoadInAppPurchaseProxyFileAsync()
        {
            StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
            StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml");
            licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario);
            CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;
            await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

            try
            {
                listing = await CurrentAppSimulator.LoadListingInformationAsync();
            }
            catch (Exception)
            {
                var messageDialog = new MessageDialog("LoadListingInformationAsync API gagal");
                var task = messageDialog.ShowAsync().AsTask();
            }
        }
Beispiel #10
0
        private async void Fulfill(string item, string receipt)
        {
            var t = CurrentApp.LoadListingInformationAsync();
            int v;
            switch (item)
            {
                case IAPs.IAP_AdditionalLogin:
                    products.ItemsSource = null;
                    progressRing.IsActive = true;
                    var prevData = await Storage.LoadAsync<byte[]>(IAPs.IAP_AdditionalLogin);
                    if (prevData == null)
                    {
                        v = 2;
                    }
                    else
                    {
                        var dData = ProtectedData.Unprotect(prevData, null);
                        int value = BitConverter.ToInt32(dData, 0);
                        v = value + 1;
                    }

                    Save(v);
                    using (var c = new HttpClient())
                    {
                        var result = await c.PostAsync("https://wauth.apphb.com/api/AddPayment", new StringContent(JsonConvert.SerializeObject(new PayingUser { Username = (App.Current as App).currentInfo.Username, Count = v }), Encoding.UTF8, "application/json"));
                    }
                    progressRing.IsActive = false;
                    products.ItemsSource = prods.ProductListings.Values.Select(x => new { x.Name, Status = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? "Purchased" : x.FormattedPrice, x.ImageUri, x.ProductId, BuyNowButtonVisible = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible });
                    break;
                case IAPs.IAP_PushNotification:
                    products.ItemsSource = null;
                    progressRing.IsActive = true;
                    var ch = WPUtils.ChannelStartup();
                    SystemTray.SetProgressIndicator(this, new ProgressIndicator { IsVisible = true, Text = AppResources.PushConnect, IsIndeterminate = true });
                    var tsk = WPUtils.UploadCurrentData();

                    while (ch.ConnectionStatus != ChannelConnectionStatus.Connected && ch.ChannelUri == null)
                        await Task.Delay(1000);

                    await WPUtils.PushNotificationSetUp(this);
                    SystemTray.SetProgressIndicator(this, null);

                    progressRing.IsActive = false;
                    products.ItemsSource = prods.ProductListings.Values.Select(x => new { x.Name, Status = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? "Purchased" : x.FormattedPrice, x.ImageUri, x.ProductId, BuyNowButtonVisible = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible });
                    await tsk;
                    break;
                default:
                    break;
            }

            prods = await t;
            var prod = prods.ProductListings.Single(x => x.Value.ProductId == item);

            if (prod.Value.ProductType == ProductType.Consumable)
            {
                CurrentApp.ReportProductFulfillment(item);
            }

        }
Beispiel #11
0
        protected static FullAppInfo GetAppInfoFromListing(ListingInformation listing)
        {
            FullAppInfo appInfo = null;

            if (listing != null)
            {
                appInfo = new FullAppInfo();
                appInfo.Name = listing.Name;
                appInfo.Description = listing.Description;
                appInfo.Market = listing.CurrentMarket;
                appInfo.AgeRating = listing.AgeRating;
                appInfo.Price = listing.FormattedPrice;
            }
            return appInfo;
        }