Add Queue Enterprise billing and visible upgrade CTAs for all roles.
Deploy Ladill Queue / deploy (push) Successful in 1m32s

Enterprise charges per active branch (GHS 299+) with wallet subscribe/renew; sidebar and dashboard upsell no longer gated behind settings.view.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-06-30 01:23:36 +00:00
co-authored by Cursor
parent 0770faaa9f
commit 165c7238fe
11 changed files with 382 additions and 83 deletions
+37 -1
View File
@@ -2,6 +2,7 @@
namespace App\Services\Qms;
use App\Models\Branch;
use App\Models\Organization;
use Carbon\Carbon;
@@ -12,7 +13,7 @@ class PlanService
$settings = $organization->settings ?? [];
$plan = (string) ($settings['plan'] ?? 'free');
if ($plan === 'pro' && ! empty($settings['plan_expires_at'])) {
if (in_array($plan, ['pro', 'enterprise'], true) && ! empty($settings['plan_expires_at'])) {
if (Carbon::parse($settings['plan_expires_at'])->isPast()) {
return 'free';
}
@@ -31,6 +32,24 @@ class PlanService
return $this->planKey($organization) === 'pro';
}
public function isEnterprise(Organization $organization): bool
{
return $this->planKey($organization) === 'enterprise';
}
public function hasPaidPlan(Organization $organization): bool
{
return in_array($this->planKey($organization), ['pro', 'enterprise'], true);
}
public function activeBranchCount(Organization $organization): int
{
return Branch::query()
->where('organization_id', $organization->id)
->where('is_active', true)
->count();
}
public function maxBranches(Organization $organization): ?int
{
return config('qms.plans.'.$this->planKey($organization).'.max_branches');
@@ -59,4 +78,21 @@ class PlanService
{
return (int) config('qms.plans.pro.price_minor', 9900);
}
public function enterprisePricePerBranchMinor(): int
{
return (int) config('qms.plans.enterprise.price_minor_per_branch', 29900);
}
public function enterprisePriceMinor(Organization $organization): int
{
$branches = max(1, $this->activeBranchCount($organization));
return $branches * $this->enterprisePricePerBranchMinor();
}
public function canSubscribeEnterprise(Organization $organization): bool
{
return $this->activeBranchCount($organization) >= (int) config('qms.enterprise.min_branches', 2);
}
}
+19 -8
View File
@@ -18,7 +18,7 @@ class ProRenewalService
public function dueOrganizations(): Collection
{
return Organization::query()
->where('settings->plan', 'pro')
->whereIn('settings->plan', ['pro', 'enterprise'])
->whereNotNull('settings->plan_expires_at')
->get()
->filter(fn (Organization $organization) => $this->isDue($organization));
@@ -27,7 +27,8 @@ class ProRenewalService
public function isDue(Organization $organization): bool
{
$settings = $organization->settings ?? [];
if (($settings['plan'] ?? '') !== 'pro') {
$plan = (string) ($settings['plan'] ?? 'free');
if (! in_array($plan, ['pro', 'enterprise'], true)) {
return false;
}
if (array_key_exists('auto_renew', $settings) && $settings['auto_renew'] === false) {
@@ -47,27 +48,37 @@ class ProRenewalService
}
$settings = $organization->settings ?? [];
$price = $this->plans->proPriceMinor();
$reference = 'queue-pro-'.$organization->id.'-'.now()->format('YmdHis');
$plan = (string) ($settings['plan'] ?? 'free');
$isEnterprise = $plan === 'enterprise';
$price = $isEnterprise
? $this->plans->enterprisePriceMinor($organization)
: $this->plans->proPriceMinor();
$reference = ($isEnterprise ? 'queue-enterprise-' : 'queue-pro-')
.$organization->id.'-'.now()->format('YmdHis');
try {
$charged = $this->billing->debit(
$organization->owner_ref,
$price,
'queue_pro_renewal',
$isEnterprise ? 'queue_enterprise_renewal' : 'queue_pro_renewal',
$reference,
'Ladill Queue Pro — monthly renewal',
$isEnterprise
? 'Ladill Queue Enterprise — monthly renewal'
: 'Ladill Queue Pro — monthly renewal',
);
} catch (\Throwable) {
$charged = false;
}
if ($charged) {
$settings['plan'] = 'pro';
$settings['plan'] = $plan;
$settings['auto_renew'] = true;
$settings['plan_expires_at'] = now()
->addDays((int) config('qms.pro.period_days', 30))
->toIso8601String();
if ($isEnterprise) {
$settings['enterprise_billed_branches'] = $this->plans->activeBranchCount($organization);
}
unset($settings['plan_renewal_error']);
$organization->update(['settings' => $settings]);
@@ -78,7 +89,7 @@ class ProRenewalService
$graceEnd = $expires->copy()->addDays((int) config('qms.pro.grace_days', 3));
if ($graceEnd->isPast()) {
$settings['plan'] = 'free';
unset($settings['plan_expires_at']);
unset($settings['plan_expires_at'], $settings['enterprise_billed_branches']);
$settings['plan_renewal_error'] = 'Suspended after failed renewal.';
} else {
$settings['plan_renewal_error'] = 'Renewal failed — top up your wallet.';