trypost/app/Http/Controllers/App/Settings/UsageController.php
Paulo Castellano aacc4390a2 refactor(billing): replace MonthlyCreditsLimit Pennant feature with BillingCycle
Credit allotment is now derived directly from BillingCycle::for($account)->creditAllotment()
instead of a cached Pennant feature, removing the dynamic cache-invalidation footgun
(forgetPlanFeatureCache) that had to be called from every subscription/workspace mutation.
2026-06-22 09:55:03 -03:00

44 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\App\Settings;
use App\Http\Controllers\App\Controller;
use App\Support\BillingCycle;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
class UsageController extends Controller
{
public function index(Request $request): Response|RedirectResponse
{
if (config('trypost.self_hosted')) {
return redirect()->route('app.calendar');
}
abort_unless($request->user()->isAccountOwner(), SymfonyResponse::HTTP_FORBIDDEN);
$account = $request->user()->account;
$totalSocialAccounts = 0;
$totalMembers = $account->users()->count();
foreach ($account->workspaces as $workspace) {
$totalSocialAccounts += $workspace->socialAccounts()->count();
}
return Inertia::render('settings/account/Usage', [
'usage' => [
'workspaceCount' => $account->workspaces->count(),
'socialAccountCount' => $totalSocialAccounts,
'memberCount' => $totalMembers,
'creditsUsed' => BillingCycle::for($account)->usedCredits(),
'monthlyCreditsLimit' => BillingCycle::for($account)->creditAllotment(),
],
]);
}
}