new changes

This commit is contained in:
Niranjan
2026-04-07 20:29:49 +05:30
parent 8fe63c7cf4
commit 31fe556bb0
79 changed files with 2917 additions and 0 deletions

View 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,
];
}
}

View 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,
];
}
}

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