【问题标题】:StoreProduct IsInUserCollection is always falseStoreProduct IsInUserCollection 始终为 false
【发布时间】:2018-12-04 00:19:08
【问题描述】:

我们在 Microsoft Store 中有一款 UWP 产品。该产品有许多订阅附加组件。用户在应用内购买订阅插件。 编辑我们的代码由 Microsoft Docs Enable subscription add-ons for your app 拼凑而成

StorePurchaseResult result = await product.RequestPurchaseAsync();
if (result.Status == StorePurchaseStatus.Succeeded)

结果返回StorePurchaseStatus.Succeeded。微软已将用户的钱用于订阅附加组件。到目前为止一切顺利。

我们需要这样的产品列表

string[] productKinds = { "Durable" };
List<String> filterList = new List<string>(productKinds);

StoreProductQueryResult queryResult = await storeContext.GetAssociatedStoreProductsAsync(filterList);
productList = queryResult.Products.Values.ToList();

然后遍历

foreach (StoreProduct storeProduct in products)
{
    if (storeProduct.IsInUserCollection)
...
}

storeProduct.IsInUserCollection 总是返回 false。 Microsoft 已接受插件的付款,但未将其添加到用户的产品集合中,因此我们无法验证他们是否已为插件付款。

我们哪里出错了?

EDIT 2根据@lukeja 的建议,我运行了这个方法

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}");
    }
}

这只会输出一个附加组件。免费的附加组件。我们有 16 个附加组件,其中只有一个是免费的。

为什么我们的任何付费附加订阅都没有退还?

EDIT 3 appLicense.AddOnLicenses 仅包括当前用户的附加许可,而不是应用的所有附加许可。 @lukeja 提供的代码示例在支付订阅的用户的上下文中运行时按预期工作。

【问题讨论】:

    标签: windows-store-apps windows-store


    【解决方案1】:

    我不确定您为什么要使用这种方法。我目前在我的应用程序中执行此操作的方式以及 Microsoft 文档建议的方式是这样的......

    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;
    }
    

    【讨论】:

    • 感谢您的回复@lukeja 我已经编辑了我的问题以显示对 Microsoft 文档的引用,我在其中获取了我们使用的代码。我们有 16 个附加组件,我们当前使用的代码返回我们迭代的全部 16 个。您提供的代码仅返回我们在商店中为该应用提供的 16 个附加组件中的一个附加组件。
    猜你喜欢
    • 2012-03-29
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 2020-07-25
    • 2011-05-01
    相关资源
    最近更新 更多