コード例 #1
0
ファイル: TrialHelper.cs プロジェクト: WoYang/Roamit
        public static async Task TryUpgrade()
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            try
            {
                StorePurchaseResult result = await context.RequestPurchaseAsync(RemoveAdsAndSizeLimit_StoreID);

                Debug.WriteLine($"In app purchase of {RemoveAdsAndSizeLimit_Token} finished with status: {result.Status}");

                CheckIfFullVersion();

#if !DEBUG
                App.Tracker.Send(HitBuilder.CreateCustomEvent("TryUpgrade", "Upgraded", result.Status.ToString()).Build());
#endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"In app purchase of {RemoveAdsAndSizeLimit_Token} failed: {ex.Message}");
#if !DEBUG
                App.Tracker.Send(HitBuilder.CreateCustomEvent("TryUpgrade", "Failed", ex.Message).Build());
#endif
            }
        }
コード例 #2
0
ファイル: StoreHelper.cs プロジェクト: meteorsnows/Roamit
        internal static async Task <StorePurchaseStatus> TryPurchaseConsumable(PurchaseItem item)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            Guid trackingId = Guid.NewGuid();

            try
            {
                StorePurchaseResult result = await context.RequestPurchaseAsync(item.StoreID);

                var fulfillResult = await context.ReportConsumableFulfillmentAsync(item.StoreID, 1, trackingId);

                Debug.WriteLine($"In app purchase of consumable {item.Token} finished with status: Purchase={result.Status}, Fulfill={fulfillResult.Status}");

#if !DEBUG
                App.Tracker.Send(HitBuilder.CreateCustomEvent("TryDonate" + item.Token, "Done", $"Purchase={result.Status}, Fulfill={fulfillResult.Status}").Build());
#endif

                return(result.Status);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"In app purchase of consumable {item.Token} failed: {ex.Message}");
#if !DEBUG
                App.Tracker.Send(HitBuilder.CreateCustomEvent("TryDonate" + item.Token, "Failed", ex.Message).Build());
#endif
                return(StorePurchaseStatus.NotPurchased);
            }
        }
コード例 #3
0
ファイル: DonateView.xaml.cs プロジェクト: mattleibow/CodeHub
 private void reactToPurchaseResult(StorePurchaseResult result)
 {
     if (result.Status == StorePurchaseStatus.Succeeded)
     {
         Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType {
             Message = "Thanks for your donation! I deeply appreciate your contribution to the development of CodeHub",
             Glyph   = "\uED54"
         });
     }
     else if (result.Status == StorePurchaseStatus.AlreadyPurchased)
     {
         Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType
         {
             Message = "It seems you have already made this donation",
             Glyph   = "\uE783"
         });
     }
     else
     {
         Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType
         {
             Message = "There seems to be a problem. Try again later",
             Glyph   = "\uE783"
         });
     }
 }
コード例 #4
0
        private async void PurchaseLicense()
        {
            StoreProductResult productResult = await storeContext.GetStoreProductForCurrentAppAsync();

            if (productResult.ExtendedError != null)
            {
                // An error has occurred
                return;
            }

            StoreAppLicense appLicense = await storeContext.GetAppLicenseAsync();

            if (appLicense.IsTrial)
            {
                StorePurchaseResult purchaseResult = await productResult.Product.RequestPurchaseAsync();

                if (purchaseResult.Status == StorePurchaseStatus.Succeeded)
                {
                    // Show Gratitude message
                    ThanksForPurchasingDialog dialog = new ThanksForPurchasingDialog();
                    await dialog.ShowAsync();
                }

                await GetLicense();
            }
        }
コード例 #5
0
        private async void reactToPurchaseResult(StorePurchaseResult result)
        {
            if (result.Status == StorePurchaseStatus.Succeeded)
            {
                var messageDialog = new MessageDialog("Thanks for your donation! I deeply appreciate your contribution to the development of CodeHub.");

                messageDialog.Commands.Add(new UICommand("OK"));

                messageDialog.CancelCommandIndex = 0;

                await messageDialog.ShowAsync();
            }
            else if (result.Status == StorePurchaseStatus.AlreadyPurchased)
            {
                var messageDialog = new MessageDialog("It seems you have already made this donation.");

                messageDialog.Commands.Add(new UICommand("OK"));

                messageDialog.CancelCommandIndex = 0;

                await messageDialog.ShowAsync();
            }
            else
            {
                var messageDialog = new MessageDialog("There seems to be a problem. Try again later.");

                messageDialog.Commands.Add(new UICommand("OK"));

                messageDialog.CancelCommandIndex = 0;

                await messageDialog.ShowAsync();
            }
        }
