Ejemplo n.º 1
0
        private static ProductReceipt Create(XElement descendant)
        {
            var receipt     = new ProductReceipt();
            var idAttribute = descendant.Attribute("Id");

            if (idAttribute != null)
            {
                receipt.Id = new Guid(idAttribute.Value);
            }

            var appIdAttribute = descendant.Attribute("AppId");

            if (appIdAttribute != null)
            {
                receipt.AppId = appIdAttribute.Value;
            }

            var productIdAttribute = descendant.Attribute("ProductId");

            if (productIdAttribute != null)
            {
                receipt.ProductId = productIdAttribute.Value;
            }

            var productTypeAttribute = descendant.Attribute("ProductType");

            if (productTypeAttribute != null)
            {
                ProductType type;
                if (Enum.TryParse(productTypeAttribute.Value, out type))
                {
                    receipt.ProductType = type;
                }
            }

            var purchaseDateAttribute = descendant.Attribute("PurchaseDate");

            if (purchaseDateAttribute != null)
            {
                DateTimeOffset date;
                if (DateTimeOffset.TryParse(purchaseDateAttribute.Value, out date))
                {
                    receipt.PurchaseDate = date;
                }
            }
            return(receipt);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Requests a purchase of the application. completionHandler gets called with either true or false indicating if
        ///             the app was purchased.
        ///
        /// </summary>
        public static async void RequestProductPurchase(string productId, Action <PurchaseResults, Exception> onComplete)
        {
            try
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    try
                    {
                        var task = CurrentApp.RequestProductPurchaseAsync(productId).AsTask();

                        await task;

                        if (onComplete != null)
                        {
                            Windows.ApplicationModel.Store.PurchaseResults result = task.Result;
                            PurchaseResults purchase = null;
                            if (result != null)
                            {
                                purchase                = new PurchaseResults();
                                purchase.OfferId        = result.OfferId;
                                purchase.Status         = (ProductPurchaseStatus)result.Status;
                                purchase.ReceiptXml     = result.ReceiptXml;
                                purchase.ProductReceipt = ProductReceipt.CreateReceipt(result.ReceiptXml);
                                purchase.TransactionId  = result.TransactionId;
                            }

                            onComplete(purchase, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (onComplete != null)
                        {
                            onComplete(null, ex);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                if (onComplete != null)
                {
                    onComplete(null, ex);
                }
            }
        }
Ejemplo n.º 3
0
        private static async void LoadProductReceipts(List <string> productIds, Action <List <ProductReceipt>, Exception> onComplete)
        {
            var receipts = new List <ProductReceipt>();

            for (int index = 0; index < productIds.Count; index++)
            {
                var productId = productIds[index];

                if (string.IsNullOrEmpty(productId))
                {
                    continue;
                }

                try
                {
#if DEBUG
                    var task = CurrentApp.GetProductReceiptAsync(productId);
#else
                    var task = CurrentApp.GetProductReceiptAsync(productId).AsTask();
#endif
                    await task;

                    var receiptXml = task.Result;

                    var receipt = ProductReceipt.CreateReceipt(receiptXml);

                    receipts.Add(receipt);
                }
                catch (Exception ex)
                {
                    if (onComplete != null)
                    {
                        EtceteraWindows.RunOnUnityThread(() => onComplete(null, ex));
                    }
                    return;
                }
            }

            if (onComplete != null)
            {
                EtceteraWindows.RunOnUnityThread(() => onComplete(receipts, null));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the product receipt for the given productId.
        ///
        /// </summary>
        /// <param name="productIds"/>
        /// <returns/>
        public static async void GetProductReceipts(List <string> productIds, Action <List <ProductReceipt>, Exception> onComplete)
        {
            try
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    try
                    {
                        var task = CurrentApp.GetAppReceiptAsync().AsTask();

                        await task;

                        if (onComplete != null)
                        {
                            var receiptXml = task.Result;
                            var receipts   = ProductReceipt.CreateReceipts(receiptXml);
                            onComplete(receipts, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (onComplete != null)
                        {
                            onComplete(null, ex);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                if (onComplete != null)
                {
                    onComplete(null, ex);
                }
            }
        }
Ejemplo n.º 5
0
        private static ProductReceipt Create(XElement descendant)
        {
            var receipt = new ProductReceipt();
            var idAttribute = descendant.Attribute("Id");
            if (idAttribute != null)
            {
                receipt.Id = new Guid(idAttribute.Value);
            }

            var appIdAttribute = descendant.Attribute("AppId");
            if (appIdAttribute != null)
            {
                receipt.AppId = appIdAttribute.Value;
            }

            var productIdAttribute = descendant.Attribute("ProductId");
            if (productIdAttribute != null)
            {
                receipt.ProductId = productIdAttribute.Value;
            }

            var productTypeAttribute = descendant.Attribute("ProductType");
            if (productTypeAttribute != null)
            {
                ProductType type;
                if (Enum.TryParse(productTypeAttribute.Value, out type))
                {
                    receipt.ProductType = type;
                }
            }

            var purchaseDateAttribute = descendant.Attribute("PurchaseDate");
            if (purchaseDateAttribute != null)
            {
                DateTimeOffset date;
                if (DateTimeOffset.TryParse(purchaseDateAttribute.Value, out date))
                {
                    receipt.PurchaseDate = date;
                }
            }
            return receipt;
        }