1. Go to this page and download the library: Download code-heaven/license-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
code-heaven / license-sdk example snippets
use CodeHeaven\License\Client;
use CodeHeaven\License\LicenseException;
use CodeHeaven\License\TransportException;
$client = new Client('YOUR_VENDOR_KEY', [
'cacheTtl' => 12 * 3600, // serve a fresh answer for 12h
'offlineGrace' => 14 * 24 * 3600, // keep working up to 14 days if the API is down
]);
try {
$res = $client->validate('LICENSE-KEY', 'shop.example.com', 'booknetic-pro');
} catch (LicenseException $e) {
// 403: invalid / expired / domain_not_activated ($e->apiCode tells you which)
bail("License problem: {$e->apiCode}");
} catch (TransportException $e) {
// API unreachable AND no cached valid result within grace.
bail('License server unreachable.');
}
if ($res['valid']) {
enable_premium_features();
} else {
// $res['status'] is one of: valid | invalid | expired | domain_not_activated | revoked
disable_premium_features($res['status']);
}
use CodeHeaven\License\SeatLimitException;
try {
$client->activateDomain('LICENSE-KEY', 'shop.example.com');
} catch (SeatLimitException $e) {
// 409 — buyer has used every seat; prompt them to deactivate another site.
}
$update = $client->checkUpdate('LICENSE-KEY', 'booknetic-pro', '4.1.0', 'shop.example.com');
if ($update['hasUpdate']) {
// latestVersion + changelog[{version,date,notes}]
$dl = $client->download('LICENSE-KEY', 'booknetic-pro', 'shop.example.com', $update['latestVersion']);
// $dl['url'] is a short-lived signed package URL; $dl['expiresAt'] tells you when it dies.
download_and_install_zip($dl['url']);
}
use CodeHeaven\License\FileCache;
use CodeHeaven\License\TransientCache;
// Outside WordPress:
new Client($key, ['cache' => new FileCache('/var/cache/myplugin')]);
// Inside WordPress (rides transients / the object cache):
new Client($key, ['cache' => new TransientCache('myplugin_')]);