Integration

After you’ve developed your app, go to the Author Dashboard and add a product you will be integrating licensing to. You will need to do three things:

  1. Save the product as a draft

  2. Note the ID for the product at the top of page

  3. Add licensing into your assembly, compile and upload files

The product ID is the identifier of your product which is to be used in the code.

Adding the licensing library to your app

You will need to download the Licensing library and add it as a reference in your app.

using PoshTrader.Licensing;

Validate licensing library origin

External libraries might be a subject of tampering by hackers to work around the licensing infrastructure. It's a good practice to validate its origin by comparing the code signature and making sure it hasn't tampered before executing any functions.

var assembly = Assembly.GetAssembly(typeof(ItemLicense));
var certificate = X509Certificate.CreateFromSignedFile(assembly.Location);
if (certificate.GetCertHashString() != "07FF85A977EF497368AA1ADEB64D43B2B55BD4D8")
{
    throw new Exception("Could not validate 'PoshTrader.Licensing' assembly origin.");
}

This doesn't apply to the cTrader platform and trying to validate its origin using the method above won't work.

Add item attributes

Those attributes serve as important data during communication with our licensing server. Make sure that these attributes are correct, and the version is up to date.

[Item(ID, "Sample Indicator", Version = "1.0.0", Author = "John Doe")]

Create item license object

At the beginning of your app life cycle, you need to create an item license object where you pass your main class object with item attributes as a parameter.

var license = new ItemLicense(this);

Verify license validation

The next thing you need to do is to check the license status. If the license is not valid, then a window will pop out asking for License Activation. If the user fails to validate his purchase, you will want to terminate the app or take some other action.

if (!license.IsValid())
    return;

Check if the user is running a trial period

Optionally, you might want to check if the user is running the Free 7-day trial and make some features not available or limited to demo trading accounts only.

if (license.IsTrial())
{
    // limited features
}
else
{
    // all features
}

You can do these checks as often and as many times as you need. The license validation process is done on the background asynchronously and syncs the status with our servers periodically.

Last updated