我正在使用Windows.Services.Store API在Windows中发布的桌面桥应用程序中添加附加订阅。
我创建了一个为期3个月的测试附加订阅,为期1周的试用期。我可以通过从我的应用程序调用StoreAppLicence方法获得一个StoreContext.GetAppLicenseAsync
实例,然后从它的AddOnLicenses
属性中找到一个StoreLicense实例,该实例的SkuStoreId
在开始时与测试添加的StoreId匹配。但是不知道这个订阅是在试用期还是在付费(完整)阶段,因为它没有像IsTrial
那样的StoreAppLicence属性。
因此,我想知道如何确定订阅是在试用期还是在付费期,以便向我的用户展示我的应用程序中的归属状态。
更新
我不太清楚,但我询问的情况后,目前的用户已经“购买”附加订阅作为免费试用。我想知道如何确定试用期是否尚未完成,还是试用期已过,订阅已转至已支付(完整)期。
也许我可以通过将用户在本地“购买”订阅的数据存储起来,并将其与当前日期进行比较,但这似乎并不理想,因为这可能与Windows服务器管理的数据不一致。
发布于 2019-03-17 04:34:53
也许我找到了解决办法。
用IsTrial
方法得到的StoreCollectionData的StoreCollectionData性质提供了我所需要的信息。此外,StoreCollectionData还包括AcquiredDate
属性,该属性指示订阅添加的购买日期,对于计算过期日期非常有用。根据我的经验,用ExpirationDate
方法获得的StoreLicense的StoreLicense性质似乎不准确(比实际过期日期晚3天)。
示例代码如下所示。
public enum LicenseStatus
{
Unknown = 0,
Trial,
Full
}
private static StoreContext _context;
public static async Task<(string storeId, LicenseStatus status, DateTimeOffset acquiredDate)[]> GetSubscriptionAddonStatusesAsync()
{
if (_context is null)
_context = StoreContext.GetDefault();
StoreProductQueryResult queryResult = await _context.GetUserCollectionAsync(new[] { "Durable" });
if (queryResult.ExtendedError != null)
throw queryResult.ExtendedError;
IEnumerable<(string, LicenseStatus, DateTimeOffset)> Enumerate()
{
foreach (KeyValuePair<string, StoreProduct> pair in queryResult.Products)
{
StoreSku sku = pair.Value.Skus.FirstOrDefault();
StoreCollectionData data = sku?.CollectionData;
if (data != null)
{
LicenseStatus status = data.IsTrial ? LicenseStatus.Trial : LicenseStatus.Full;
yield return (pair.Key, status, data.AcquiredDate);
}
}
}
return Enumerate().ToArray();
}
另一方面,在StoreContext.GetUserCollectionAsync
方法中仍然存在一种奇怪的东西。它只提供最新的附加信息,而从它的解释,它应该提供所有附加的信息。因此,如果要检查多个附加项,此方法将是不够的.
发布于 2019-02-25 02:57:44
C#示例:
subscriptionStoreProduct = await GetSubscriptionProductAsync();
if (subscriptionStoreProduct == null)
{
return;
}
// Check if the first SKU is a trial and notify the customer that a trial is available.
// If a trial is available, the Skus array will always have 2 purchasable SKUs and the
// first one is the trial. Otherwise, this array will only have one SKU.
StoreSku sku = subscriptionStoreProduct.Skus[0];
if (sku.SubscriptionInfo.HasTrialPeriod)
{
// You can display the subscription trial info to the customer here. You can use
// sku.SubscriptionInfo.TrialPeriod and sku.SubscriptionInfo.TrialPeriodUnit
// to get the trial details.
}
else
{
// You can display the subscription purchase info to the customer here. You can use
// sku.SubscriptionInfo.BillingPeriod and sku.SubscriptionInfo.BillingPeriodUnit
// to provide the renewal details.
}
更新
如果用户可以使用订阅,则只有两种可能,一种是试用期,另一种是他们已经购买的。代码中的方法(GetSubscriptionProductAsync)获取用户可以使用的订阅,您可以在示例(购买一个挂号附加程序。)中看到详细信息。属性HasTrialPeriod获得一个值,该值指示订阅是否包含试用期。
https://stackoverflow.com/questions/54837363
复制相似问题