Reputation: 3556
I am working on adding add-on subscription to my Desktop Bridge app published in Windows store using Windows.Services.Store APIs.
I created a test add-on of subscription for 3 month period with 1 week trial period. I can get a StoreAppLicence instance by StoreContext.GetAppLicenseAsync
method calling from my app and then from its AddOnLicenses
property, find a StoreLicense instance whose SkuStoreId
matches the StoreId of the test add-on in the beginning. But there is no clue whether this subscription is in trial period or in paid (full) period because it does not have IsTrial
property like StoreAppLicence.
So I would like to how to determine whether the subscription is in trial period or in paid period for showing my users the status of subcription in my app.
Update
I was not clear enough but I am asking about the case after the current user has "purchased" add-on subscription as free trial. I would like to know how to determine whether the trial period has not finished yet or the trial period has passed already and the subscription has moved to paid (full) period.
Probably I can achieve it by storing the data on when the user "purchased" the subscription in local and comparing it with the current date but it seems not ideal because there might be a chance of inconsistency with the data managed by Windows Store server.
Upvotes: 0
Views: 612
Reputation: 3556
Probably I found a solution.
IsTrial
property of StoreCollectionData obtained by StoreContext.GetUserCollectionAsync
method provides the information what I need. In addition, the StoreCollectionData also includes AcquiredDate
property which indicates the purchase date of subscription add-on and is useful to calculate the expiration date on your own. In my experience, ExpirationDate
property of StoreLicense obtained by StoreContext.GetAppLicenseAsync
method seems not accurate (3 days later than actual expiration date).
The sample code would be as follows.
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();
}
On the other hand, there still exists a weird thing on StoreContext.GetUserCollectionAsync
method. It only provides the information on the latest add-on while from its explanation, it should provide the information on all add-ons. Therefore, if you want to check multiple add-ons, this method will not be enough.
Upvotes: 1
Reputation: 1086
C# example:
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.
}
Derive from sample Purchase a subscription add-on and Class StoreSku Class
Update
If users can use subscription, there are only two possibilities, one for a trial period and one that they have already purchased. The method (GetSubscriptionProductAsync) in the code gets the subscriptions which users can use, you could see the details in the sample(Purchase a cubscription add-on). The property HasTrialPeriod gets a value that indicates whether the subscription contains a trial period.
Upvotes: 0