Skip to main content

Handy Extension Licensing: Developer Kit

Adding licence keys, licensed features and licensed updates to your own Joomla extension takes an afternoon, not a week. Here is how, step by step.

The developer kit comes with Handy Extension Licensing: you'll find handylicensing-devkit-1.1.1.zip next to the package in My downloads. It contains the client library, the embed.php tool and a complete example extension, and the client needs nothing but Joomla 6 and PHP's sodium extension.

1. Create the product

In Handy Extension Licensing create the product: element (e.g. pkg_myext, or com_myext, mod_myext, plg_system_myext …), key prefix (e.g. MYX1), features (e.g. pro, updates) and plans. Copy the public key from Signing Key.

2. Embed the client

php devkit/tools/embed.php \
    --namespace "Acme\Component\MyExt\Administrator\Licensing" \
    --prefix MYX1 \
    --public-key "<base64 public key>" \
    --package pkg_myext \
    --component com_myext \
    --out path/to/com_myext/admin/src/Licensing
  • --package: the installed extension whose update site gets the Download Key (the product element).
  • --component: the component whose options store the key (option name license_key, change with --option).
  • --validate-url (optional): the online validation address of your licence server.
  • The tool writes LicenseConfig.php, LicenseVerifier.php, LicenseStatus.php, LicenseService.php, OnlineValidator.php and Field/LicensestatusField.php. Don't edit them; run the tool again after updating the kit.

3. Licence key in the options

In the config.xml of your component:

<fieldset name="license" label="Licence" addfieldprefix="Acme\Component\MyExt\Administrator\Licensing\Field">
    <field name="license_key" type="textarea" label="Licence Key" rows="4" filter="string" class="font-monospace"/>
    <field name="license_status" type="licensestatus" label="Status"/>
</fieldset>

The status field shows whether the key is valid for this site, with licence number, licensee, domains, features and update period. Texts can be translated with COM_MYEXT_LICENSE_STATUS_<CODE> and COM_MYEXT_LICENSE_<LABEL>.

4. Check features

use Acme\Component\MyExt\Administrator\Licensing\LicenseService;

$license = new LicenseService(Factory::getContainer()->get(DatabaseInterface::class));

if ($license->hasFeature('pro')) {
    // professional function
}

$status = $license->getStatus();   // valid, missing, malformed, signature, domain, expired, revoked, suspended

Verification is offline: signature, key prefix, the site's domain (subdomains and * allowed; development hosts always) and expiry, cached for the request. onlineStatus() also asks the licence server about revoked, suspended or superseded licences and new keys — call it from a scheduled task rather than on every page.

5. Licensed updates

In the manifest of the extension named in --package:

<updateservers>
    <server type="extension" priority="1" name="My Extension">https://licences.example.com/index.php?option=com_handylicensing&amp;task=updates.xml&amp;product=pkg_myext</server>
</updateservers>
<dlid prefix="dlid=" suffix=""/>

Write the key into the update site (the Download Key) after installations and whenever it changes:

// installer script (package or component), postflight():
(new LicenseService($db))->ensureUpdateSiteKey();

// a system plugin, after the options of your component were saved:
public function onExtensionAfterSave(AfterSaveEvent $event): void
{
    if ($event->getContext() === 'com_config.component' && $event->getItem()->element === 'com_myext') {
        (new LicenseService($db))->syncUpdateSites((string) (new Registry($event->getItem()->params))->get('license_key'));
    }
}

Then publish each release by uploading its zip in Handy Extension Licensing (or through the API, or with Handy Download Sales).

6. Release builds

Build your extension with the public key of your licence server, and never ship a key pair whose secret is in a repository. Handy Extension Licensing's own build replaces PUBLIC_KEY in the embedded LicenseConfig.php (build.py --public-key …); you can do the same or run embed.php in your build.

The example extension: Hello Licensed

example/com_hellolicensed is a component with a dashboard that shows the licence status and a “professional” function that needs the feature pro, with the key in its options, an update server and the Download Key. Create the product com_hellolicensed (prefix HLO1, features basic, pro, updates), build the example with your public key, install it, issue a licence, paste the key — and upload version 1.0.1 to see a licensed update in Joomla.

API reference

POST https://licences.example.com/index.php?option=com_handylicensing&task=api.<action>&format=json
Authorization: Bearer hel_…            (or X-HandyLicensing-Token: hel_…)
Content-Type: application/json

Responses: {"success": true, "data": …} or {"success": false, "error": {"code": …, "message": …}} with HTTP 400, 401, 403 (scope missing), 404, 405, 409, 413, 422, 429 or 503.

Actions
ActionScopeBody
productsread— (products with features and plans)
issueissueproduct, plan, name, email, domains, source_ref, order_ref, notes
licencereadnumber or source_ref
domainsmanagenumber, domains (plan limits apply)
suspend, reinstate, revokemanagenumber, reason
renewmanagenumber, months (optional)
periodmanagenumber, until (end of a subscription's paid period)
transfermanagenumber, name, email, note
releasereleasesproduct, file_name, file_base64, notes, target_platform, php_minimum, state, replace
validatepublic, rate limitedkey, domain → valid, status, licence summary (no personal data), key_current

Idempotency: issue with a source_ref never creates a second licence — repeat the request as often as needed. A transfer (1.1) signs a key for the new holder; keys issued before are superseded: refused by the update server and reported by validate.

Getting Handy Extension Licensing

A Single Site licence is £49.99; an Agency licence for every site you look after is £199. Both include twelve months of updates, and everything keeps working afterwards. You can try it first in our demo, and if you have a question before you buy, just ask us.