This. Alternatively, you can use this process to purchase an add-on, such as a new game level for the user.
To request the purchase of an app or add-on, the Windows.Services.Store namespace provides several different methods:
- If you know the Store ID of the app or add-on, you can use the RequestPurchaseAsync method of the StoreContext class.
- If you already have a StoreProduct, StoreSku, or StoreAvailability object that represents the app or add-on, you can use the RequestPurchaseAsync methods of these objects. For examples of different ways to retrieve a StoreProduct in your code, see Get product info for apps and add-ons.
Each method presents a standard purchase UI to the user and then completes asynchronously after the transaction is complete. The method returns an object that indicates whether the transaction was successful. to enable in-app purchases
This example demonstrates how to use the RequestPurchaseAsync method of the StoreContext class to purchase an app or add-on with a known Store ID. For a complete sample application, see the Store sample.
private StoreContext context = null; 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. } 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."; break;; } }
Video
Watch the following video for an overview of how to implement in-app purchases in your app.