Tighten Care free tier and bill Pro/Enterprise per branch.
Deploy Ladill Care / deploy (push) Successful in 29s

Free keeps core records, appointments, and basic workflows; Pro unlocks lab, pharmacy, billing, and Queue. Both paid tiers bill per branch with unlimited branches. Enterprise adds multi-dept workflows, analytics, AI-assisted healthcare integration, and priority support (not Afia).
This commit is contained in:
isaacclad
2026-07-15 14:14:35 +00:00
parent 78be5c803d
commit f9aa4a679f
19 changed files with 414 additions and 193 deletions
@@ -52,8 +52,11 @@ class BranchController extends Controller
->where('organization_id', $organization->id)
->count();
if (! app(PlanService::class)->canAddBranch($organization, $currentCount)) {
return back()->withInput()->with('error', 'Your plan allows one branch. Upgrade to Care Pro for unlimited branches.');
$plans = app(PlanService::class);
if (! $plans->canAddBranch($organization, $currentCount)) {
return redirect()
->route('care.pro.index')
->with('upsell', $plans->branchLimitMessage($organization));
}
$validated = $request->validate([
+35 -34
View File
@@ -26,8 +26,9 @@ class ProController extends Controller
? Carbon::parse($settings['plan_expires_at'])
: null;
$planKey = $plans->planKey($organization);
$branchCount = $plans->activeBranchCount($organization);
$enterprisePrice = $plans->enterprisePriceMinor($organization);
$branchCount = max(1, $plans->activeBranchCount($organization));
$proTotal = $plans->proPriceTotalMinor($organization);
$enterpriseTotal = $plans->enterprisePriceMinor($organization);
return view('care.pro.index', [
'organization' => $organization,
@@ -36,16 +37,17 @@ class ProController extends Controller
'isEnterprise' => $planKey === 'enterprise',
'hasPaidPlan' => $plans->hasPaidPlan($organization),
'canManage' => $canManage,
'proPriceMinor' => $plans->proPriceMinor(),
'proPricePerBranchMinor' => $plans->proPricePerBranchMinor(),
'proPriceMinor' => $proTotal,
'enterprisePricePerBranchMinor' => $plans->enterprisePricePerBranchMinor(),
'enterprisePriceMinor' => $enterprisePrice,
'enterprisePriceMinor' => $enterpriseTotal,
'branchCount' => $branchCount,
'canSubscribeEnterprise' => $plans->canSubscribeEnterprise($organization),
'enterpriseMinBranches' => (int) config('care.enterprise.min_branches', 2),
'enterpriseMinBranches' => (int) config('care.enterprise.min_branches', 1),
'prepaidMonths' => (array) config('care.prepaid_months', [6, 12, 24]),
'currency' => (string) config('billing.currency', 'GHS'),
'planExpiresAt' => $expiresAt,
'enterpriseBilledBranches' => (int) ($settings['enterprise_billed_branches'] ?? $branchCount),
'billedBranches' => (int) ($settings['billed_branches'] ?? $branchCount),
'salesUrl' => ladill_platform_url('contact-sales'),
]);
}
@@ -60,15 +62,18 @@ class ProController extends Controller
->with('success', 'Your organization already has an active paid plan.');
}
$branches = max(1, $plans->activeBranchCount($organization));
return $this->chargeMonthlyWallet(
$organization,
$billing,
$plans->proPriceMinor(),
$plans->proPriceTotalMinor($organization),
'pro',
'care_pro',
'care-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
'Ladill Care Pro — monthly subscription',
'Ladill Care Pro — '.$branches.' branch(es) monthly',
'Welcome to Care Pro — active for one month.',
$branches,
);
}
@@ -83,12 +88,14 @@ class ProController extends Controller
}
if (! $plans->canSubscribeEnterprise($organization)) {
$min = (int) config('care.enterprise.min_branches', 2);
$min = (int) config('care.enterprise.min_branches', 1);
return redirect()->route('care.pro.index')
->with('error', "Enterprise billing requires at least {$min} active branches. Add another branch or choose Pro for a single site.");
->with('error', "Enterprise requires at least {$min} active branch. Contact sales for custom multi-site onboarding.");
}
$branches = max(1, $plans->activeBranchCount($organization));
return $this->chargeMonthlyWallet(
$organization,
$billing,
@@ -96,9 +103,9 @@ class ProController extends Controller
'enterprise',
'care_enterprise',
'care-enterprise-'.$organization->id.'-'.now()->format('Y-m-d-His'),
'Ladill Care Enterprise — monthly subscription',
'Ladill Care Enterprise — '.$branches.' branch(es) monthly',
'Welcome to Care Enterprise — active for one month.',
$plans->activeBranchCount($organization),
$branches,
);
}
@@ -120,17 +127,15 @@ class ProController extends Controller
$months = (int) $validated['months'];
if ($plan === 'enterprise' && ! $plans->canSubscribeEnterprise($organization)) {
$min = (int) config('care.enterprise.min_branches', 2);
$min = (int) config('care.enterprise.min_branches', 1);
return redirect()->route('care.pro.index')
->with('error', "Enterprise billing requires at least {$min} active branches.");
->with('error', "Enterprise requires at least {$min} active branch.");
}
$monthlyMinor = $plan === 'enterprise'
? $plans->enterprisePriceMinor($organization)
: $plans->proPriceMinor();
$branches = max(1, $plans->activeBranchCount($organization));
$monthlyMinor = $plans->monthlyPriceMinor($organization, $plan);
$amountMinor = $monthlyMinor * $months;
$branches = $plan === 'enterprise' ? $plans->activeBranchCount($organization) : null;
try {
$checkout = $billing->initiatePlanCheckout(
@@ -139,10 +144,10 @@ class ProController extends Controller
$months,
$amountMinor,
route('care.pro.paystack.callback'),
array_filter([
[
'organization_id' => $organization->id,
'enterprise_billed_branches' => $branches,
], static fn ($v) => $v !== null),
'billed_branches' => $branches,
],
);
} catch (\Throwable) {
return redirect()->route('care.pro.index')
@@ -191,9 +196,9 @@ class ProController extends Controller
$plan = (string) ($result['plan'] ?? 'pro');
$months = (int) ($result['months'] ?? 0);
$branches = isset($metadata['enterprise_billed_branches'])
? (int) $metadata['enterprise_billed_branches']
: null;
$branches = isset($metadata['billed_branches'])
? (int) $metadata['billed_branches']
: max(1, $plans->activeBranchCount($organization));
$this->activatePrepaidPlan($organization, $plan, $months, $branches);
@@ -212,7 +217,7 @@ class ProController extends Controller
string $reference,
string $description,
string $successMessage,
?int $enterpriseBranches = null,
int $billedBranches,
): RedirectResponse {
try {
if (! $billing->canAfford($organization->owner_ref, $priceMinor)) {
@@ -241,13 +246,11 @@ class ProController extends Controller
$settings['plan'] = $plan;
$settings['auto_renew'] = true;
$settings['billing_method'] = 'wallet_monthly';
$settings['billed_branches'] = $billedBranches;
$settings['plan_expires_at'] = now()
->addDays((int) config('care.pro.period_days', 30))
->toIso8601String();
if ($enterpriseBranches !== null) {
$settings['enterprise_billed_branches'] = $enterpriseBranches;
}
unset($settings['plan_renewal_error']);
unset($settings['plan_renewal_error'], $settings['enterprise_billed_branches']);
$organization->update(['settings' => $settings]);
return redirect()->route('care.pro.index')->with('success', $successMessage);
@@ -257,17 +260,15 @@ class ProController extends Controller
Organization $organization,
string $plan,
int $months,
?int $enterpriseBranches = null,
int $billedBranches,
): void {
$settings = $organization->settings ?? [];
$settings['plan'] = $plan;
$settings['auto_renew'] = false;
$settings['billing_method'] = 'paystack_prepaid';
$settings['billed_branches'] = $billedBranches;
$settings['plan_expires_at'] = now()->addMonths($months)->toIso8601String();
if ($enterpriseBranches !== null) {
$settings['enterprise_billed_branches'] = $enterpriseBranches;
}
unset($settings['plan_renewal_error']);
unset($settings['plan_renewal_error'], $settings['enterprise_billed_branches']);
$organization->update(['settings' => $settings]);
}
}
@@ -8,6 +8,7 @@ use App\Models\Branch;
use App\Services\Care\AppointmentPatientNotifier;
use App\Services\Care\AuditLogger;
use App\Services\Care\CarePermissions;
use App\Services\Care\PlanService;
use App\Services\Messaging\MessagingCredentialsService;
use App\Services\Queue\QueueClient;
use App\Support\OrganizationBranding;
@@ -30,10 +31,13 @@ class SettingsController extends Controller
->where('organization_id', $organization->id)
->count();
$plans = app(PlanService::class);
return view('care.settings.edit', [
'organization' => $organization,
'canManage' => $canManage,
'branchCount' => $branchCount,
'canUseQueueIntegration' => $plans->canUseQueueIntegration($organization),
'messagingSmsReady' => $credential->hasValidSms(),
'messagingEmailReady' => $credential->hasValidBird(),
'facilityTypes' => [
@@ -50,6 +54,7 @@ class SettingsController extends Controller
$this->authorizeAbility($request, 'settings.manage');
$organization = $this->organization($request);
$owner = $this->ownerRef($request);
$plans = app(PlanService::class);
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
@@ -68,7 +73,16 @@ class SettingsController extends Controller
$settings['onboarded'] = true;
$settings['facility_type'] = $validated['facility_type'];
// Queue integration is Pro/Enterprise only — free plans cannot enable it.
$wantsQueue = $request->boolean('queue_integration_enabled');
if ($wantsQueue && ! $plans->canUseQueueIntegration($organization)) {
return redirect()
->route('care.pro.index')
->with('upsell', 'Ladill Queue integration is part of Care Pro. Upgrade to connect service queues and counters.');
}
if (! $plans->canUseQueueIntegration($organization)) {
$wantsQueue = false;
}
$settings['queue_integration_enabled'] = $wantsQueue;
$settings[AppointmentPatientNotifier::SETTING_BOOKED_SMS] = $request->boolean('notify_appointment_booked_sms');
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Http\Middleware;
use App\Services\Care\OrganizationResolver;
use App\Services\Care\PlanService;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Blocks free-plan accounts from Pro modules (lab, pharmacy, billing, Queue integration).
*/
class EnsurePaidPlan
{
public function __construct(
protected OrganizationResolver $organizations,
protected PlanService $plans,
) {}
public function handle(Request $request, Closure $next): Response
{
$user = $request->user();
if (! $user) {
return $next($request);
}
$organization = $this->organizations->resolveForUser($user);
if (! $organization || $this->plans->hasPaidPlan($organization)) {
return $next($request);
}
if ($request->expectsJson() || $request->ajax()) {
return response()->json([
'message' => 'This feature requires Care Pro or Enterprise.',
'upgrade_url' => route('care.pro.index'),
], 402);
}
return redirect()
->route('care.pro.index')
->with('upsell', 'Lab, pharmacy, billing, and Queue integration are part of Care Pro. Upgrade to unlock them.');
}
}
+1 -1
View File
@@ -22,7 +22,7 @@ class AppServiceProvider extends ServiceProvider
{
Event::listen(ServiceEventOccurred::class, PlatformServiceEventListener::class);
View::composer('partials.sidebar', function ($view) {
View::composer(['partials.sidebar', 'partials.topbar-desktop-widgets', 'partials.afia', 'components.app-layout'], function ($view) {
/** @var User|null $user */
$user = auth()->user();
$planKey = 'free';
+59 -6
View File
@@ -42,6 +42,17 @@ class PlanService
return in_array($this->planKey($organization), ['pro', 'enterprise'], true);
}
/** Lab, pharmacy, billing, and Ladill Queue integration require Pro or Enterprise. */
public function canUseProModules(Organization $organization): bool
{
return $this->hasPaidPlan($organization);
}
public function canUseQueueIntegration(Organization $organization): bool
{
return $this->hasPaidPlan($organization);
}
public function activeBranchCount(Organization $organization): int
{
return Branch::query()
@@ -53,8 +64,9 @@ class PlanService
public function maxBranches(Organization $organization): ?int
{
$plan = config('care.plans.'.$this->planKey($organization));
$max = $plan['max_branches'] ?? null;
return $plan['max_branches'] ?? null;
return $max === null ? null : (int) $max;
}
public function canAddBranch(Organization $organization, int $currentCount): bool
@@ -64,25 +76,66 @@ class PlanService
return $max === null || $currentCount < $max;
}
public function branchLimitMessage(Organization $organization): string
{
$max = $this->maxBranches($organization);
$key = $this->planKey($organization);
if ($key === 'free') {
return 'Your Free plan allows 1 branch. Upgrade to Care Pro for unlimited branches (billed per branch).';
}
if ($key === 'pro' && $max !== null) {
return "Your Pro plan allows up to {$max} branches (billed per branch).";
}
return 'Branch limit reached for your current plan.';
}
public function proPricePerBranchMinor(): int
{
return (int) config(
'care.plans.pro.price_minor_per_branch',
config('care.plans.pro.price_minor', 199000),
);
}
/** @deprecated Prefer proPricePerBranchMinor() — Pro is billed per branch. */
public function proPriceMinor(): int
{
return (int) config('care.plans.pro.price_minor', 19900);
return $this->proPricePerBranchMinor();
}
public function enterprisePricePerBranchMinor(): int
{
return (int) config('care.plans.enterprise.price_minor_per_branch', 49900);
return (int) config(
'care.plans.enterprise.price_minor_per_branch',
config('care.plans.enterprise.price_minor', 499000),
);
}
/** Total monthly amount for Pro = active branches × per-branch rate (min 1). */
public function proPriceTotalMinor(Organization $organization): int
{
return max(1, $this->activeBranchCount($organization)) * $this->proPricePerBranchMinor();
}
/** Total monthly amount for Enterprise = active branches × per-branch rate (min 1). */
public function enterprisePriceMinor(Organization $organization): int
{
$branches = max(1, $this->activeBranchCount($organization));
return max(1, $this->activeBranchCount($organization)) * $this->enterprisePricePerBranchMinor();
}
return $branches * $this->enterprisePricePerBranchMinor();
public function monthlyPriceMinor(Organization $organization, string $plan): int
{
return $plan === 'enterprise'
? $this->enterprisePriceMinor($organization)
: $this->proPriceTotalMinor($organization);
}
public function canSubscribeEnterprise(Organization $organization): bool
{
return $this->activeBranchCount($organization) >= (int) config('care.enterprise.min_branches', 2);
// Enterprise is a feature tier (not branch-gated). min_branches defaults to 1.
return $this->activeBranchCount($organization) >= (int) config('care.enterprise.min_branches', 1);
}
}
+7 -10
View File
@@ -50,9 +50,8 @@ class ProRenewalService
$settings = $organization->settings ?? [];
$plan = (string) ($settings['plan'] ?? 'free');
$isEnterprise = $plan === 'enterprise';
$price = $isEnterprise
? $this->plans->enterprisePriceMinor($organization)
: $this->plans->proPriceMinor();
$branches = max(1, $this->plans->activeBranchCount($organization));
$price = $this->plans->monthlyPriceMinor($organization, $plan);
$reference = ($isEnterprise ? 'care-enterprise-' : 'care-pro-')
.$organization->id.'-'.now()->format('YmdHis');
@@ -63,8 +62,8 @@ class ProRenewalService
$isEnterprise ? 'care_enterprise_renewal' : 'care_pro_renewal',
$reference,
$isEnterprise
? 'Ladill Care Enterprise — monthly renewal'
: 'Ladill Care Pro — monthly renewal',
? 'Ladill Care Enterprise — '.$branches.' branch(es) monthly renewal'
: 'Ladill Care Pro — '.$branches.' branch(es) monthly renewal',
);
} catch (\Throwable) {
$charged = false;
@@ -73,13 +72,11 @@ class ProRenewalService
if ($charged) {
$settings['plan'] = $plan;
$settings['auto_renew'] = true;
$settings['billed_branches'] = $branches;
$settings['plan_expires_at'] = now()
->addDays((int) config('care.pro.period_days', 30))
->toIso8601String();
if ($isEnterprise) {
$settings['enterprise_billed_branches'] = $this->plans->activeBranchCount($organization);
}
unset($settings['plan_renewal_error']);
unset($settings['plan_renewal_error'], $settings['enterprise_billed_branches']);
$organization->update(['settings' => $settings]);
return;
@@ -89,7 +86,7 @@ class ProRenewalService
$graceEnd = $expires->copy()->addDays((int) config('care.pro.grace_days', 3));
if ($graceEnd->isPast()) {
$settings['plan'] = 'free';
unset($settings['plan_expires_at'], $settings['enterprise_billed_branches']);
unset($settings['plan_expires_at'], $settings['billed_branches'], $settings['enterprise_billed_branches']);
$settings['plan_renewal_error'] = 'Suspended after failed renewal.';
} else {
$settings['plan_renewal_error'] = 'Renewal failed — top up your wallet.';