Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
The StoreContext
class is part of the Windows.Services.Store namespace, which is used in Universal Windows Platform (UWP) applications to interact with the Microsoft Store. It allows developers to access and manage digital products, such as in-app purchases and subscriptions, directly from their applications. This article will guide you through how to use the StoreContext
class in a Windows environment, specifically within UWP applications.
The StoreContext
class provides several methods to facilitate interactions with the Microsoft Store. These include methods to:
To retrieve information about a product listed in the Microsoft Store, you can use the GetStoreProductsAsync
method. Here's a simple example:
using Windows.Services.Store;
using System.Collections.Generic;
public async void GetProductInfo()
{
StoreContext context = StoreContext.GetDefault();
List<string> productKinds = new List<string> { "Durable" };
StoreProductQueryResult result = await context.GetStoreProductsAsync(productKinds, new List<string> { "9NBLGGH4R315" });
if (result.ExtendedError == null)
{
foreach (var item in result.Products)
{
StoreProduct product = item.Value;
System.Diagnostics.Debug.WriteLine($"Product: {product.Title}, Price: {product.Price.FormattedPrice}");
}
}
else
{
System.Diagnostics.Debug.WriteLine($"Error: {result.ExtendedError.Message}");
}
}
To initiate a purchase of a product, use the RequestPurchaseAsync
method:
using Windows.Services.Store;
public async void PurchaseProduct(string productId)
{
StoreContext context = StoreContext.GetDefault();
StorePurchaseResult result = await context.RequestPurchaseAsync(productId);
switch (result.Status)
{
case StorePurchaseStatus.Succeeded:
System.Diagnostics.Debug.WriteLine("Purchase successful!");
break;
case StorePurchaseStatus.AlreadyPurchased:
System.Diagnostics.Debug.WriteLine("Product already purchased.");
break;
case StorePurchaseStatus.NotPurchased:
System.Diagnostics.Debug.WriteLine("Purchase not completed.");
break;
case StorePurchaseStatus.NetworkError:
System.Diagnostics.Debug.WriteLine("Network error occurred.");
break;
case StorePurchaseStatus.ServerError:
System.Diagnostics.Debug.WriteLine("Server error occurred.");
break;
}
}
If you are developing a non-UWP application, such as a traditional Windows desktop application, the StoreContext
class is not applicable. Instead, you might consider using other APIs or services for managing purchases and licenses, such as: