Skip to content

Instantly share code, notes, and snippets.

@vovafeldman
Last active October 2, 2024 11:04
Show Gist options
  • Save vovafeldman/bb7fbd006c6ab4c60e6e7d678b0d11d6 to your computer and use it in GitHub Desktop.
Save vovafeldman/bb7fbd006c6ab4c60e6e7d678b0d11d6 to your computer and use it in GitHub Desktop.
Validates a license key using Freemius API using the PHP SDK
<?php
// Freemius PHP SDK - https://github.com/Freemius/freemius-php-sdk
require_once './php-sdk-master/freemius/Freemius.php';
define( 'FS__API_SCOPE', 'developer' );
define( 'FS__API_DEV_ID', 1234 );
define( 'FS__API_PUBLIC_KEY', 'pk_YOUR_PUBLIC_KEY' );
define( 'FS__API_SECRET_KEY', 'sk_YOUR_SECRET_KEY' );
// Init SDK.
$api = new Freemius_Api(FS__API_SCOPE, FS__API_DEV_ID, FS__API_PUBLIC_KEY, FS__API_SECRET_KEY);
$licenses = $api->Api("/plugins/{$plugin_id}/licenses.json?search=" . urlencode($validated_license_key));
$is_valid_license_key = (1 === count($licenses->licenses));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment