Learn how to effectively use logging in your software with LicenseSpring's step-by-step tutorial. Enhance debugging and improve application performance.
Trial License Tutorial: Step-by-Step Guide to Implementing Trial Versions
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
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.
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.
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:
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.
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.
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.
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.
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.
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.
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.
To see more about user-based licensing, and how it can affect trial licenses, go to our User-Based Licensing Tutorial.
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.
Q: Trial license overriding regular license.
If a device already has a license, and you try to activate a trial license on that device, for the same product, that trial license will override the regular license, deleting it from the device. The user will then have to activate their regular license again to retrieve it. This will be on the developer to make sure that they are not activating trial licenses on devices that already contain a regular license for the same product.
Q: Why is my trial license activation failing?
Trial license activation requires the same steps as a regular activation. You will need to make sure that whatever credentials you use to activate your trial license (key or user) are correct.
Q: What do I do if my trial license is expired and I want to extend it?
If the trial license has already expired, and you want to extend the trial duration, you can reset the trial license or edit the duration on the platform, then have the user reactivate their trial license, but it's probably easier to just issue a new trial license for them to activate.
Q: How do I restrict features for trial licenses?
There are multiple ways to do this. You can use license features, and add only the features you want available to your trial license. You can also use the fact that the license will have a license type: trial, which you can implement internal logic to block off features. For example: if a license is a trial type license, then don't allow them to be able to click this button. The implementation will vary per use-case, and the end-result will really depend on how you want to block off features.
Q: Do I have to use license policies to create trial licenses?
No. You do not need license policies to create trial licenses. You can issue licenses normally, then use custom settings to change a license into a trial license. License policies simply make it easier to save the settings for a trial type license, so that each time you issue a license, you will not have to change all the custom settings.