If you are offering your plugin on the SmartStore Community Marketplace, you can easily make it licensable. If a plugin is licensable, it will behave as follows:
- A shop administrator can use your plugin for free for 30 days (demonstration mode). After this period, the plugin has to be licensed.
- A shop administrator receives a license key after purchasing the plugin on the SmartStore Marketplace. To activate the license key, it has to be entered in the SmartStore.NET backend (Plugins > Manage Plugins). A key is only valid for the IP address that originally activated it.
- The license status is periodically checked to ensure that nobody is misusing your plugin.
The following steps are necessary to make a plugin licensable:
- Add a reference of
lib\SmartStore.Licensing\SmartStore.Licensing.dllto your plugin.
Open your main plugin class (typically derived from one of the base plugin classes:
IPlugin.). Decorate it with the
Decorate your controllers or action methods with the
LicenseRequiredfilter attribute, or alternatively, call
LicenseChecker.Check[State]()in your code.
The LicensableModule Attribute
The attribute is intended to mark a plugin as a licensed piece of code where the user has to enter a license key that has to be activated.
The LicenseRequired Filter Attribute
You can decorate either a whole controller class or just a single action method with the
LicenseRequired attribute. This attribute internally calls
LicenseChecker.Check() right before your action is processed, giving it the opportunity to block the action. If the license isn't valid, the
LicenseRequiredView will be rendered by default, which you can override by setting the property
ViewName on the attribute. Alternatively, you could just display a notification for which you can use the properties
NotificationMessageType. Ajax requests will be recognized automatically, and a suitable response will be generated according to the negotiated content type (either JSON or HTML).
If you want to block certain methods or even your entire plugin when it is in demo mode, you need to set the property BlockDemo to True, otherwise everything will be accessible in the demo mode, as the value of BlockDemo is False by default.
The License Checker
The license checker is a set of static functions for license validation within
SmartStore.Licensing.dll. As a plugin developer, you probably get into situations where you want to check the license status explicitly - that's what the license checker is for. Always provide the system name of the plugin, not the system name of a provider.
Checks the state of a license. This method is an overload of
LicenseChecker.Check method. Available states (return values) are Unlicensed, Demo and Licensed.
Typically, you check the state of the license when you do not need or want any output, or want to cut the output.
This is the main method for checking the state of a license. Returns a
LicenseCheckerResult object with various information about the status check. If you need a stringified version of the result (German and English localization supported), call the
ToString() method of the returned object.
Imagine you have developed a plugin to communicate with an ERP system. Furthermore, your plugin transmits data to a web service whenever an order is placed in your shop and consumes another web service to keep your product data up-to-date. If you decide to allow the product data to be updated completely in the demo mode of your plugin, it may be sufficient for the plugin user to import the product data only once. Therefore, you should interrupt the routine that's responsible for updating product data after a certain number of products have been updated. To do so, you would use the
CheckState() method, which checks whether the state is Demo and stops the routine accordingly (see code example 1). This way, the user can see a demonstration of the actual function without getting the whole pie. Order events should, of course, be processed and transmitted to the ERP system completely for demonstration purposes, as it's way too difficult to keep track of the number of processed orders. However, when the demonstration period is over, no more orders should be processed. Therefore, you would use the
CheckState() method to check whether the state is Unlicensed and to stop the event accordingly (see code example 2).
Examples and Special Cases
LicenseChecker.Check() are checking the license state against the current request URL or as a fallback against the current store URL (if there is no HTTP request object, which is usually the case in background tasks). The second parameter of these methods allows you to provide a different URL. The best example for this case is the promotion feed plugins. These plugins automatically create a feed file for each store (in a multi-store installation) within a background task. The creation of the feed file should be skipped if there is no active license for that particular store.
Additionally, a payment plugin can hide its payment methods at checkout if there is no active license. To enable this to work, you must override the