コード例 #6
0
ファイル: DonateView.xaml.cs プロジェクト: xiangsxuan/CodeHub
        private void ReactToPurchaseResult(StorePurchaseResult result)
        {
            if (result.Status == StorePurchaseStatus.Succeeded)
            {
                Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType {
                    Message = "Thanks for your donation! I deeply appreciate your contribution to the development of CodeHub",
                    Glyph   = "\uED54"
                });

                SettingsService.Save <bool>(SettingsKeys.IsAdsEnabled, false);
                GlobalHelper.HasAlreadyDonated = true;
                Messenger.Default.Send(new GlobalHelper.AdsEnabledMessageType());
            }
            else if (result.Status == StorePurchaseStatus.AlreadyPurchased)
            {
                Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType
                {
                    Message = "It seems you have already made this donation",
                    Glyph   = "\uE783"
                });
            }
            else
            {
                Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType
                {
                    Message = "There seems to be a problem. Try again later",
                    Glyph   = "\uE783"
                });
            }
        }
コード例 #7
0
        private async void Purchase_Click(object sender, RoutedEventArgs e)
        {
            var item = (ItemDetails)ProductsListView.SelectedItem;
            StorePurchaseResult result = await storeContext.RequestPurchaseAsync(item.StoreId);

            var loader = new Windows.ApplicationModel.Resources.ResourceLoader();

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                Result.Text = loader.GetString("PurchaseStatusAlreadyPurchased");
                break;

            case StorePurchaseStatus.Succeeded:
                Result.Text = loader.GetString("PurchaseStatusSucceeded") + " " + item.Title + " !";
                break;

            case StorePurchaseStatus.NotPurchased:
                Result.Text = loader.GetString("PurchaseStatusNotPurchased");
                break;

            case StorePurchaseStatus.NetworkError:
                Result.Text = loader.GetString("PurchaseStatusNetworkError");
                break;

            case StorePurchaseStatus.ServerError:
                Result.Text = loader.GetString("PurchaseStatusServerError");
                break;

            default:
                Result.Text = loader.GetString("PurchaseStatusUnknownError");
                break;
            }
        }
コード例 #8
0
        private async Task <StorePurchaseResult> PurchaseAddOn(string InAppOfferToken)
        {
            string[] filterList = new string[] { "Durable" };

            if (UtilityData.addOnCollection == null || UtilityData.addOnCollection.ExtendedError != null)
            {
                UtilityData.addOnCollection = await storeContext.GetUserCollectionAsync(filterList);
            }

            var isPurchasedList = UtilityData.addOnCollection.Products.Values.Where(p => p.InAppOfferToken.Equals(InAppOfferToken)).ToList();

            if (isPurchasedList.Count == 0)
            {
                if (UtilityData.addOnsAssociatedStoreProducts == null)
                {
                    UtilityData.addOnsAssociatedStoreProducts = await storeContext.GetAssociatedStoreProductsAsync(filterList);
                }

                var AddOnList = UtilityData.addOnsAssociatedStoreProducts.Products.Values.Where(p => p.InAppOfferToken.Equals(InAppOfferToken)).ToList();

                StorePurchaseResult result = await storeContext.RequestPurchaseAsync(AddOnList[0].StoreId);

                return(result);
            }
            return(null);
        }
コード例 #9
0
ファイル: DonateView.xaml.cs プロジェクト: mattleibow/CodeHub
        private async void fourth_tier_Tapped(object sender, TappedRoutedEventArgs e)
        {
            ViewModel.isLoading = true;
            StorePurchaseResult result = await WindowsStore.RequestPurchaseAsync(donateFourthAddOnId);

            ViewModel.isLoading = false;
            reactToPurchaseResult(result);
        }
コード例 #10
0
        /// <summary>
        /// Invoked when the user asks purchase the app.
        /// </summary>
        private async void PurchaseFullLicense()
        {
            // Get app store product details
            StoreProductResult productResult = await storeContext.GetStoreProductForCurrentAppAsync();

            if (productResult.ExtendedError != null)
            {
                // The user may be offline or there might be some other server failure
                rootPage.NotifyUser($"ExtendedError: {productResult.ExtendedError.Message}", NotifyType.ErrorMessage);
                return;
            }

            rootPage.NotifyUser("Buying the full license...", NotifyType.StatusMessage);
            StoreAppLicense license = await storeContext.GetAppLicenseAsync();

            if (license.IsTrial)
            {
                StorePurchaseResult result = await productResult.Product.RequestPurchaseAsync();

                if (result.ExtendedError != null)
                {
                    rootPage.NotifyUser($"Purchase failed: ExtendedError: {result.ExtendedError.Message}", NotifyType.ErrorMessage);
                    return;
                }

                switch (result.Status)
                {
                case StorePurchaseStatus.AlreadyPurchased:
                    rootPage.NotifyUser($"You already bought this app and have a fully-licensed version.", NotifyType.ErrorMessage);
                    break;

                case StorePurchaseStatus.Succeeded:
                    // License will refresh automatically using the StoreContext.OfflineLicensesChanged event
                    break;

                case StorePurchaseStatus.NotPurchased:
                    rootPage.NotifyUser("Product was not purchased, it may have been canceled.", NotifyType.ErrorMessage);
                    break;

                case StorePurchaseStatus.NetworkError:
                    rootPage.NotifyUser("Product was not purchased due to a Network Error.", NotifyType.ErrorMessage);
                    break;

                case StorePurchaseStatus.ServerError:
                    rootPage.NotifyUser("Product was not purchased due to a Server Error.", NotifyType.ErrorMessage);
                    break;

                default:
                    rootPage.NotifyUser("Product was not purchased due to an Unknown Error.", NotifyType.ErrorMessage);
                    break;
                }
            }
            else
            {
                rootPage.NotifyUser("You already bought this app and have a fully-licensed version.", NotifyType.ErrorMessage);
            }
        }
