Tighten Care free tier and bill Pro/Enterprise per branch.
Deploy Ladill Care / deploy (push) Successful in 29s
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:
@@ -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([
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user