SDKs
...
Tutorials
Licensing Scenarios

Trial Licensing

10min

In this guide, we will explore the powerful capabilities of LicenseSpring's trial licensing feature, which enables software vendors to offer time-limited evaluation periods for their products.

Prerequisites

  1. Completed the Getting Started Tutorial, specifically:
    • Initialized LicenseManager (or LicenseHandler) with your configuration using the appropriate settings.
    • Created a LicenseID using either LicenseID::fromKey or LicenseID::fromUser function, depending on the activation method you prefer.

Differences Between Trial and Non-Trial Licenses

Distinguishing trial and non-trial licenses involves several key differences:

  1. Limited Validity: Trial licenses have a predefined expiration date, restricting the user's access to the software after this date. In contrast, non-trial licenses typically have no time restrictions, allowing perpetual usage.
  2. Identifiability: The LicenseSpring SDKs can recognize trial licenses as distinct entities. This enables developers to implement conditional logic based on the license type. For instance, specific features can be locked off for trial licenses, providing a tailored trial experience.

Allowing multiple licenses on trial

Inside Settings --> Preferences --> Allow multiple licenses on trial. This checkbox will allow you to create unlimited trial on same hardware_id.

Document image


Getting a Trial License Using the SDK

By integrating a LicenseSpring SDK into your application's codebase, you gain the ability to effortlessly generate and activate trial licenses.

It is shown how to create and enable a key-based trial license below:

C++
C#
Java
Swift
Python


Note: When using a key-based trial license, we leave the first parameter as a nullptr. When issuing a user-based trial license, we input the user email.

Note: 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.

It is also possible to pass a string of an email as the lone parameter, as shown below:

C++
C#
Java
Swift


Determining if the Current License Is a Trial

It is straightforward to check whether the current license in your software application is a trial license.

Each SDK has a method within the License object that allows developers to distinguish between trial and non-trial licenses, as shown below:

C++
C#
Java
Swift
Python


Sample Code for Obtaining and Activating a Trial License

The following sample code illustrates obtaining and activating trial licenses for both key and user-based licenses.

For the sample code to operate for user-based license, simply replace the nullptr in Customer::ptr_t user = nullptr with a Customer object.

Also, licensePolicyCode can be set to the string of any license policy code associated with the license, otherwise if left as empty it will use the default license policy.

C++
Python


After activating a trial license, developers can control the state of the application through the isTrial() method accessible through the License object.

This functionality is shown below:

C++
Python


Troubleshooting

Exceptions Related to Trial Licensing

Exceptions that might occur when performing offline license activation:

  • TrialNotAllowedException: Trial is not allowed by product license policy.