コード例 #11
0
        private async void ProductsListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            ItemDetails Item = (ItemDetails)e.ClickedItem;

            if (context == null)
            {
                context = StoreContext.GetDefault();
                // If your app is a desktop app that uses the Desktop Bridge, you
                // may need additional code to configure the StoreContext object.
                // For more info, see https://aka.ms/storecontext-for-desktop.
            }

            StorePurchaseResult result = await context.RequestPurchaseAsync(Item.StoreId);

            // Capture the error message for the operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            MessageDialog dialog = new MessageDialog("");

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                dialog.Content = "The user has already purchased the product.";
                break;

            case StorePurchaseStatus.Succeeded:
                dialog.Content = "The purchase was successful.";
                break;

            case StorePurchaseStatus.NotPurchased:
                dialog.Content = "The purchase did not complete. " +
                                 "The user may have cancelled the purchase. ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.NetworkError:
                dialog.Content = "The purchase was unsuccessful due to a network error. " +
                                 "ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.ServerError:
                dialog.Content = "The purchase was unsuccessful due to a server error. " +
                                 "ExtendedError: " + extendedError;
                break;

            default:
                dialog.Content = "The purchase was unsuccessful due to an unknown error. " +
                                 "ExtendedError: " + extendedError;
                break;
            }
            await dialog.ShowAsync();
        }
コード例 #12
0
        //This came from some sort of Microsoft Tutorial
        public async void PurchaseAddOn(string storeId)
        {
            try
            {
                if (context == null)
                {
                    context = StoreContext.GetDefault();
                }

                workingProgressRing.IsActive = true;
                StorePurchaseResult result = await context.RequestPurchaseAsync(storeId);

                workingProgressRing.IsActive = false;



                switch (result.Status)
                {
                case StorePurchaseStatus.AlreadyPurchased:
                    storeResult.Text       = "The user has already purchased the product.";
                    storeResult.Visibility = Visibility.Visible;
                    break;

                case StorePurchaseStatus.Succeeded:
                    //storeResult.Text = "The purchase was successful.";
                    ManyThanks.Text       = "Many Thanks!";
                    ManyThanks.Visibility = Visibility.Visible;
                    break;

                case StorePurchaseStatus.NotPurchased:
                    storeResult.Text       = "The user cancelled the purchase.";
                    storeResult.Visibility = Visibility.Visible;
                    break;

                case StorePurchaseStatus.NetworkError:
                    storeResult.Text       = "The purchase was unsuccessful due to a network error.";
                    storeResult.Visibility = Visibility.Visible;
                    break;

                case StorePurchaseStatus.ServerError:
                    storeResult.Visibility = Visibility.Visible;
                    storeResult.Text       = "The purchase was unsuccessful due to a server error.";
                    break;

                default:
                    storeResult.Text       = "The purchase was unsuccessful due to an unknown error.";
                    storeResult.Visibility = Visibility.Visible;
                    break;
                }
            }
            catch (Exception ex)
            {
                storeResult.Text       = "The purchase was unsuccessful due to an unknown error.";
                storeResult.Visibility = Visibility.Visible;
            }
        }
コード例 #13
0
ファイル: SetPage.xaml.cs プロジェクト: IchenDEV/MinesweeperS
        public async void PurchaseAddOn(string storeId)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
                // If your app is a desktop app that uses the Desktop Bridge, you
                // may need additional code to configure the StoreContext object.
                // For more info, see https://aka.ms/storecontext-for-desktop.
            }

            workingProgressRing.IsActive = true;
            StorePurchaseResult result = await context.RequestPurchaseAsync(storeId);

            workingProgressRing.IsActive = false;

            // Capture the error message for the operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                // textBlock.Text = "The user has already purchased the product.";
                ConsumeAddOn("9P44R6NSLH1P");
                break;

            case StorePurchaseStatus.Succeeded:
                //  textBlock.Text = "The purchase was successful.";
                ConsumeAddOn("9P44R6NSLH1P");
                break;

            case StorePurchaseStatus.NotPurchased:
                //    textBlock.Text = "The purchase did not complete. " +
                //  "The user may have cancelled the purchase. ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.NetworkError:
                //   textBlock.Text = "The purchase was unsuccessful due to a network error. " +
                //    "ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.ServerError:
                //   textBlock.Text = "The purchase was unsuccessful due to a server error. " +
                //      "ExtendedError: " + extendedError;
                break;

            default:
                //   textBlock.Text = "The purchase was unsuccessful due to an unknown error. " +
                //      "ExtendedError: " + extendedError;
                break;
            }
        }
