PHP code example of getkeymanager / laravel-sdk

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/ */

    

getkeymanager / laravel-sdk example snippets


'license_file_path' => env('LICENSE_FILE_PATH', 'storage/licenses'),
'default_identifier' => env('DEFAULT_IDENTIFIER', null), // or 'example.com'
'public_key_file' => storage_path('keys/public.pem'),

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'));
    }
}

'middleware' => [
    'redirect_to' => '/license-

use GetKeyManager\Laravel\Facades\GetKeyManager;

$result = GetKeyManager::createLicenseKeys(
    'product-uuid',
    'generator-uuid',
    [
        ['activation_limit' => 5, 'validity_days' => 365],
        ['activation_limit' => 1, 'validity_days' => 30]
    ],
    '[email protected]'
);

// Read offline license file
$offlineLicense = file_get_contents('license.lic');

$result = GetKeyManager::validateOfflineLicense($offlineLicense, [
    'hardwareId' => GetKeyManager::generateHardwareId()
]);

$details = GetKeyManager::getLicenseDetails('XXXXX-XXXXX-XXXXX-XXXXX');

// Get activations
$activations = GetKeyManager::getLicenseActivations('XXXXX-XXXXX-XXXXX-XXXXX');

// Suspend a license
GetKeyManager::suspendLicense('XXXXX-XXXXX-XXXXX-XXXXX');

// Resume a suspended license
GetKeyManager::resumeLicense('XXXXX-XXXXX-XXXXX-XXXXX');

// Revoke a license (permanent)
GetKeyManager::revokeLicense('XXXXX-XXXXX-XXXXX-XXXXX');

// Get license metadata
$metadata = GetKeyManager::getLicenseMetadata('XXXXX-XXXXX-XXXXX-XXXXX');

// Update metadata
GetKeyManager::updateLicenseMetadata('XXXXX-XXXXX-XXXXX-XXXXX', [
    'server_name' => 'Production 1',
    'deployment_date' => now()->toDateString()
]);

// Delete specific metadata key
GetKeyManager::deleteLicenseMetadata('XXXXX-XXXXX-XXXXX-XXXXX', 'server_name');

GetKeyManager::sendTelemetry('XXXXX-XXXXX-XXXXX-XXXXX', [
    'event' => 'feature_used',
    'feature_name' => 'export_pdf',
    'usage_count' => 1,
    'timestamp' => now()->toIso8601String()
]);

// Get product downloadables
$downloads = GetKeyManager::getDownloadables('product-uuid');

// Get download URL (authenticated)
$url = GetKeyManager::getDownloadUrl('downloadable-uuid', 'XXXXX-XXXXX-XXXXX-XXXXX');

// Redirect user to download
return redirect($url['data']['download_url']);

return [
    'api_key' => env('LICENSE_MANAGER_API_KEY'),
    'base_url' => env('LICENSE_MANAGER_BASE_URL', 'https://api.getkeymanager.com'),
    'environment' => env('LICENSE_MANAGER_ENVIRONMENT', 'production'),
    'verify_signatures' => env('LICENSE_MANAGER_VERIFY_SIGNATURES', true),
    'public_key' => env('LICENSE_MANAGER_PUBLIC_KEY'),
    'timeout' => env('LICENSE_MANAGER_TIMEOUT', 30),
    'cache_enabled' => env('LICENSE_MANAGER_CACHE_ENABLED', true),
    'cache_ttl' => env('LICENSE_MANAGER_CACHE_TTL', 300),
    'retry_attempts' => env('LICENSE_MANAGER_RETRY_ATTEMPTS', 3),
    'retry_delay' => env('LICENSE_MANAGER_RETRY_DELAY', 1000),
    
    'middleware' => [
        'redirect_to' => '/license-

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);
}
bash
php artisan vendor:publish --tag=getkeymanager-config
bash
php artisan license:validate XXXXX-XXXXX-XXXXX-XXXXX

# With options
php artisan license:validate XXXXX-XXXXX-XXXXX-XXXXX \
    --hardware-id=custom-hwid \
    --product-id=product-uuid

# JSON output
php artisan license:validate XXXXX-XXXXX-XXXXX-XXXXX --json
bash
php artisan license:activate XXXXX-XXXXX-XXXXX-XXXXX

# With custom hardware ID
php artisan license:activate XXXXX-XXXXX-XXXXX-XXXXX \
    --hardware-id=server-001 \
    --name="Production Server"

# Domain-based activation
php artisan license:activate XXXXX-XXXXX-XXXXX-XXXXX \
    --domain=example.com