-
Notifications
You must be signed in to change notification settings - Fork 5
Endpoint: Activate
API's activate endpoint will let you activate and register a license key.
$response = Api::activate($client, $getClosure, $setClosure);
Parameter | Type | Description |
---|---|---|
$client | Client |
An instance of the client. |
$getClosure | Closure |
A function that should return an instance of LicenseRequest . |
$setClosure | Closure |
A function used to save or store somewhere the activated license string. |
Type | Description |
---|---|
null |
If response is empty. |
object |
The decoded response as an object. Use $response->error to check if response had an error. Use $response->errors for the list of errors. Use $response->message for the message returned by the API. Use $response->data for the license key data. |
The following example will show how to activate a license key and how to store the activated license string.
$licenseKey = '1564d65f4s6165esample-1';
$response = Api::activate(
Client::instance(), // Client instance
function() use($licenseKey) {
// MUST RETURN AN INSTANCE OF LicenseRequest
return LicenseRequest::create(
'https://your-domain.com/wp-admin/admin-ajax.php', // API's base url
'YOUR-STORE', // API's store code
'SKU', // Related product SKU
$licenseKey,
LicenseRequest::DAILY_FREQUENCY // Frequency in which to will validate against the API
);
}, // getClosure
function($licenseString) {
// ---------------------------------------------
// Code here...
// Code to save the LICENSE STRING somewhere.
// Apply encryption if necessary.
// ---------------------------------------------
// as sample
save_license($licenseString);
} // setClosure
);
Make sure to store the $licenseString
in somewhere safe. Add your encryption method of choice if necessary.
You can set the validation frequency when creating an instance of LicenseRequest
. The validation frequency will dictate how frequent should the client validate the activated license key against the API service. This is used to optimize calls to your API and create less stress as possible. When not validating against the API directly, the client will validate the license key with the data retrieved and stored in the license string.
// For daily validations
LicenseRequest::DAILY_FREQUENCY
// For weekly validations
LicenseRequest::WEEKLY_FREQUENCY
// For hourly validations
LicenseRequest::HOURLY_FREQUENCY
You can also set a custom frequency using the format used for function strtotime. Sample:
LicenseRequest::create(
'https://your-domain.com/wp-admin/admin-ajax.php',
'YOUR-STORE',
'SKU',
$licenseKey,
'+1 years' // Custom frequency to validate once a year.
);
You can specify the API handler to use when creating the license request, is the sixth parameter (after frequency). If no handler is specified, WP Ajax configuration will be used as default.
$licenseKey = '1564d65f4s6165esample-1';
$response = Api::activate(
Client::instance(), // Client instance
function() use($licenseKey) {
return LicenseRequest::create(
'https://your-domain.com', // API's base url
'YOUR-STORE', // API's store code
'SKU', // Related product SKU
$licenseKey,
LicenseRequest::DAILY_FREQUENCY, // Frequency
'wp_rest' // API Handler
);
},
function($licenseString) {
// Code here...
}
);
- WP Ajax
- Wordpress REST API
To use this handler, simply don't specify anything during creation. All code samples in the wiki use this handler.
Use string wp_rest
to specify this handler. Also, make sure to specify your root domain URL (removing /wp-admin/admin-ajax.php
) as base URL (without any /
slash at the end). See example:
$licenseKey = '1564d65f4s6165esample-1';
$response = Api::activate(
Client::instance(), // Client instance
function() use($licenseKey) {
return LicenseRequest::create(
'https://your-domain.com', // API's base url
'YOUR-STORE',
'SKU',
$licenseKey,
LicenseRequest::DAILY_FREQUENCY,
'wp_rest' // API Handler
);
},
function($licenseString) {
// Code here...
}
);