Files
ladill-care/app/Http/Middleware/EnsurePaidPlan.php
T
isaacclad f9aa4a679f
Deploy Ladill Care / deploy (push) Successful in 29s
Tighten Care free tier and bill Pro/Enterprise per branch.
Free keeps core records, appointments, and basic workflows; Pro unlocks lab, pharmacy, billing, and Queue. Both paid tiers bill per branch with unlimited branches. Enterprise adds multi-dept workflows, analytics, AI-assisted healthcare integration, and priority support (not Afia).
2026-07-15 14:14:35 +00:00

45 lines
1.3 KiB
PHP

<?php
namespace App\Http\Middleware;
use App\Services\Care\OrganizationResolver;
use App\Services\Care\PlanService;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Blocks free-plan accounts from Pro modules (lab, pharmacy, billing, Queue integration).
*/
class EnsurePaidPlan
{
public function __construct(
protected OrganizationResolver $organizations,
protected PlanService $plans,
) {}
public function handle(Request $request, Closure $next): Response
{
$user = $request->user();
if (! $user) {
return $next($request);
}
$organization = $this->organizations->resolveForUser($user);
if (! $organization || $this->plans->hasPaidPlan($organization)) {
return $next($request);
}
if ($request->expectsJson() || $request->ajax()) {
return response()->json([
'message' => 'This feature requires Care Pro or Enterprise.',
'upgrade_url' => route('care.pro.index'),
], 402);
}
return redirect()
->route('care.pro.index')
->with('upsell', 'Lab, pharmacy, billing, and Queue integration are part of Care Pro. Upgrade to unlock them.');
}
}