Files
ladill-care/app/Services/Care/PlanService.php
T
isaaccladandCursor 4bc485dfea
Deploy Ladill Care / deploy (push) Successful in 35s
Add Care Pro billing, renewal, and scheduler.
Organizations can subscribe from wallet, expire correctly on free tier, and renew nightly via care:pro-renew.

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

53 lines
1.3 KiB
PHP

<?php
namespace App\Services\Care;
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('care.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
{
$plan = config('care.plans.'.$this->planKey($organization));
return $plan['max_branches'] ?? null;
}
public function canAddBranch(Organization $organization, int $currentCount): bool
{
$max = $this->maxBranches($organization);
return $max === null || $currentCount < $max;
}
public function proPriceMinor(): int
{
return (int) config('care.plans.pro.price_minor', 19900);
}
}