How to check if an add-on has purchased that use StoreContext class

Fei Xue - MSFT 1,111 Reputation points
2019-10-30T06:32:31.537+00:00

I have defined a durable AddOn, and when I used RequestPurchaseAsync() method to check if an add-on has purchased or not, it always shows UI which will be annoying to the user.

In the previous version I used: CurrentApp.LicenseInformation.ProductLicenses[ProductId].IsActive to check if the add-on has purchased. So is there any method in StoreContext to solve the problem?

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 31,551 Reputation points Microsoft Vendor
    2019-10-31T01:21:43.987+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    In order to check if an add-on has purchased or not, please check the license information using StoreContext Class. To access the licenses for durable add-ons of the current app for which the user has an entitlement to use, use the AddOnLicenses property of the StoreAppLicense object as follows:

    public async void GetLicenseInfo()  
    {  
        if (context == null)  
        {  
            context = StoreContext.GetDefault();  
        }  
        StoreAppLicense appLicense = await context.GetAppLicenseAsync();  
      
        if (appLicense == null)  
        {  
            textBlock.Text = "An error occurred while retrieving the license.";  
            return;  
        }  
      
        // Access the valid licenses for durable add-ons for this app.  
        foreach (KeyValuePair item in appLicense.AddOnLicenses)  
        {  
            StoreLicense addOnLicense = item.Value;  
            // Use members of the addOnLicense object to access license info  
            // for the add-on.  
        }  
    }  
    

    For more information, please refer to this document: Get license info for apps and add-ons.

    Thanks

    0 comments No comments

0 additional answers

Sort by: Most helpful