Limit Pro to 3 branches and leave Business unlimited.
Deploy Ladill POS / deploy (push) Successful in 2m15s
Deploy Ladill POS / deploy (push) Successful in 2m15s
Enforce plan location caps in SubscriptionService, surface upgrade copy on plans and branch settings, and cover the limits in tests.
This commit is contained in:
@@ -111,6 +111,32 @@ class SubscriptionService
|
||||
return PosLocation::owned($ownerRef)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Max branches for the account's plan. null = unlimited.
|
||||
*/
|
||||
public function maxLocations(User $user): ?int
|
||||
{
|
||||
if (! $this->gatingActive()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$key = $this->planKey($user);
|
||||
|
||||
if ($key === 'free') {
|
||||
return (int) config('pos.free.max_locations', 1);
|
||||
}
|
||||
|
||||
if ($key === ProSubscription::PLAN_ENTERPRISE) {
|
||||
$max = config('pos.plans.enterprise.max_locations');
|
||||
|
||||
return $max === null ? null : (int) $max;
|
||||
}
|
||||
|
||||
$max = config('pos.plans.pro.max_locations', 3);
|
||||
|
||||
return $max === null ? null : (int) $max;
|
||||
}
|
||||
|
||||
public function canUseMultiLocation(User $user): bool
|
||||
{
|
||||
return $this->isPro($user);
|
||||
@@ -118,11 +144,29 @@ class SubscriptionService
|
||||
|
||||
public function canAddLocation(User $user, string $ownerRef): bool
|
||||
{
|
||||
if (! $this->canUseMultiLocation($user)) {
|
||||
return $this->locationCount($ownerRef) < (int) config('pos.free.max_locations', 1);
|
||||
$max = $this->maxLocations($user);
|
||||
|
||||
if ($max === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return $this->locationCount($ownerRef) < $max;
|
||||
}
|
||||
|
||||
public function locationLimitMessage(User $user): string
|
||||
{
|
||||
$key = $this->planKey($user);
|
||||
$max = $this->maxLocations($user);
|
||||
|
||||
if ($key === 'free') {
|
||||
return 'Your Free plan allows 1 branch. Upgrade to Pro for up to 3 branches, or Business for unlimited.';
|
||||
}
|
||||
|
||||
if ($key === ProSubscription::PLAN_PRO && $max !== null) {
|
||||
return "Your Pro plan allows up to {$max} branches. Upgrade to Business for unlimited locations.";
|
||||
}
|
||||
|
||||
return 'Branch limit reached for your current plan.';
|
||||
}
|
||||
|
||||
public function canManageTeam(User $user): bool
|
||||
|
||||
Reference in New Issue
Block a user