Skip to content

Instantly share code, notes, and snippets.

@darylldoyle
Created February 10, 2020 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darylldoyle/48d37e788aee45c129f072fe48d83f7e to your computer and use it in GitHub Desktop.
Save darylldoyle/48d37e788aee45c129f072fe48d83f7e to your computer and use it in GitHub Desktop.
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