64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Core\Tenant\Exceptions;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Exception thrown when an operation targets a suspended package.
|
||
|
|
*
|
||
|
|
* This exception indicates that the workspace's packages have been suspended
|
||
|
|
* (e.g., for non-payment or policy violation), preventing feature access.
|
||
|
|
*
|
||
|
|
* @see EntitlementException Base exception class
|
||
|
|
*/
|
||
|
|
class PackageSuspendedException extends EntitlementException
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
string $message = 'Your package has been suspended.',
|
||
|
|
?string $featureCode = null,
|
||
|
|
public readonly ?int $workspaceId = null,
|
||
|
|
int $code = 403,
|
||
|
|
?\Throwable $previous = null
|
||
|
|
) {
|
||
|
|
parent::__construct($message, $featureCode, $code, $previous);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create exception for a specific workspace.
|
||
|
|
*/
|
||
|
|
public static function forWorkspace(int $workspaceId, ?string $featureCode = null): self
|
||
|
|
{
|
||
|
|
return new self(
|
||
|
|
message: 'Your package has been suspended. Please contact support or update your billing details.',
|
||
|
|
featureCode: $featureCode,
|
||
|
|
workspaceId: $workspaceId,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the workspace ID whose packages are suspended.
|
||
|
|
*/
|
||
|
|
public function getWorkspaceId(): ?int
|
||
|
|
{
|
||
|
|
return $this->workspaceId;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Render the exception as an HTTP response.
|
||
|
|
*/
|
||
|
|
public function render($request)
|
||
|
|
{
|
||
|
|
if ($request->expectsJson()) {
|
||
|
|
return response()->json([
|
||
|
|
'message' => $this->getMessage(),
|
||
|
|
'error' => 'package_suspended',
|
||
|
|
'feature_code' => $this->featureCode,
|
||
|
|
], $this->getCode());
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()
|
||
|
|
->with('error', $this->getMessage());
|
||
|
|
}
|
||
|
|
}
|