Trial License Tutorial: Step-by-Step Guide to Implementing Trial Versions

Published on: August 11, 2022
Last updated: July 6, 2023
LicenseSpring Guide
Table of Contents:

Trial Licenses are an alternative, expiring license type that exist within the LicenseSpring SDK. Trial licenses provide LicenseSpring’s customers the opportunity to tailor the state of their application for trial users. We will learn the essence of working with trial licenses using the LicenseSpring SDKs in this tutorial.

This guide will walk you through implementing trial licenses within the LicenseSpring SDK. By the end of this tutorial, you should understand how to provide end users with a functional trial license option, and manipulate the state for trial users. We will also examine the differences between trial and non-trial licenses, getting different trial licenses by policy, and extending trial license validity periods. We will create a basic program that gives the option for the input of a license policy, creates a trial license, then activates the trial license if the user doesn’t have a non-trial license for the same product.

For a C++ code sample on how to issue and activate a key-based trial licenses.

Here are the steps we will go through:

  • Differences Between Trial and Non-Trial Licenses
  • Issuing Trial Licenses
  • Extending a Trial License Validity Period on LicenseSpring
  • Allow Multiple Licenses on Trial
  • Differences Between User-based and Key-based Trial Licenses

Differences Between Trial and Non-Trial Licenses

Trial Licenses can be specified to only last a certain amount of time, such that, after its expiry date, the user can no longer use that trial license. Furthermore, these licenses are identifiable by the SDKs as a trial license, so the developer can use logic to determine what code is executed, for example: locking off certain features from trial licenses. Finally, trial licenses can be easily issued through the SDK. This will make the process of automating license creation and activation much simpler, especially for key-based trial licenses. User-based trial licenses work slightly different, but we will go through how they work later in this tutorial.

How to detect a trial vs. non-trial license

cpp
csharp
java
1 2 3 4 5 6 7 8 if ( license->isTrial() ) { //Trial license code } else { //Normal license code }

Issuing Trial Licenses

To create a trial license, you will first need to enable it on your product. When creating your product, there will be a checkbox labelled "Product has trial period". You will need to check this off, to be able to create trial licenses. You will also note a "Trial Duration" box. Trial duration determines how long your trial license will last until it expired from the moment it is activated, not issued. This is not too important too decide now, as it can be overwritten in the license issuing stage, but it determines what your default trial duration is, when a license/license-policy is first created.

Creating a product that allows trial licenses

Note: all these trial features can be overwritten later, so if you have already created a product that did not have trial licenses enabled, and you would like to add it, you can always edit your product to include trials.

Editing a product to include trial licenses

License Policies

Now that your product allows trials, it is recommended to make some license policies. These license policies save license settings, so that when you issue a license you won't have to recreate your settings each time. This is a good place to make a regular license policy and a trial license policy.

When we create our trial license policy we will create it as so:

Trial license policy

Note: we were able to create a trial license with a longer duration than the trial duration we specified when creating our product.

In the image below you will see we now have one non-trial license policy and one trial license policy. You will also notice that our non-trial license has the "Is Default" slider on. That slider determines which license policy is our default, so when we start creating a license, it will always start with the settings defined by that license policy.

Here I created one non-trial license one trial license.

Now that we have set up our product and license policy, there are two ways to issue trial licenses.

Through the Platform

You can issue trial licenses manually through the platform. Although this requires more work, this also allows for better control of your licenses.

We will now create a trial license for our product. Note when we first create our license, it will use our default license policy. From here, you can use the slider "Use custom license values" and turn on "Is Trial" for our license, but since we already created a trial license policy, let's use that instead.

Creating our license with our trial license policy

From here, you can activate this license normally, and it will expire based off your trial duration.

This method may work for some implementations, but for developers who are expecting a lot of trial licenses to be issued, our next method is probably more useful.

Through the SDK

You can automate issuing trial licenses by using the LicenseSpring SDK. You can create and activate a trial license within your application by incorporating this SDK within your code. Here is how to issue and activate a key-based trial license. We will go through how to issue a user-based trial license later.

cpp
csharp
java
1 2 3 4 5 6 7 //When using a key-based trial license, we leave the first parameter as a nullptr. //If we leave the second parameter, or pass it an empty string, it will use our default //license policy to create our trial license. Otherwise, we can pass it a specific //license policy code to use that policy's license settings. auto licenseId = licenseManager->getTrialLicense( nullptr, "license policy code" ); //We then use the licenseId to activate our generated key-based trial license auto license = licenseManager->activateLicense( licenseId );

Note, if we had not turned on "Product has trial period" for our product, our code would have encountered an error.

One more feature that is different about using the SDK to issue trial license is that when issuing your trial license, you can input any license policy regardless of if "Is Trial" is checked off, and the new license will have "Is Trial" checked off. Even using a license policy that is not a trial license policy will create a license with the same settings as that license policy with the exception that it is a trial license. It will have the trial duration specified when creating the product, or the last trial duration given to that license policy.

This method can be very useful for automating trial licenses, especially for developers who expect a large volume of trial licenses to be issued.

Extending a Trial License Validity Period on LicenseSpring

If you would like to extend the trial duration on a trial license, you can always do so through the platform by editing the trial license.

Extending a trial licenses validity period

You will notice, that you can either increase the amount of days before the trial license expires, or set a date. Furthermore, you can change the license into a regular license altogether by unchecking the "Is Trial" box.

Make sure, once you have updated your trial license, that the user's device runs an online check. This will sync up their local license with the online license, updating it to reflect the changes.

cpp
csharp
java
1 2 3 //This will run an online check on your local license and sync it to the license //on the LicenseSpring servers. license->check();

Allow Multiple Licenses on Trial

Within your LicenseSpring platform you can turn on "Allow multiple licenses on trial". This is found under Settings>Preferences. When this is turned on, every time a trial license is issued, it will create a new trial license, with a different key (for key-based trial licenses) each time. If you would like to avoid this, you can turn it off, limiting the user to one trial license.

Allowing multiple trial license option

Differences Between User-based and Key-Based Trial Licenses

Unlike key-based trial license, issuing a user-based trial license through the SDK require a bit more effort to implement. Issuing a user-based trial license on the platform works the same as any non-trial user-based license. You will just need to assign the user for the license.

Issuing through the SDK will first require the user's email. If the user has never been assigned to a license before, this will add their email to the customer database. If this is the user's first time being assigned to a license, or the user's password has never been changed, then you can proceed with activating their license normally, as the SDK will use the initial password associated with the account. If the user has changed their password, you will have to use this new password when activating their trial license.

cpp
csharp
java
1 2 3 4 5 6 7 auto licenseId = licenseManager->getTrialLicense( "email@example.com" ); //The password field will be empty if the email account is not using an initial password. if ( licenseId.password().empty() ) { licenseId.setPassword( "password associated with email account" ); } auto license = licenseManager->activateLicense( licenseId ); //returns a trial license

To see more about user-based licensing, and how it can affect trial licenses, go to our User-Based Licensing Tutorial.

Conclusion

You should now have a good understanding of how trial licenses work, and how they can be used to set expiry dates, and potentially block off features within your application. You should also now have the basic tools required to incorporate trial licenses into your project, including automating the trial issuing and activation process.

Frequently Asked Questions

Do I have to use license policies to create trial licenses?
How do I restrict features for trial licenses?
What do I do if my trial license is expired and I want to extend it?
Why is my trial license activation failing?
Why is My Trial license overriding regular license?