//购买订阅产品的结果。 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; } }
//购买订阅产品的结果。 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; } }
public async void Purchase() { var result = await product.RequestPurchaseAsync(); switch (result.Status) { case StorePurchaseStatus.AlreadyPurchased: case StorePurchaseStatus.Succeeded: IsActive = true; break; default: IsActive = false; break; } }
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); }
/// <summary> /// Prompt for purchase popup /// </summary> /// <param name="sku"></param> /// <returns></returns> private async Task <PurchaseResult> PromptUserToPurchaseAsync(StoreSku sku) { string productId = sku.StoreId; // 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 storeProduct.RequestPurchaseAsync(); // Capture the error message for the operation, if any. string extendedError = string.Empty; if (result.ExtendedError != null) { extendedError = result.ExtendedError.Message; } return(result.Status switch { StorePurchaseStatus.Succeeded => new PurchaseResult() { PurchaseState = PurchaseState.Purchased, Sku = productId }, // Show a UI to acknowledge that the customer has purchased your subscription // and unlock the features of the subscription. StorePurchaseStatus.NotPurchased => new PurchaseResult() { PurchaseState = PurchaseState.Failed, Sku = productId }, StorePurchaseStatus.ServerError => new PurchaseResult() { PurchaseState = PurchaseState.Failed, Sku = productId }, StorePurchaseStatus.NetworkError => new PurchaseResult() { PurchaseState = PurchaseState.Failed, Sku = productId }, StorePurchaseStatus.AlreadyPurchased => new PurchaseResult() { PurchaseState = PurchaseState.Purchased, Sku = productId }, _ => new PurchaseResult() { PurchaseState = PurchaseState.Failed, Sku = productId }, });
public async Task PromptUserToPurchaseAsync() { // 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: Common.fullVersion = true; Common.SetVersion(); 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); Common.fullVersion = true; Common.SetVersion(); break; } }
private async Task PromptUserToPurchaseAdFreeAsync() { // 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: await Helpers.ShowDialog(ResourceStringNames.adFreePurchaseSuccessful.GetResourceString()); break; case StorePurchaseStatus.NotPurchased: await Helpers.ShowDialog(ResourceStringNames.addOnNotPurchasedFormat.GetResourceString().FormatString(extendedError)); break; case StorePurchaseStatus.ServerError: case StorePurchaseStatus.NetworkError: System.Diagnostics.Debug.WriteLine(ResourceStringNames.addOnErrorDuringPurchaseFormat.GetResourceString().FormatString(extendedError)); break; case StorePurchaseStatus.AlreadyPurchased: System.Diagnostics.Debug.WriteLine(ResourceStringNames.addOnAlreadyPurchasedFormat.GetResourceString().FormatString(extendedError)); break; } }
public async void PurchaseSubscription(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. } // First, get the StoreProduct object for the subscription add-on. This example // assumes you already know the Store ID for the add-on and you have passed // it to this method. string[] productKinds = { "Durable" }; List <String> filterList = new List <string>(productKinds); string[] storeIds = new string[] { storeId }; workingProgressRing.IsActive = true; StoreProductQueryResult queryResult = await context.GetStoreProductsAsync(filterList, storeIds); workingProgressRing.IsActive = false; StoreProduct mySubscription = queryResult.Products.FirstOrDefault().Value; // Make sure the user has not already acquired the subscription add-on, then // offer it for purchase to the user. if (!mySubscription.IsInUserCollection) { workingProgressRing.IsActive = true; StorePurchaseResult result = await mySubscription.RequestPurchaseAsync(); 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 = "The purchase was successful."; 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; } } }
public static async Task <bool> OpenStoreRemoveAds() { #if DEBUG if (!LicenseInformation.ProductLicenses["RemoveAds"].IsActive) { try { PurchaseResults results = await CurrentAppSimulator.RequestProductPurchaseAsync("RemoveAds"); if (results.Status == ProductPurchaseStatus.Succeeded || results.Status == ProductPurchaseStatus.AlreadyPurchased) { RemoveAds = true; } } catch (Exception) { // The in-app purchase was not completed because // an error occurred. } } else { RemoveAds = true; } #else var context = StoreContext.GetDefault(); StoreProduct subscriptionStoreProduct = null; StoreProductQueryResult result = await context.GetAssociatedStoreProductsAsync(new string[] { "Durable" }); var subscriptionStoreId = "9NV9QN9LX9FG"; foreach (var item in result.Products) { StoreProduct product = item.Value; if (product.StoreId == subscriptionStoreId) { subscriptionStoreProduct = product; } } // Load the sellable add-ons for this app and check if the trial is still // available for this customer. If they previously acquired a trial they won't // be able to get a trial again, and the StoreProduct.Skus property will // only contain one SKU. StorePurchaseResult purchaseResult = await subscriptionStoreProduct?.RequestPurchaseAsync(); switch (purchaseResult.Status) { case StorePurchaseStatus.AlreadyPurchased: case StorePurchaseStatus.Succeeded: RemoveAds = true; break; case StorePurchaseStatus.NotPurchased: case StorePurchaseStatus.ServerError: case StorePurchaseStatus.NetworkError: RemoveAds = false; break; default: RemoveAds = false; break; } #endif return(RemoveAds); }