Skip to content

Instantly share code, notes, and snippets.

@darylldoyle

darylldoyle/checkLicence.php Secret

Created Feb 10, 2020
Embed
What would you like to do?
Using the Freemius API to check if a licence is valid
<?php
/**
* Check to see if our licence is valid
*
* @param $license
*
* @return bool
*/
function checkLicence( $license ) {
define( 'FS__API_SCOPE', 'plugin' );
define( 'FS__API_DEV_ID', 0001 );
define( 'FS__API_PUBLIC_KEY', 'pk_xxxxxxxxxxxxxxxxx' );
define( 'FS__API_SECRET_KEY', 'sk_xxxxxxxxxxxxxxxxx' );
// Init SDK.
$api = new Freemius_Api( FS__API_SCOPE, FS__API_DEV_ID, FS__API_PUBLIC_KEY, FS__API_SECRET_KEY );
// Get all products.
$result = $api->Api( sprintf( '/licenses/%s.json', $license ) );
if ( property_exists( $result, 'error' ) ) {
return false;
} else {
try {
$now = new DateTime();
$expiration = new DateTime( $result->expiration );
$activated = $result->activated;
if ( $activated && $expiration >= $now ) {
return true;
}
return false;
} catch ( Exception $exception ) {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment