Files
ladill-frontdesk/app/Services/Frontdesk/PlanService.php
T
isaaccladandCursor 5be14d0982
Deploy Ladill Frontdesk / deploy (push) Successful in 2m46s
Add 3-tier plans, Paystack prepaid Pro, and Enterprise contact-sales card.
Sidebar settings and upgrade share one footer with consistent spacing.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 01:55:38 +00:00

94 lines
2.7 KiB
PHP

<?php
namespace App\Services\Frontdesk;
use App\Models\Device;
use App\Models\Organization;
use Carbon\Carbon;
class PlanService
{
public function planKey(Organization $organization): string
{
$settings = $organization->settings ?? [];
$plan = (string) ($settings['plan'] ?? 'free');
if (in_array($plan, ['pro', 'enterprise'], true) && ! empty($settings['plan_expires_at'])) {
if (Carbon::parse($settings['plan_expires_at'])->isPast()) {
return 'free';
}
}
return array_key_exists($plan, config('frontdesk.plans', [])) ? $plan : 'free';
}
public function isPro(Organization $organization): bool
{
return $this->planKey($organization) === 'pro';
}
public function isEnterprise(Organization $organization): bool
{
return $this->planKey($organization) === 'enterprise';
}
/** Self-serve paid plans only — enterprise is sales-led. */
public function hasPaidPlan(Organization $organization): bool
{
return $this->planKey($organization) === 'pro';
}
/** @return array<string, mixed> */
public function plan(Organization $organization): array
{
$key = $this->planKey($organization);
return [
'key' => $key,
...(array) config('frontdesk.plans.'.$key, []),
];
}
/** Null means unlimited included host emails (Pro). */
public function freeEmailsPerMonth(Organization $organization): ?int
{
$value = config('frontdesk.plans.'.$this->planKey($organization).'.free_emails_per_month', 100);
return $value === null ? null : (int) $value;
}
public function canAddBranch(Organization $organization, int $currentCount): bool
{
$limit = config('frontdesk.plans.'.$this->planKey($organization).'.max_branches');
return $limit === null || $currentCount < (int) $limit;
}
public function canAddKiosk(Organization $organization): bool
{
$limit = config('frontdesk.plans.'.$this->planKey($organization).'.max_kiosk_devices');
if ($limit === null) {
return true;
}
$count = Device::query()
->where('organization_id', $organization->id)
->where('type', 'kiosk')
->count();
return $count < (int) $limit;
}
public function hasFeature(Organization $organization, string $feature): bool
{
$features = config('frontdesk.plans.'.$this->planKey($organization).'.features', []);
return in_array($feature, $features, true);
}
public function proPriceMinor(): int
{
return (int) config('frontdesk.plans.pro.price_minor', 7900);
}
}