示例#1
0
        public static void RequestAppPurchase(bool requireReceipt, Action <CallbackResponse <string> > OnAppPurchaseFinished)
        {
            string result             = String.Empty;
            bool   didPurchaseSucceed = false;

            Utils.RunOnWindowsUIThread(async() =>
            {
                try
                {
                    if (_isLicenseSimulationOn)
                    {
                        result = await CurrentAppSimulator.RequestAppPurchaseAsync(requireReceipt);
                        if (CurrentAppSimulator.LicenseInformation.IsActive && !CurrentAppSimulator.LicenseInformation.IsTrial)
                        {
                            didPurchaseSucceed = true;
                        }
                    }
                    else
                    {
                        result = await CurrentApp.RequestAppPurchaseAsync(requireReceipt);
                        if (CurrentApp.LicenseInformation.IsActive && !CurrentApp.LicenseInformation.IsTrial)
                        {
                            didPurchaseSucceed = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    DebugLog.Log(LogLevel.Error, "Error purchasing the app " + ex.ToString());
                    Utils.RunOnUnityAppThread(() =>
                    {
                        if (OnAppPurchaseFinished != null)
                        {
                            OnAppPurchaseFinished(
                                new CallbackResponse <string>
                            {
                                Status    = CallbackStatus.Failure,
                                Result    = null,
                                Exception = ex
                            });
                        }
                    });

                    return;
                }

                Utils.RunOnUnityAppThread(() =>
                {
                    if (OnAppPurchaseFinished != null)
                    {
                        OnAppPurchaseFinished(new CallbackResponse <string>
                        {
                            Status    = didPurchaseSucceed ? CallbackStatus.Success : CallbackStatus.Failure,
                            Result    = result,
                            Exception = null
                        });
                    }
                });
            });
        }
示例#2
0
        public async Task <bool> BuyProduct(string FeatureName)
        {
            try
            {
#if DEBUG
                if (licenseInformation.IsTrial)
                {
                    await CurrentAppSimulator.RequestAppPurchaseAsync(false);
                }

                PurchaseResults Result = await CurrentAppSimulator.RequestProductPurchaseAsync(FeatureName);
#else
                PurchaseResults Result = await CurrentApp.RequestProductPurchaseAsync(FeatureName);
#endif

                //Reset status;
                _HasRemoveAds = null;

                //Check the license state to determine if the in-app purchase was successful.
                return(Result.Status == ProductPurchaseStatus.Succeeded || Result.Status == ProductPurchaseStatus.AlreadyPurchased);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        /// <summary>
        /// Invoked when the user asks purchase the app.
        /// </summary>
        private async void PurchaseFullLicense()
        {
            LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;

            rootPage.NotifyUser("Buying the full license...", NotifyType.StatusMessage);
            if (licenseInformation.IsTrial)
            {
                try
                {
                    await CurrentAppSimulator.RequestAppPurchaseAsync(false);

                    if (!licenseInformation.IsTrial && licenseInformation.IsActive)
                    {
                        rootPage.NotifyUser("You successfully upgraded your app to the fully-licensed version.", NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser("You still have a trial license for this app.", NotifyType.ErrorMessage);
                    }
                }
                catch (Exception)
                {
                    rootPage.NotifyUser("The upgrade transaction failed. You still have a trial license for this app.", NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("You already bought this app and have a fully-licensed version.", NotifyType.ErrorMessage);
            }
        }
示例#4
0
        internal async void PurchaseFullLicense()
        {
            MainPageViewModel mainPageVM = ServiceLocator.Current.GetInstance <MainPageViewModel>();

            licenseInformation = CurrentAppSimulator.LicenseInformation;
            if (licenseInformation.IsTrial)
            {
                try
                {
                    await CurrentAppSimulator.RequestAppPurchaseAsync(false);

                    if (!licenseInformation.IsTrial && licenseInformation.IsActive)
                    {
                        mainPageVM.ResumeDownloadAction();
                    }
                    else
                    {
                        mainPageVM.CancelDownloadAction();
                    }
                }
                catch (Exception)
                {
                    mainPageVM.CancelDownloadAction();
                }
            }
        }
示例#5
0
        /// <summary>
        /// Requests purchase of your app if it is in trial mode, returns an xml reciept if successful
        /// </summary>
        /// <param name="response">A callback containing the receipt</param>
        public static void PurchaseApp(Action <string> response)
        {
#if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0)
            if (_isTest)
            {
                UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
                {
                    string result = await CurrentAppSimulator.RequestAppPurchaseAsync(true);

                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        if (response != null)
                        {
                            response(result);
                        }
                    }, true);
                }, true);
            }
            else
            {
                UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
                {
                    string result = await CurrentApp.RequestAppPurchaseAsync(true);

                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        if (response != null)
                        {
                            response(result);
                        }
                    }, true);
                }, true);
            }
#endif
        }
示例#6
0
        public static async Task <Boolean> Purchase()
        {
            try
            {
#if DEBUG
                await CurrentAppSimulator.RequestAppPurchaseAsync(false);
#else
                await CurrentApp.RequestAppPurchaseAsync(false);
#endif
                if (!IsTrial())
                {
                    ResourceLoader _res          = ResourceLoader.GetForCurrentView();
                    MessageDialog  messageDialog = new MessageDialog(_res.GetString("VersionFull"), _res.GetString("ThanksPurchase"));
                    messageDialog.Commands.Add(new UICommand("Ok", (command) => { }));
                    messageDialog.CancelCommandIndex  = 0;
                    messageDialog.DefaultCommandIndex = 0;
                    await messageDialog.ShowAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#7
0
        public async Task PurchaseAppAsync()
        {
            await LoadLicenseData();

            if (IsTrialLicense)
            {
                await CurrentAppSimulator.RequestAppPurchaseAsync(false);
            }
        }
示例#8
0
        public async Task PurchaseAppAsync()
        {
            // TODO: Module 12: Exercise 1: Task 3.1: Implement the PurchaseAppAsync method to purchase the app
            await LoadLicenseData();

            if (IsTrialLicense)
            {
                await CurrentAppSimulator.RequestAppPurchaseAsync(false);
            }
        }
示例#9
0
 private async Task <string> PurchaseApplicationAsync()
 {
     if (_useSimulator)
     {
         return(await CurrentAppSimulator.RequestAppPurchaseAsync(false));
     }
     else
     {
         return(await CurrentApp.RequestAppPurchaseAsync(false));
     }
 }
        public async Task PurchaseApp()
        {
            await LoadLicenses();

            if (!this.IsFull)
            {
                await CurrentAppSimulator.RequestAppPurchaseAsync(false);
            }
            else
            {
                return;
            }
        }
示例#11
0
        internal async static Task SimulatePurchase()
        {
            try
            {
                var result = await CurrentAppSimulator.RequestAppPurchaseAsync(false);

                // Purchased.
            }
            catch (Exception)
            {
                // Purchase failed.
            }

            await Task.CompletedTask;
        }
示例#12
0
        private async void buttonPurchase_Click(object sender, RoutedEventArgs e)
        {
            try
            {
#if DEBUG
                await CurrentAppSimulator.RequestAppPurchaseAsync(false);
#else
                await CurrentApp.RequestAppPurchaseAsync(false);
#endif
            }
            catch
            {
                // Failed to complete the purchase
            }
            // The license information will have been updated by this time.
            // Refresh the page content as appropriate for the new trial state.
            ShowTrialState();
        }
示例#13
0
        private async void TrialButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
#if DEBUG
                await CurrentAppSimulator.RequestAppPurchaseAsync(false);
#else
                await CurrentApp.RequestAppPurchaseAsync(false);
#endif
            }
            catch
            {
                ShowToast(SystemUtil.GetStringResource("ErrorMessage_fatal"));
                return;
            }

            (Application.Current as App).UpdatePurchaseInfo();
            UpdatePurchaseInformation();
        }
        private async void BuyAppButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            if (_licenseInformation.IsTrial)
            {
                try
                {
                    var returnCode = await CurrentAppSimulator.RequestAppPurchaseAsync(false);

                    CheckLicense();
                }
                catch (Exception ex)
                {
                    //Handle failure gracefully
                }
            }
            else
            {
                //Already purchased
            }
        }
示例#15
0
        /// <summary>
        /// Occurs when the purchase button is clicked.
        /// </summary>
        /// <param name="sender">The object where the event handler is attached.</param>
        /// <param name="e">The event data.</param>
        /// <remarks>
        /// TODO: this is not needed anymore, the app is now free of charge.
        /// </remarks>
        private async void purchaseButton_Click(object sender, RoutedEventArgs e)
        {
            bool failed = false;

            try
            {
#if DEBUG
                var s = await CurrentAppSimulator.RequestAppPurchaseAsync(false);
#else
                var s = await CurrentApp.RequestAppPurchaseAsync(false);
#endif
            }
            catch (Exception)
            {
                failed = true;
            }

            if (failed)
            {
                MessageDialog dialog = new MessageDialog("Purchase failed, please try again.");
                await dialog.ShowAsync();
            }
        }
示例#16
0
        public static void TestTrialPurchase()
        {
#pragma warning disable 4014
            CurrentAppSimulator.RequestAppPurchaseAsync(false);
#pragma warning restore 4014
        }
示例#17
0
 async void BuyApp(IUICommand c)
 {
     await CurrentAppSimulator.RequestAppPurchaseAsync(true);
 }
 /// <summary>
 /// Requests the purchase of a full app license.
 /// </summary>
 /// <param name="includeReceipt">Determines if this method should return the receipts for this app.</param>
 /// <returns>
 /// If the includeReceipt parameter is set to true, this string contains XML that represents all receipts for the
 /// app and any in-app purchases. If includeReceipt is set to false, this string is empty.
 /// </returns>
 public static IAsyncOperation <string> RequestAppPurchaseAsync(bool includeReceipt)
 {
     return(IsMockEnabled
         ? CurrentAppSimulator.RequestAppPurchaseAsync(includeReceipt)
         : CurrentApp.RequestAppPurchaseAsync(includeReceipt));
 }
 public static void TestTrialPurchase()
 {
     CurrentAppSimulator.RequestAppPurchaseAsync(false);
 }