Inheritance: IProductListing
コード例 #1
0
    public async static Task RequestPurchaseAsync(Windows.ApplicationModel.Store.ProductListing product)
    {
        var loader = ResourceManager.Loader;

        var owned = LicenseManager.IsActive(product);

        if (owned)
        {
            try { await new Windows.UI.Popups.MessageDialog(loader.GetString("Info/Purchase/Message/AlreadyPurchased/Message"), loader.GetString("Info/Purchase/Message/AlreadyPurchased/Title")).ShowAsync(); } catch { }
        }
        else
        {
            try
            {
                //https://docs.microsoft.com/en-us/answers/questions/3971/windowsapplicationmodelstorecurrentappsimulatorreq.html
                //It always return NotPurchased
                var result = await LicenseManager.RequestPurchaseAsync(product);

                switch (result.Status)
                {
                case Windows.ApplicationModel.Store.ProductPurchaseStatus.Succeeded:
                    try { await(new Windows.UI.Popups.MessageDialog(loader.GetString("Info/Purchase/Message/Purchased/Message"), loader.GetString("Info/Purchase/Message/Purchased/Title"))).ShowAsync(); } catch { }
                    break;

                case Windows.ApplicationModel.Store.ProductPurchaseStatus.AlreadyPurchased:
                    try { await(new Windows.UI.Popups.MessageDialog(loader.GetString("Info/Purchase/Message/AlreadyPurchased/Message"), loader.GetString("Info/Purchase/Message/AlreadyPurchased/Title"))).ShowAsync(); } catch { }
                    break;

                case Windows.ApplicationModel.Store.ProductPurchaseStatus.NotFulfilled:
                    break;

                case Windows.ApplicationModel.Store.ProductPurchaseStatus.NotPurchased:
                    //#if DEBUG
                    //                            await (new Windows.UI.Popups.MessageDialog(loader.GetString("Info/Purchase/Message/Purchased/Message"), loader.GetString("Info/Purchase/Message/Purchased/Title"))).ShowAsync();
                    //#endif
                    return;

                default:
                    break;
                }
            }
            catch
            {
            }
        }
    }
コード例 #2
0
        internal static ProductListing Create(Windows.ApplicationModel.Store.ProductListing productListing)
        {
            var p = new ProductListing
            {
                Description    = productListing.Description,
                FormattedPrice = productListing.FormattedPrice,
                ImageUri       = productListing.ImageUri
            };

            var keywords = productListing.Keywords.ToList();

            p.Keywords    = keywords;
            p.Name        = productListing.Name;
            p.ProductId   = productListing.ProductId;
            p.ProductType = productListing.ProductType;
            p.Tag         = productListing.Tag;

            return(p);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new ProductListing instance based on a populated Windows.ApplicationModel.Store.ProductListing instance
        /// </summary>
        /// <param name="source">A valid Windows.ApplicationModel.Store.ProductListing from the CurrentApp or CurrentAppSimulator class</param>
        /// <returns>A ProductListing instance with all properties copied from the original</returns>
        public static ProductListing Create(Windows.ApplicationModel.Store.ProductListing source)
        {
            var productListing = new ProductListing
            {
                ProductId = source.ProductId,
                Name      = source.Name,

#if WINDOWS_PHONE //Windows Phone-only members
                Description = source.Description,
                ImageUri    = source.ImageUri,
                Keywords    = source.Keywords.ToList(),
                ProductType = source.ProductType,
                Tag         = source.Tag,
#endif
                FormattedPrice = source.FormattedPrice
            };

            return(productListing);
        }
コード例 #4
0
        public override void purchase(java.lang.String idProduct)
        {
            string produto = SilverlightImplementation.toCSharp(idProduct);
               com.codename1.payment.PurchaseCallback pc = (com.codename1.payment.PurchaseCallback)SilverlightImplementation.getPurchaseCallback();
            SilverlightImplementation.dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                try
                {
                    ListingInformation listing = await CurrentApp.LoadListingInformationAsync();
                    product1 = listing.ProductListings[produto];
                    PurchaseResults purchaseResults = await CurrentApp.RequestProductPurchaseAsync(produto);

                    switch (purchaseResults.Status)
                    {
                        case ProductPurchaseStatus.Succeeded:
                            GrantFeatureLocally(produto, purchaseResults.TransactionId);
                            FulfillProduct1(produto, purchaseResults.TransactionId);
                            pc.itemPurchased(idProduct);
                            break;
                        case ProductPurchaseStatus.NotFulfilled:
                            if (!IsLocallyFulfilled(produto, purchaseResults.TransactionId))
                            {
                                GrantFeatureLocally(produto, purchaseResults.TransactionId);
                            }
                            FulfillProduct1(produto, purchaseResults.TransactionId);
                            break;
                        case ProductPurchaseStatus.NotPurchased:
                            pc.itemPurchaseError(idProduct, SilverlightImplementation.toJava("purchase failed"));
                            break;
                    }
                }
                catch (System.Exception e)
                {
                    Debug.WriteLine("Houston, we have a problem: \n\n" + e + "\n\n");
                }
            }).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
        }
コード例 #5
0
        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;
        }
コード例 #6
0
ファイル: Plugin.cs プロジェクト: kungfubozo/WinBridge
        protected static ProductInfo GetProductInfoFromProduct(ProductListing listing)
        {
            ProductInfo productInfo = null;

            if (listing != null)
            {
                productInfo = new ProductInfo();
                productInfo.Name = listing.Name;
                productInfo.Id = listing.ProductId;
                productInfo.Price = listing.FormattedPrice;
            }
            return productInfo;
        }