Organizations can subscribe from wallet, expire correctly on free tier, and renew nightly via care:pro-renew. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,22 +3,37 @@
|
||||
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 (string) data_get($organization->settings, 'plan', 'free');
|
||||
return $this->planKey($organization);
|
||||
}
|
||||
|
||||
public function isPro(Organization $organization): bool
|
||||
{
|
||||
return $this->plan($organization) === 'pro';
|
||||
return $this->planKey($organization) === 'pro';
|
||||
}
|
||||
|
||||
public function maxBranches(Organization $organization): ?int
|
||||
{
|
||||
$plan = config('care.plans.'.$this->plan($organization));
|
||||
$plan = config('care.plans.'.$this->planKey($organization));
|
||||
|
||||
return $plan['max_branches'] ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user