I've had trial capabilities implemented within my application for a little while now; a very simple 1-day full trial for context set within the Microsoft Partner Centre.
I recently got a review that stated some issues when installing my app as a trial related to it immediately expiring. So I wanted to review the logic but I am having some trouble understanding if I've taken a slightly redundant approach to the way I check for valid licences and it's not explicitly clear from the Microsoft documentation the exact logic.
Below is the snippet of code I use to check for a valid trial license:
public StoreAppLicense? AppLicense
{
get; set;
}
public bool IsTrialExpired()
{
if (AppLicense == null)
{
return false;
}
// It's expired if it's a trial, it's not active, or the expiration date is in the past
return AppLicense.IsTrial && (!AppLicense.IsActive || DateTime.UtcNow > AppLicense.ExpirationDate);
}
Do I need the date check and are the below assumptions correct?
In which case, I don't need the date check OR ALTERNATIVELY when the trial expiration date elapses does the IsActive stay true, and I am indeed supposed to do a date comparison. I feel like I'm hedging my bets but without really knowing which is the right combination.
The actual trigger for IsActive changing isn't explicit in relation to the trial-related documentation; I could also be completely missing the paragraph or sentence that clears this all up, in which case, apologies.
You assumptions are indeed correct but as stated in the docs, "it can take some hours after the trial period ends for IsActive
to begin returning a value of false
".
While IsTrial returns true, there are two ways to tell whether the trial period has expired: