Deploy Ladill Care / deploy (push) Successful in 35s
Organizations can subscribe from wallet, expire correctly on free tier, and renew nightly via care:pro-renew. Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.3 KiB
PHP
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);
|
|
}
|
|
}
|