コード例 #14
0
        //购买订阅产品的结果。
        private async Task PromptUserToPurchaseAsync()
        {
            //请求购买订阅产品。如果有试用期,将提供试用期。
            //给客户。否则,将提供非审判SKU。
            StorePurchaseResult result = await subscriptionStoreProduct.RequestPurchaseAsync();

            // 捕获错误消息的操作,如果任何国家。
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
                //错误代码
            }
            switch (result.Status)
            {
            case StorePurchaseStatus.Succeeded:
                //显示一个UI来确认客户已经购买了您的订阅
                //并解锁订阅的特性。
                Loading.IsActive = false;
                var SuccessSubscript = resourceMap.GetValue("SuccessSubscript", resourceContext);
                var messageDig1      = new MessageDialog(SuccessSubscript.ValueAsString);
                //展示窗口,获取按钮是否退出  
                var result1 = await messageDig1.ShowAsync();

                break;

            case StorePurchaseStatus.NotPurchased:
                Loading.IsActive = false;
                var CancelSubscript = resourceMap.GetValue("CancelSubscript", resourceContext);
                var messageDig2     = new MessageDialog(CancelSubscript.ValueAsString);
                //展示窗口,获取按钮是否退出  
                var result2 = await messageDig2.ShowAsync();

                break;

            case StorePurchaseStatus.ServerError:
            case StorePurchaseStatus.NetworkError:
                Loading.IsActive = false;
                var NetErrorSubFail = resourceMap.GetValue("NetErrorSubFail", resourceContext);
                var messageDig3     = new MessageDialog(NetErrorSubFail.ValueAsString);
                //展示窗口,获取按钮是否退出  
                var result3 = await messageDig3.ShowAsync();

                break;

            case StorePurchaseStatus.AlreadyPurchased:
                Loading.IsActive = false;
                var AlreadySubscript = resourceMap.GetValue("AlreadySubscript", resourceContext);
                var messageDig4      = new MessageDialog(AlreadySubscript.ValueAsString);
                //展示窗口,获取按钮是否退出  
                var result4 = await messageDig4.ShowAsync();

                break;
            }
        }
コード例 #15
0
        private static async Task <bool> PurchaseAddOn(string storeId)
        {
            bool         success = false;
            StoreContext store   = StoreContext.GetDefault();

            StorePurchaseResult result = await store.RequestPurchaseAsync(storeId);

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
            {
                Debug.WriteLine("LicenseHelper - AddOn already purchased. :D StoreId = " + storeId);
                MessageHelper.ShowIapAlreadyBoughtMessage();
                break;
            }

            case StorePurchaseStatus.Succeeded:
            {
                Debug.WriteLine("LicenseHelper - AddOn purchased. :) You are awesome! StoreId = " + storeId);
                success = true;
                MessageHelper.ShowIapAcquisitionSuccessfulMessage();
                break;
            }

            case StorePurchaseStatus.NotPurchased:
            {
                Debug.WriteLine("LicenseHelper - AddOn NOT purchased. :( StoreId = " + storeId);
                MessageHelper.ShowIapAcquisitionFailedMessage();
                break;
            }

            case StorePurchaseStatus.NetworkError:
            {
                Debug.WriteLine("LicenseHelper - Network Error. :/ StoreId = " + storeId);
                MessageHelper.ShowIapAcquisitionFailedMessage();
                break;
            }

            case StorePurchaseStatus.ServerError:
            {
                Debug.WriteLine("LicenseHelper - Server Error. :/ StoreId = " + storeId);
                MessageHelper.ShowIapAcquisitionFailedMessage();
                break;
            }

            default:
            {
                Debug.WriteLine("LicenseHelper - Unknown Error. :/ StoreId = " + storeId);
                MessageHelper.ShowIapAcquisitionFailedMessage();
                break;
            }
            }

            return(success);
        }
コード例 #16
0
        public async void PurchaseAddOn(int storeId)
        {
            purch = new Constants().storeIdArray.ToList();
            foreach (string s in purch)
            {
                Debug.WriteLine(s);
            }
            if (context == null)
            {
                context = StoreContext.GetDefault();
                // If your app is a desktop app that uses the Desktop Bridge, you
                // may need additional code to configure the StoreContext object.
                // For more info, see https://aka.ms/storecontext-for-desktop.
            }
            StorePurchaseResult result = await context.RequestPurchaseAsync(purch[storeId]);

            // Capture the error message for the operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                Debug.WriteLine("The user has already purchased the product. Try again later.");
                break;

            case StorePurchaseStatus.Succeeded:
                Debug.WriteLine("The purchase was successful.");
                break;

            case StorePurchaseStatus.NotPurchased:
                Debug.WriteLine("The purchase did not complete. " +
                                "The user may have cancelled the purchase. ExtendedError: " + extendedError);
                break;

            case StorePurchaseStatus.NetworkError:
                Debug.WriteLine("The purchase was unsuccessful due to a network error. " +
                                "ExtendedError: " + extendedError);
                break;

            case StorePurchaseStatus.ServerError:
                Debug.WriteLine("The purchase was unsuccessful due to a server error. " +
                                "ExtendedError: " + extendedError);
                break;

            default:
                Debug.WriteLine("The purchase was unsuccessful due to an unknown error. " +
                                "ExtendedError: " + extendedError);
                break;
            }
        }
コード例 #17
0
        public static async Task <PurchasAddOnReturn> PurchaseAddOnAsync(StoreContext context, string storeId)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StorePurchaseResult result = await context.RequestPurchaseAsync(storeId);

            // Capture the error message for the operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            PurchasAddOnReturn resultToReturn = default(PurchasAddOnReturn);

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                System.Diagnostics.Debug.WriteLine("The user has already purchased the product.");
                resultToReturn = PurchasAddOnReturn.Successful;
                break;

            case StorePurchaseStatus.Succeeded:
                System.Diagnostics.Debug.WriteLine("The purchase was successful.");
                resultToReturn = PurchasAddOnReturn.Successful;
                break;

            case StorePurchaseStatus.NotPurchased:
                System.Diagnostics.Debug.WriteLine("The purchase did not complete. " + "The user may have cancelled the purchase. ExtendedError: " + extendedError);
                resultToReturn = PurchasAddOnReturn.Unknown;
                break;

            case StorePurchaseStatus.NetworkError:
                System.Diagnostics.Debug.WriteLine("The purchase was unsuccessful due to a network error. " + "ExtendedError: " + extendedError);
                resultToReturn = PurchasAddOnReturn.Failed;
                break;

            case StorePurchaseStatus.ServerError:
                System.Diagnostics.Debug.WriteLine("The purchase was unsuccessful due to a server error. " + "ExtendedError: " + extendedError);
                resultToReturn = PurchasAddOnReturn.Failed;
                break;

            default:
                System.Diagnostics.Debug.WriteLine("The purchase was unsuccessful due to an unknown error. " + "ExtendedError: " + extendedError);
                resultToReturn = PurchasAddOnReturn.Failed;
                break;
            }

            return(resultToReturn);
        }
コード例 #18
0
ファイル: TargetedOffers.cs プロジェクト: bz-a/windows-uwp
        //</GetTargetedOffers>

        private async Task PurchaseOfferAsync(string productId)
        {
            if (string.IsNullOrEmpty(productId))
            {
                System.Diagnostics.Debug.WriteLine("Product ID is null or empty.");
                return;
            }

            // Purchase the add-on for the current user. Typically, a game or app would first show
            // a UI that prompts the user to buy the add-on; for simplicity, this example
            // simply purchases the add-on.
            StorePurchaseResult result = await storeContext.RequestPurchaseAsync(productId);

            // Capture the error message for the purchase operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                System.Diagnostics.Debug.WriteLine("The user has already purchased the product.");
                break;

            case StorePurchaseStatus.Succeeded:
                System.Diagnostics.Debug.WriteLine("The purchase was successful.");
                break;

            case StorePurchaseStatus.NotPurchased:
                System.Diagnostics.Debug.WriteLine("The purchase did not complete. " +
                                                   "The user may have cancelled the purchase. ExtendedError: " + extendedError);
                break;

            case StorePurchaseStatus.NetworkError:
                System.Diagnostics.Debug.WriteLine("The purchase was unsuccessful due to a network error. " +
                                                   "ExtendedError: " + extendedError);
                break;

            case StorePurchaseStatus.ServerError:
                System.Diagnostics.Debug.WriteLine("The purchase was unsuccessful due to a server error. " +
                                                   "ExtendedError: " + extendedError);
                break;

            default:
                System.Diagnostics.Debug.WriteLine("The purchase was unsuccessful due to an unknown error. " +
                                                   "ExtendedError: " + extendedError);
                break;
            }
        }
