Ejemplo n.º 1
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.º 2
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));
            }
        }