1. Go to this page and download the library: Download getkeymanager/laravel-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/ */
use GetKeyManager\Laravel\Facades\GetKeyManager;
use GetKeyManager\SDK\Constants\ValidationType;
// Validate with auto-generated identifier
$result = GetKeyManager::validateLicense('XXXXX-XXXXX-XXXXX-XXXXX');
// Or validate with specific identifier
$result = GetKeyManager::validateLicense(
'XXXXX-XXXXX-XXXXX-XXXXX',
'example.com', // Domain identifier
null, // Will use config's public key
ValidationType::OFFLINE_FIRST // Try cache first
);
if ($result['success']) {
echo "License is valid!";
}
// Activate a license
$result = GetKeyManager::activateLicense(
'XXXXX-XXXXX-XXXXX-XXXXX',
'workstation-01' // Required identifier
);
// Check a feature (fail-secure: returns false on any error)
if (GetKeyManager::checkFeature('XXXXX-XXXXX-XXXXX-XXXXX', 'advanced-features')) {
echo "Feature is enabled!";
}
use GetKeyManager\Laravel\GetKeyManagerClient;
class LicenseController extends Controller
{
public function validate(GetKeyManagerClient $license)
{
$result = $license->validateLicense(request('license_key'));
return response()->json($result);
}
}
// In routes/web.php
Route::middleware(['license.validate'])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'index']);
Route::get('/settings', [SettingsController::class, 'index']);
});
// Validate against a specific product
Route::get('/premium', function () {
return view('premium');
})->middleware('license.validate:product-uuid-here');
// Require a specific feature to be enabled
Route::get('/advanced-analytics', function () {
return view('analytics.advanced');
})->middleware('license.feature:advanced-analytics');
// Chain middlewares
Route::middleware(['license.validate', 'license.feature:reporting'])
->group(function () {
Route::get('/reports', [ReportController::class, 'index']);
});
class DashboardController extends Controller
{
public function index(Request $request)
{
$licenseData = $request->get('_license_data');
$customerEmail = $licenseData['customer_email'] ?? 'Unknown';
return view('dashboard', compact('licenseData', 'customerEmail'));
}
}
use GetKeyManager\Laravel\Facades\GetKeyManager;
use Exception;
try {
$result = GetKeyManager::validateLicense($licenseKey);
if (!$result['success']) {
// Handle validation failure
$errorCode = $result['code'] ?? 0;
$message = $result['message'] ?? 'Validation failed';
// Handle specific error codes
if ($errorCode === 4003) {
return "License has expired";
}
}
} catch (Exception $e) {
// Handle API errors
Log::error('License validation error: ' . $e->getMessage());
return "Unable to validate license";
}
use GetKeyManager\Laravel\Facades\GetKeyManager;
class FeatureTest extends TestCase
{
public function test_license_validation()
{
$result = GetKeyManager::validateLicense('test-license-key');
$this->assertTrue($result['success']);
$this->assertEquals('active', $result['data']['status']);
}
}
use GetKeyManager\Laravel\Facades\GetKeyManager;
public function test_protected_route()
{
GetKeyManager::shouldReceive('validateLicense')
->once()
->andReturn([
'success' => true,
'data' => ['status' => 'active']
]);
$response = $this->get('/protected-route');
$response->assertStatus(200);
}