コード例 #19
0
        //购买订阅产品的结果。
        private async Task PromptUserToPurchaseAsync()
        {
            //请求购买订阅产品。如果有试用期,将提供试用期。
            //给客户。否则,将提供非审判SKU。
            StorePurchaseResult result = await subscriptionStoreProduct.RequestPurchaseAsync();

            // 捕获错误消息的操作,如果任何国家。
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
                //错误代码
            }
            switch (result.Status)
            {
            case StorePurchaseStatus.Succeeded:
                //显示一个UI来确认客户已经购买了您的订阅
                //并解锁订阅的特性。
                Loading.IsActive = false;
                var messageDig1 = new MessageDialog("您已成功订阅此服务一个月!");
                //展示窗口,获取按钮是否退出  
                var result1 = await messageDig1.ShowAsync();

                break;

            case StorePurchaseStatus.NotPurchased:
                Loading.IsActive = false;
                var messageDig2 = new MessageDialog("购买没有完成。可能已经取消了购买。");
                //展示窗口,获取按钮是否退出  
                var result2 = await messageDig2.ShowAsync();

                break;

            case StorePurchaseStatus.ServerError:
            case StorePurchaseStatus.NetworkError:
                Loading.IsActive = false;
                var messageDig3 = new MessageDialog("由于服务器或网络错误,购买不成功。");
                //展示窗口,获取按钮是否退出  
                var result3 = await messageDig3.ShowAsync();

                break;

            case StorePurchaseStatus.AlreadyPurchased:
                Loading.IsActive = false;
                var messageDig4 = new MessageDialog("已经拥有此订阅。");
                //展示窗口,获取按钮是否退出  
                var result4 = await messageDig4.ShowAsync();

                break;
            }
        }
コード例 #20
0
        public async override Task <InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, string payload, IInAppBillingVerifyPurchase verifyPurchase = null)
        {
            string mspid = await GetMSProductIDForPID(productId);

            if (mspid == null)
            {
                throw new InAppBillingPurchaseException(PurchaseError.InvalidProduct);
            }


            StorePurchaseResult result = await storeContext.RequestPurchaseAsync(mspid);

            if (result.ExtendedError != null)
            {
                Debug.WriteLine("Extended Error:" + result.ExtendedError.ToString() + " Result: " + result.Status.ToString());
                throw new InAppBillingPurchaseException(PurchaseError.GeneralError, result.ExtendedError);
            }
            else
            {
                switch (result.Status)
                {
                case StorePurchaseStatus.AlreadyPurchased:
                    throw new InAppBillingPurchaseException(PurchaseError.AlreadyOwned);

                case StorePurchaseStatus.Succeeded:
                    var purchase = new InAppBillingPurchase()
                    {
                        Id            = productId,
                        ProductId     = productId,
                        AutoRenewing  = false,                                // Not supported by UWP yet
                        State         = PurchaseState.Purchased,
                        PurchaseToken = productId
                    };
                    return(purchase);

                case StorePurchaseStatus.NotPurchased:
                    throw new InAppBillingPurchaseException(PurchaseError.UserCancelled);

                case StorePurchaseStatus.NetworkError:
                    throw new InAppBillingPurchaseException(PurchaseError.ServiceUnavailable);

                case StorePurchaseStatus.ServerError:
                    throw new InAppBillingPurchaseException(PurchaseError.GeneralError);

                default:
                    Debug.WriteLine("Product was not purchased due to an unknown error.");
                    throw new InAppBillingPurchaseException(PurchaseError.GeneralError);
                }
            }
            return(null);
        }
        // Purchase the collection from the store.
        private async void PurchaseButton_Click(object sender, RoutedEventArgs e)
        {
            if (_Context == null)
            {
                _Context = StoreContext.GetDefault();
            }

            workingProgressRing.IsActive = true;
            StorePurchaseResult result = await _Context.RequestPurchaseAsync(_StoreId);

            workingProgressRing.IsActive = false;

            if (result.ExtendedError != null)
            {
                // The user may be offline or there might be some other server failure.
                Debug.WriteLine($"ExtendedError: {result.ExtendedError.Message}");
                errorText.Text = result.ExtendedError.Message;
                return;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                Debug.WriteLine("The user has already purchased the product.");
                break;

            case StorePurchaseStatus.Succeeded:
                Debug.WriteLine("The purchase was successful.");
                ShowAddOn();
                break;

            case StorePurchaseStatus.NotPurchased:
                Debug.WriteLine("The user cancelled the purchase.");
                break;

            case StorePurchaseStatus.NetworkError:
                Debug.WriteLine("The purchase was unsuccessful due to a network error.");
                errorText.Text = "The purchase was unsuccessful due to a network error.";
                break;

            case StorePurchaseStatus.ServerError:
                Debug.WriteLine("The purchase was unsuccessful due to a server error.");
                errorText.Text = "The purchase was unsuccessful due to a server error.";
                break;

            default:
                Debug.WriteLine("The purchase was unsuccessful due to an unknown error.");
                errorText.Text = "The purchase was unsuccessful due to an unknown error.";
                break;
            }
        }
コード例 #22
0
        private async void PurchaseAddOn(string storeId)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
                // If your app is a desktop app that uses the Desktop Bridge, you
                // may need additional code to configure the StoreContext object.
                // For more info, see https://aka.ms/storecontext-for-desktop.
            }

            StorePurchaseResult result = await context.RequestPurchaseAsync(storeId);

            // Capture the error message for the operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                tbStatus.Text = "You already donated.";
                break;

            case StorePurchaseStatus.Succeeded:
                tbStatus.Text = "Donation succeeded. Thank you!";
                break;

            case StorePurchaseStatus.NotPurchased:
                tbStatus.Text = "Your purchase did not complete. " +
                                "The user may have cancelled the purchase. ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.NetworkError:
                tbStatus.Text = "The purchase was unsuccessful due to a network error. " +
                                "ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.ServerError:
                tbStatus.Text = "The purchase was unsuccessful due to a server error. " +
                                "ExtendedError: " + extendedError;
                break;

            default:
                tbStatus.Text = "The purchase was unsuccessful due to an unknown error. " +
                                "ExtendedError: " + extendedError;
                break;
            }
        }
コード例 #23
0
        public async static Task PurchaseAddOn(string storeId)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StorePurchaseResult result = await context.RequestPurchaseAsync(storeId);

            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                var settings = ApplicationData.Current.LocalSettings;
                settings.Values["IsPro"] = true;
                await ContentDialogService.Show(new ThanksBuyProContentDialog());

                break;

            case StorePurchaseStatus.Succeeded:
                var settings2 = ApplicationData.Current.LocalSettings;
                settings2.Values["IsPro"] = true;
                StaticContent.IsPro       = true;
                await ContentDialogService.Show(new ThanksBuyProContentDialog());

                break;

            case StorePurchaseStatus.NotPurchased:
                await new MessageDialog($"Произошла ошибка при покупке Music X Pro: {extendedError}", "Покупка Music X Pro").ShowAsync();
                break;

            case StorePurchaseStatus.NetworkError:
                await new MessageDialog($"Невозможно купить Music X Pro из-за проблем с интернет-подключением", "Покупка Music X Pro").ShowAsync();
                break;

            case StorePurchaseStatus.ServerError:
                await new MessageDialog($"Произошла ошибка на серере при покупке Music X Pro: {extendedError}", "Покупка Music X Pro").ShowAsync();
                break;

            default:
                await new MessageDialog($"Произошла неизвестная на сервере при покупке Music X Pro: {extendedError}", "Покупка Music X Pro").ShowAsync();
                break;
            }
        }
コード例 #24
0
        public async void PurchaseAddOn(string storeId)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
                // If your app is a desktop app that uses the Desktop Bridge, you
                // may need additional code to configure the StoreContext object.
                // For more info, see https://aka.ms/storecontext-for-desktop.
            }

            workingProgressRing.IsActive = true;
            StorePurchaseResult result = await context.RequestPurchaseAsync(storeId);

            workingProgressRing.IsActive = false;

            // Capture the error message for the operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.Succeeded:
                textBlock.Text = "感谢赞助";
                break;

            case StorePurchaseStatus.NotPurchased:
                textBlock.Text = "取消赞助" +
                                 "ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.NetworkError:
                textBlock.Text = "网络错误赞助失败" +
                                 "ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.ServerError:
                textBlock.Text = "服务器错误赞助失败" +
                                 "ExtendedError: " + extendedError;
                break;

            default:
                textBlock.Text = "未知错误赞助失败 " +
                                 "ExtendedError: " + extendedError;
                break;
            }
        }
コード例 #25
0
        public async void PurchaseAddOn(string storeId)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StorePurchaseResult result = await context.RequestPurchaseAsync(storeId);

            // Capture the error message for the operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                AdGrid.Visibility = Visibility.Collapsed;
                break;

            case StorePurchaseStatus.Succeeded:
                AdGrid.Visibility = Visibility.Collapsed;
                break;

            case StorePurchaseStatus.NotPurchased:
                //     textBlock.Text = "The purchase did not complete. " +
                //          "The user may have cancelled the purchase. ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.NetworkError:
                //      textBlock.Text = "The purchase was unsuccessful due to a network error. " +
                //          "ExtendedError: " + extendedError;
                break;

            case StorePurchaseStatus.ServerError:
                //      textBlock.Text = "The purchase was unsuccessful due to a server error. " +
                //          "ExtendedError: " + extendedError;
                break;

            default:
                //      textBlock.Text = "The purchase was unsuccessful due to an unknown error. " +
                //          "ExtendedError: " + extendedError;
                break;
            }
        }
コード例 #26
0
        public async void PurchaseAddOn(string addOnStoreId)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StorePurchaseResult result = await context.RequestPurchaseAsync(addOnStoreId);

            // Capture the error message for the operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.Succeeded:
                await SharedLogic.Instance.NotificationManager.ShowMessageAsync("Thanks for the donation! Love you!");

                ConsumeAddOn(addOnStoreId);
                this.Hide();
                SplitViewMenu.SelectPrevious();
                break;

            case StorePurchaseStatus.NetworkError:
                await SharedLogic.Instance.NotificationManager.ShowMessageAsync("The purchase was unsuccessful due to a network error. " +
                                                                                "ExtendedError: " + extendedError);

                break;

            case StorePurchaseStatus.ServerError:
                await SharedLogic.Instance.NotificationManager.ShowMessageAsync("The purchase was unsuccessful due to a server error. " +
                                                                                "ExtendedError: " + extendedError);

                break;

            default:
                await SharedLogic.Instance.NotificationManager.ShowMessageAsync("The purchase was unsuccessful due to an unknown error. " +
                                                                                "ExtendedError: " + extendedError);

                break;
            }
        }
コード例 #27
0
        public async Task <StorePurchaseStatus> PurchaseAsync()
        {
            try
            {
                if (PreLoadTask == null)
                {
                    PreLoadStoreData();
                }

                await PreLoadTask;

                if (ProductResult != null && ProductResult.ExtendedError == null)
                {
                    if (ProductResult.Product != null)
                    {
                        StorePurchaseResult Result = await ProductResult.Product.RequestPurchaseAsync();

                        switch (Result.Status)
                        {
                        case StorePurchaseStatus.AlreadyPurchased:
                        case StorePurchaseStatus.Succeeded:
                        {
                            ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = true;
                            break;
                        }
                        }

                        return(Result.Status);
                    }
                    else
                    {
                        return(StorePurchaseStatus.NetworkError);
                    }
                }
                else
                {
                    return(StorePurchaseStatus.NetworkError);
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, $"{nameof(PurchaseAsync)} threw an exception");
                return(StorePurchaseStatus.NetworkError);
            }
        }
コード例 #28
0
ファイル: MSStoreHelper.cs プロジェクト: qlmgg/RX-Explorer
        public async Task <StorePurchaseStatus> PurchaseAsync()
        {
            try
            {
                await Task.Run(() =>
                {
                    InitLocker.WaitOne();
                });

                StoreProductResult ProductResult = await Store.GetStoreProductForCurrentAppAsync();

                if (ProductResult.ExtendedError == null)
                {
                    if (ProductResult.Product != null)
                    {
                        StorePurchaseResult Result = await ProductResult.Product.RequestPurchaseAsync();

                        switch (Result.Status)
                        {
                        case StorePurchaseStatus.AlreadyPurchased:
                        case StorePurchaseStatus.Succeeded:
                        {
                            ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = true;
                            break;
                        }
                        }

                        return(Result.Status);
                    }
                    else
                    {
                        return(StorePurchaseStatus.NetworkError);
                    }
                }
                else
                {
                    return(StorePurchaseStatus.NetworkError);
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, $"{nameof(PurchaseAsync)} threw an exception");
                return(StorePurchaseStatus.NetworkError);
            }
        }
コード例 #29
0
        private static async Task <bool> PromptUserToPurchaseAsync()
        {
            bool response = false;

            // Request a purchase of the subscription product. If a trial is available it will be offered
            // to the customer. Otherwise, the non-trial SKU will be offered.
            StorePurchaseResult result = await subscriptionStoreProduct.RequestPurchaseAsync();

            // Capture the error message for the operation, if any.
            string extendedError = string.Empty;

            if (result.ExtendedError != null)
            {
                extendedError = result.ExtendedError.Message;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.Succeeded:
                accountType = "starter";
                DateTimeOffset vencimiento = new DateTimeOffset();
                updateCloureAccount(vencimiento);
                response = true;
                break;

            case StorePurchaseStatus.NotPurchased:
                System.Diagnostics.Debug.WriteLine("The purchase did not complete. " +
                                                   "The customer may have cancelled the purchase. ExtendedError: " + extendedError);
                break;

            case StorePurchaseStatus.ServerError:
            case StorePurchaseStatus.NetworkError:
                System.Diagnostics.Debug.WriteLine("The purchase was unsuccessful due to a server or network error. " +
                                                   "ExtendedError: " + extendedError);
                break;

            case StorePurchaseStatus.AlreadyPurchased:
                System.Diagnostics.Debug.WriteLine("The customer already owns this subscription." +
                                                   "ExtendedError: " + extendedError);
                break;
            }

            return(response);
        }
コード例 #30
0
        private async void PurchaseAddOnButton_Click(object sender, RoutedEventArgs e)
        {
            string productStoreId = "";

            StorePurchaseResult result = await storeContext.RequestPurchaseAsync(productStoreId);

            if (result.ExtendedError != null)
            {
                Debug.WriteLine(result.ExtendedError);
                return;
            }

            switch (result.Status)
            {
            case StorePurchaseStatus.AlreadyPurchased:
                break;

            case StorePurchaseStatus.Succeeded:
                break;

            case StorePurchaseStatus.NotPurchased:
                break;

            case StorePurchaseStatus.NetworkError:
                break;

            case StorePurchaseStatus.ServerError:
                break;

            default:
                break;
            }

            var license = await storeContext.GetAppLicenseAsync();

            if (license.AddOnLicenses != null)
            {
                foreach (var licenseItem in license.AddOnLicenses)
                {
                    Debug.WriteLine($"{licenseItem.Key}:{licenseItem.Value.IsActive}:{licenseItem.Value.ExpirationDate.ToLocalTime()}");
                }
            }
        }