コード例 #1
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);
            }
        }
コード例 #2
0
        public static async Task Buy()
        {
            var licenseInformation = await Get();

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

                    await CurrentApp.RequestAppPurchaseAsync(false);

                    if (!licenseInformation.IsTrial && licenseInformation.IsActive)
                    {
                        PurchaseResult = "You successfully upgraded your app to the fully-licensed version.";
                    }
                    else
                    {
                        PurchaseResult = "The purchase could not be completed at this time.";
                    }
                }
                catch (Exception)
                {
                    PurchaseResult = "The purchase could not be completed at this time.";
                }
            }
            else
            {
                PurchaseResult = "You already bought this app and have a fully-licensed version.";
            }
        }
コード例 #3
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
                        });
                    }
                });
            });
        }
コード例 #4
0
ファイル: WSANativeStore.cs プロジェクト: VaibhavDesai/GEARS
        /// <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
        }
コード例 #5
0
        public static async Task <string> RequestAppPurchaseAsync(bool includeReceipt)
        {
#if DEBUG
            return(await CurrentAppSimulator.RequestAppPurchaseAsync(includeReceipt));
#else
            return(await CurrentApp.RequestAppPurchaseAsync(includeReceipt));
#endif
        }
コード例 #6
0
 private async Task <string> PurchaseApplicationAsync()
 {
     if (_useSimulator)
     {
         return(await CurrentAppSimulator.RequestAppPurchaseAsync(false));
     }
     else
     {
         return(await CurrentApp.RequestAppPurchaseAsync(false));
     }
 }
コード例 #7
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();
        }
コード例 #8
0
ファイル: AboutPage.xaml.cs プロジェクト: EternalWind/locana
        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();
        }
コード例 #9
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();
            }
        }
コード例 #10
0
 /// <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));
 }
コード例 #11
0
        /// <summary>
        /// Updates the UI with the licensing information.
        /// </summary>
        /// <param name="possibleException">The possible exception.</param>
        private async void UpdateUIWithLicensingInformation(Exception possibleException = null)
        {
            try
            {
                if (possibleException != null)
                {
                    await new MessageDialog("Unable to contact Lotaris server. Please try again...", "Hello world! Lotaris edition").ShowAsync();
                    return;
                }

                if (CurrentApp.LicenseInformation.IsTrial)
                {
                    LicenseInfoButton.Visibility = Visibility.Collapsed;
                    if (CurrentApp.LicenseInformation.IsActive)
                    {
                        LicenseInformationTextBlock.Text = "Trial license will expire on " + String.Format("{0:ddd, MMM d, yyyy}", CurrentApp.LicenseInformation.ExpirationDate);
                    }
                    else
                    {
                        LicenseInformationTextBlock.Text = "Trial license expired.";
                        MessageDialog msg = new MessageDialog("Your trial license has expired. You must buy a new license.", "Trial expired");
                        msg.Commands.Add(new UICommand("Buy license", async UICommandInvokedHandler =>
                        {
                            try
                            {
                                await CurrentApp.RequestAppPurchaseAsync();

                                if (CurrentApp.LicenseInformation.IsActive)
                                {
                                    await new MessageDialog("Thanks for your purchase.", "Purchase succeeded").ShowAsync();
                                }
                                else
                                {
                                    await new MessageDialog("The license for this application has expired. You must buy a new license to use this app.", "Purchase failed").ShowAsync();

                                    Application.Current.Exit();
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex.GetType() != typeof(UnauthorizedAccessException))
                                {
                                    new MessageDialog("An error occurred, please try again later.", "Error").ShowAsync();
                                }
                            }
                        }));

                        msg.Commands.Add(new UICommand("Exit", UICommandInvokedHandler => Application.Current.Exit()));
                        await msg.ShowAsync();
                    }
                }
                else
                {
                    if (CurrentApp.LicenseInformation.IsActive)
                    {
                        LicenseInformationTextBlock.Text = "Full version";
                        LicenseInfoButton.Visibility     = Visibility.Visible;
                    }
                    else
                    {
                        MessageDialog msg = new MessageDialog("Your license has expired. You must buy a new license.", "License expired");
                        msg.Commands.Add(new UICommand("Buy license", async UICommandInvokedHandler =>
                        {
                            try
                            {
                                await CurrentApp.RequestAppPurchaseAsync();
                                if (CurrentApp.LicenseInformation.IsActive)
                                {
                                    new MessageDialog("Thanks for your purchase.", "Purchase succeeded").ShowAsync();
                                }
                                else
                                {
                                    new MessageDialog("The license for this application has expired. You must buy a new license to use this app.", "Purchase failed").ShowAsync();

                                    Application.Current.Exit();
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex.GetType() != typeof(UnauthorizedAccessException))
                                {
                                    new MessageDialog("An error occurred, please try again later.", "Error").ShowAsync();
                                }
                            }
                        }));

                        msg.Commands.Add(new UICommand("Exit", UICommandInvokedHandler => Application.Current.Exit()));
                        await msg.ShowAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(UnauthorizedAccessException))
                {
                    new MessageDialog("An error occurred, please try again later.", "Error").ShowAsync();
                }
            }
        }
コード例 #12
0
        public async Task <object> PurchaseAppAsync()
        {
            var result = await CurrentApp.RequestAppPurchaseAsync(true);

            return(result);
        }
コード例 #13
0
 protected async Task <string> RequestAppPurchaseAsyncInternal()
 {
     return(await CurrentApp.RequestAppPurchaseAsync(true));
 }