Module licensing

We have included the following code into the gateway hook but I’m not sure if this is sufficient to protect against a gateway that is in production but does not have license key for our module. We want to offer our module for testing (2 hour trial) without worrying that it could be used for production without purchasing.

@Override
public void notifyLicenseStateChanged(final LicenseState licenseState) {
    super.notifyLicenseStateChanged( licenseState );
    protectLicense( licenseState );
}

private static void protectLicense(final LicenseState licenseState) {
    if( licenseState == null || (licenseState.getLicenseMode() == LicenseMode.Trial && licenseState.isTrialExpired() ) ) {
        //Raise an exception
        throw new IllegalStateException("The module is not activated.");
    }

Raising an exception is not going to do anything to protect your module when the trial expires. You have to decide what functionality, if any, remains and actually disable it somehow. Then you need to re-enable that functionality once the trial is reset.

I would expect that to do bad things to the gateway’s module manager. You need to save your inactive/trial/activated state in a private variable accessible from a static method, or in some other object that all parts of your module have access to. Everything your module does should check that static method before proceeding, returning bad quality on invalid data, drawing an overlay on custom components (or replace the component content with the trial expired message), or restricting behaviour in some way that makes it obvious that the trial has expired. Don’t throw exceptions.

If checking a static variable everywhere is too much of a performance hit, you could also spawn a runnable on state change that would iterate through your module-specific objects to pass on the notice in an optimized fashion.

2 Likes

Great thanks, I think we will pursue the runnable method.

Is the showcase API project working, We see our modules but when we click “add” to generate license for a particular module we get a popup with a new key but that key does not show up in the list. whats the exact procedure?

Restricting the functionality of your module, such as not updating the tags with latest values etc, is the best option, when trial expired state is true,

Perhaps a bug. Are you sure your search box is completely empty?

yes the search filter is empty.

Hmmm. Works for me. Showed in the list as soon as the popup was closed. Are you using the latest project?

Note, new license keys are not attached to a particular module. You have to create the key first, then add modules to it.

I guess I was not using the latest project. As soon as i used your provided project i see all the licenses.

Thank you!