new changes
This commit is contained in:
16
panel-api/app/Modules/SaaS/BillingHooksService.php
Normal file
16
panel-api/app/Modules/SaaS/BillingHooksService.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\SaaS;
|
||||
|
||||
class BillingHooksService
|
||||
{
|
||||
public function emitUsageEvent(string $tenantId, string $eventType, array $payload): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'event_type' => $eventType,
|
||||
'status' => 'queued',
|
||||
'payload' => $payload,
|
||||
];
|
||||
}
|
||||
}
|
||||
18
panel-api/app/Modules/SaaS/QuotaService.php
Normal file
18
panel-api/app/Modules/SaaS/QuotaService.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\SaaS;
|
||||
|
||||
class QuotaService
|
||||
{
|
||||
public function check(string $tenantId, string $resource, int $requested = 1): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => $tenantId,
|
||||
'resource' => $resource,
|
||||
'requested' => $requested,
|
||||
'allowed' => true,
|
||||
'limit' => null,
|
||||
'current_usage' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
38
panel-api/app/Modules/SaaS/SaaSController.php
Normal file
38
panel-api/app/Modules/SaaS/SaaSController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\SaaS;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class SaaSController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly QuotaService $quota,
|
||||
private readonly BillingHooksService $billing
|
||||
) {
|
||||
}
|
||||
|
||||
public function checkQuota(Request $request): JsonResponse
|
||||
{
|
||||
$tenantId = (string) $request->attributes->get('tenant_id', '');
|
||||
$resource = (string) $request->input('resource', '');
|
||||
$requested = (int) $request->input('requested', 1);
|
||||
|
||||
return response()->json([
|
||||
'data' => $this->quota->check($tenantId, $resource, $requested),
|
||||
]);
|
||||
}
|
||||
|
||||
public function usageEvent(Request $request): JsonResponse
|
||||
{
|
||||
$tenantId = (string) $request->attributes->get('tenant_id', '');
|
||||
$eventType = (string) $request->input('event_type', 'generic');
|
||||
$payload = (array) $request->input('payload', []);
|
||||
|
||||
return response()->json([
|
||||
'data' => $this->billing->emitUsageEvent($tenantId, $eventType, $payload),
|
||||
], 202);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user