Пример #1
0
        private static async void Purchase(string productId, Action <PurchaseResults, Exception> completionHandler)
        {
            Exception exception = null;
            string    result    = null;

            try
            {
                result = await CurrentApp.RequestProductPurchaseAsync(productId, true);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (completionHandler != null)
            {
                PurchaseResults purchase = null;
                if (result != null)
                {
                    purchase = new PurchaseResults();
                    //purchase.offerId = result.OfferId;
                    purchase.Status     = ProductPurchaseStatus.Succeeded;
                    purchase.ReceiptXml = result;
                    //purchase.transactionId = result.TransactionId;
                }

                EtceteraWindows.RunOnUnityThread(() => completionHandler(purchase, exception));
            }
        }
Пример #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);
                }
            }
        }
Пример #3
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);
                }
            }
        }
Пример #4
0
        private static async void Purchase(string productId, Action<PurchaseResults, Exception> completionHandler)
        {
            Exception exception = null;
            string result = null;
            try
            {
                result = await CurrentApp.RequestProductPurchaseAsync(productId, true);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (completionHandler != null)
            {
                PurchaseResults purchase = null;
                if (result != null)
                {
                    purchase = new PurchaseResults();
                    //purchase.offerId = result.OfferId;
                    purchase.Status = ProductPurchaseStatus.Succeeded;
                    purchase.ReceiptXml = result;
                    //purchase.transactionId = result.TransactionId;
                }

                EtceteraWindows.RunOnUnityThread(() => completionHandler(purchase, exception));
            }
        }