Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions app/Contracts/LicensingServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Contracts;

use App\Models\EnterpriseLicense;
use App\Models\Organization;

interface LicensingServiceInterface
{
/**
* Validate a license key with optional domain checking
*/
public function validateLicense(string $licenseKey, ?string $domain = null): \App\Data\LicenseValidationResult;

/**
* Issue a new license for an organization
*/
public function issueLicense(Organization $organization, array $config): EnterpriseLicense;

/**
* Revoke an existing license
*/
public function revokeLicense(EnterpriseLicense $license): bool;

/**
* Check if an organization is within usage limits
*/
public function checkUsageLimits(EnterpriseLicense $license): array;

/**
* Generate a secure license key
*/
public function generateLicenseKey(Organization $organization, array $config): string;

/**
* Refresh license validation timestamp
*/
public function refreshValidation(EnterpriseLicense $license): bool;

/**
* Check if a domain is authorized for a license
*/
public function isDomainAuthorized(EnterpriseLicense $license, string $domain): bool;

/**
* Get license usage statistics
*/
public function getUsageStatistics(EnterpriseLicense $license): array;

/**
* Suspend a license
*/
public function suspendLicense(EnterpriseLicense $license, ?string $reason = null): bool;

/**
* Reactivate a suspended license
*/
public function reactivateLicense(EnterpriseLicense $license): bool;
}
57 changes: 57 additions & 0 deletions app/Data/LicenseValidationResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Data;

use App\Models\EnterpriseLicense;

class LicenseValidationResult
{
public function __construct(
public readonly bool $isValid,
public readonly string $message,
public readonly ?EnterpriseLicense $license = null,
public readonly array $violations = [],
public readonly array $metadata = []
) {}

public function isValid(): bool
{
return $this->isValid;
}

public function getMessage(): string
{
return $this->message;
}

public function getLicense(): ?EnterpriseLicense
{
return $this->license;
}

public function getViolations(): array
{
return $this->violations;
}

public function getMetadata(): array
{
return $this->metadata;
}

public function hasViolations(): bool
{
return ! empty($this->violations);
}

public function toArray(): array
{
return [
'is_valid' => $this->isValid,
'message' => $this->message,
'license_id' => $this->license?->id,
'violations' => $this->violations,
'metadata' => $this->metadata,
];
}
}
55 changes: 55 additions & 0 deletions app/Exceptions/LicenseException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Exceptions;

use Exception;

class LicenseException extends Exception
{
public static function notFound(): self
{
return new self('License not found');
}

public static function expired(): self
{
return new self('License has expired');
}

public static function revoked(): self
{
return new self('License has been revoked');
}

public static function suspended(?string $reason = null): self
{
$message = 'License is suspended';
if ($reason) {
$message .= ': '.$reason;
}

return new self($message);
}

public static function domainNotAuthorized(string $domain): self
{
return new self("Domain '{$domain}' is not authorized for this license");
}

public static function usageLimitExceeded(array $violations): self
{
$messages = array_column($violations, 'message');

return new self('Usage limits exceeded: '.implode(', ', $messages));
}

public static function validationFailed(string $reason): self
{
return new self('License validation failed: '.$reason);
}

public static function generationFailed(): self
{
return new self('Failed to generate license key');
}
}
25 changes: 25 additions & 0 deletions app/Facades/Licensing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static \App\Data\LicenseValidationResult validateLicense(string $licenseKey, string $domain = null)
* @method static \App\Models\EnterpriseLicense issueLicense(\App\Models\Organization $organization, array $config)
* @method static bool revokeLicense(\App\Models\EnterpriseLicense $license)
* @method static array checkUsageLimits(\App\Models\EnterpriseLicense $license)
* @method static string generateLicenseKey(\App\Models\Organization $organization, array $config)
* @method static bool refreshValidation(\App\Models\EnterpriseLicense $license)
* @method static bool isDomainAuthorized(\App\Models\EnterpriseLicense $license, string $domain)
* @method static array getUsageStatistics(\App\Models\EnterpriseLicense $license)
* @method static bool suspendLicense(\App\Models\EnterpriseLicense $license, string $reason = null)
* @method static bool reactivateLicense(\App\Models\EnterpriseLicense $license)
*/
class Licensing extends Facade
{
protected static function getFacadeAccessor()
{
return 'licensing';
}
}
Loading