Search code examples
c#winui

Microsoft StoreAppLicense understanding the trial logic


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?

  • (IsActive = True && IsTrial = True) This Means it's under trial and the trial hasn't ended.
  • (IsActive = False && IsTrial = True) This Means it's under trial, and the trial has ended.

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.


Solution

  • 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:

    • If you want to take action the moment the trial period expires then compare the current Coordinated Universal Time (or Zulu time) with ExpirationDate.
    • Otherwise, you can check IsActive, which returns true during the trial period and false some time after the trial period ends.