We have a UWP product in the Microsoft Store. The product has a number of subscription add-ons. Users make in-app purchases of subscription add-ons. EDIT Our code is cobbled from Microsoft Docs Enable subscription add-ons for your app
StorePurchaseResult result = await product.RequestPurchaseAsync();
if (result.Status == StorePurchaseStatus.Succeeded)
The result returns StorePurchaseStatus.Succeeded
. Microsoft has taken the user's money for the subscription add-on. All good so far.
We qet a product list like this
string[] productKinds = { "Durable" };
List<String> filterList = new List<string>(productKinds);
StoreProductQueryResult queryResult = await storeContext.GetAssociatedStoreProductsAsync(filterList);
productList = queryResult.Products.Values.ToList();
Then iterate through
foreach (StoreProduct storeProduct in products)
{
if (storeProduct.IsInUserCollection)
...
}
but storeProduct.IsInUserCollection
always returns false. Microsoft has accepted payment for the add-on but not added it to the user's collection of products, so we cannot verify they have paid for the add-on.
Where did we go wrong?
EDIT 2 Following a suggestion from @lukeja I ran this method
async Task CheckSubsAsync()
{
StoreContext context = context = StoreContext.GetDefault();
StoreAppLicense appLicense = await context.GetAppLicenseAsync();
foreach (var addOnLicense in appLicense.AddOnLicenses)
{
StoreLicense license = addOnLicense.Value;
Debug.WriteLine($"license.SkuStoreId {license.SkuStoreId}");
}
}
This outputs only a single add-on. The free add-on. We have 16 add-ons only one of which is free.
Why aren't any of our paid add-on subscriptions returned?
EDIT 3 appLicense.AddOnLicenses
only includes add-on licenses for the current user, not all add-ons for the app. The code sample provided by @lukeja works as expected when run within the context of the user who paid the subscription.
I'm not sure why you're using that method. The way I'm currently doing it in my app and the way that Microsoft's documentation suggests is like this...
private async Task<bool> CheckIfUserHasSubscriptionAsync()
{
StoreAppLicense appLicense = await context.GetAppLicenseAsync();
// Check if the customer has the rights to the subscription.
foreach (var addOnLicense in appLicense.AddOnLicenses)
{
StoreLicense license = addOnLicense.Value;
if (license.IsActive)
{
// The expiration date is available in the license.ExpirationDate property.
return true;
}
}
// The customer does not have a license to the subscription.
return false;
}