Files
ladill-queue/app/Services/Qms/PlanService.php
T
isaaccladandCursor 0770faaa9f
Deploy Ladill Queue / deploy (push) Successful in 42s
Add Queue Pro billing, renewal, and scheduler.
Organizations can upgrade from wallet with plan expiry enforcement and nightly qms:pro-renew charges.

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

63 lines
1.6 KiB
PHP

<?php
namespace App\Services\Qms;
use App\Models\Organization;
use Carbon\Carbon;
class PlanService
{
public function planKey(Organization $organization): string
{
$settings = $organization->settings ?? [];
$plan = (string) ($settings['plan'] ?? 'free');
if ($plan === 'pro' && ! empty($settings['plan_expires_at'])) {
if (Carbon::parse($settings['plan_expires_at'])->isPast()) {
return 'free';
}
}
return array_key_exists($plan, config('qms.plans', [])) ? $plan : 'free';
}
public function plan(Organization $organization): string
{
return $this->planKey($organization);
}
public function isPro(Organization $organization): bool
{
return $this->planKey($organization) === 'pro';
}
public function maxBranches(Organization $organization): ?int
{
return config('qms.plans.'.$this->planKey($organization).'.max_branches');
}
public function maxQueues(Organization $organization): ?int
{
return config('qms.plans.'.$this->planKey($organization).'.max_queues');
}
public function canAddBranch(Organization $organization, int $currentCount): bool
{
$max = $this->maxBranches($organization);
return $max === null || $currentCount < $max;
}
public function canAddQueue(Organization $organization, int $currentCount): bool
{
$max = $this->maxQueues($organization);
return $max === null || $currentCount < $max;
}
public function proPriceMinor(): int
{
return (int) config('qms.plans.pro.price_minor', 9900);
}
}