Bill Frontdesk Pro and Enterprise per branch.
Deploy Ladill Frontdesk / deploy (push) Successful in 47s

Pro is GHS 990/branch/mo and Enterprise is GHS 1990/branch/mo, with the
Care-style branch selector UI, self-serve Enterprise checkout, and renewal
charges scaled to billed branches.
This commit is contained in:
isaacclad
2026-07-16 00:42:34 +00:00
parent 3bbd1a8ddd
commit bdbf572f19
9 changed files with 295 additions and 61 deletions
@@ -26,6 +26,7 @@ class ProController extends Controller
? Carbon::parse($settings['plan_expires_at'])
: null;
$planKey = $plans->planKey($organization);
$branchCount = max(1, $plans->activeBranchCount($organization));
return view('frontdesk.pro.index', [
'organization' => $organization,
@@ -34,10 +35,17 @@ class ProController extends Controller
'isEnterprise' => $planKey === 'enterprise',
'hasPaidPlan' => $plans->hasPaidPlan($organization),
'canManage' => $canManage,
'proPriceMinor' => $plans->proPriceMinor(),
'proPricePerBranchMinor' => $plans->proPricePerBranchMinor(),
'proPriceMinor' => $plans->proPriceTotalMinor($organization),
'enterprisePricePerBranchMinor' => $plans->enterprisePricePerBranchMinor(),
'enterprisePriceMinor' => $plans->enterprisePriceMinor($organization),
'branchCount' => $branchCount,
'canSubscribeEnterprise' => $plans->canSubscribeEnterprise($organization),
'enterpriseMinBranches' => (int) config('frontdesk.enterprise.min_branches', 1),
'prepaidMonths' => (array) config('frontdesk.prepaid_months', [6, 12, 24]),
'currency' => (string) config('billing.currency', 'GHS'),
'planExpiresAt' => $expiresAt,
'billedBranches' => (int) ($settings['billed_branches'] ?? $branchCount),
'salesUrl' => ladill_platform_url('contact-sales'),
]);
}
@@ -52,20 +60,60 @@ class ProController extends Controller
->with('success', 'Your organization already has an active paid plan.');
}
if ($plans->isEnterprise($organization)) {
return redirect()->route('frontdesk.pro.index')
->with('success', 'Your organization is on Frontdesk Enterprise.');
}
$validated = $request->validate([
'branches' => ['required', 'integer', 'min:1', 'max:999'],
]);
$branches = $plans->resolveCheckoutBranches($organization, (int) $validated['branches']);
$amountMinor = $plans->priceForBranches('pro', $branches);
return $this->chargeMonthlyWallet(
$organization,
$billing,
$plans->proPriceMinor(),
$amountMinor,
'pro',
'frontdesk_pro',
'frontdesk-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
'Ladill Frontdesk Pro — monthly subscription',
'Ladill Frontdesk Pro — '.$branches.' branch(es) monthly',
'Welcome to Frontdesk Pro — active for one month.',
$branches,
);
}
public function subscribeEnterprise(Request $request, PlanService $plans, BillingClient $billing): RedirectResponse
{
$this->authorizeAbility($request, 'settings.manage');
$organization = $this->organization($request);
if ($plans->hasPaidPlan($organization)) {
return redirect()->route('frontdesk.pro.index')
->with('success', 'Your organization already has an active paid plan.');
}
if (! $plans->canSubscribeEnterprise($organization)) {
$min = (int) config('frontdesk.enterprise.min_branches', 1);
return redirect()->route('frontdesk.pro.index')
->with('error', "Enterprise requires at least {$min} active branch. Add a branch or contact sales.");
}
$validated = $request->validate([
'branches' => ['required', 'integer', 'min:1', 'max:999'],
]);
$branches = $plans->resolveCheckoutBranches($organization, (int) $validated['branches']);
$amountMinor = $plans->priceForBranches('enterprise', $branches);
return $this->chargeMonthlyWallet(
$organization,
$billing,
$amountMinor,
'enterprise',
'frontdesk_enterprise',
'frontdesk-enterprise-'.$organization->id.'-'.now()->format('Y-m-d-His'),
'Ladill Frontdesk Enterprise — '.$branches.' branch(es) monthly',
'Welcome to Frontdesk Enterprise — active for one month.',
$branches,
);
}
@@ -73,27 +121,41 @@ class ProController extends Controller
{
$this->authorizeAbility($request, 'settings.manage');
$validated = $request->validate([
'plan' => ['required', 'in:pro'],
'plan' => ['required', 'in:pro,enterprise'],
'months' => ['required', 'integer', 'in:6,12,24'],
'branches' => ['required', 'integer', 'min:1', 'max:999'],
]);
$organization = $this->organization($request);
if ($plans->hasPaidPlan($organization) || $plans->isEnterprise($organization)) {
if ($plans->hasPaidPlan($organization)) {
return redirect()->route('frontdesk.pro.index')
->with('success', 'Your organization already has an active plan.');
}
$plan = $validated['plan'];
$months = (int) $validated['months'];
$amountMinor = $plans->proPriceMinor() * $months;
if ($plan === 'enterprise' && ! $plans->canSubscribeEnterprise($organization)) {
$min = (int) config('frontdesk.enterprise.min_branches', 1);
return redirect()->route('frontdesk.pro.index')
->with('error', "Enterprise requires at least {$min} active branch.");
}
$branches = $plans->resolveCheckoutBranches($organization, (int) $validated['branches']);
$amountMinor = $plans->priceForBranches($plan, $branches) * $months;
try {
$checkout = $billing->initiatePlanCheckout(
$organization->owner_ref,
'pro',
$plan,
$months,
$amountMinor,
route('frontdesk.pro.paystack.callback'),
['organization_id' => $organization->id],
[
'organization_id' => $organization->id,
'billed_branches' => $branches,
],
);
} catch (\Throwable) {
return redirect()->route('frontdesk.pro.index')
@@ -140,11 +202,18 @@ class ProController extends Controller
abort(403);
}
$plan = (string) ($result['plan'] ?? 'pro');
$months = (int) ($result['months'] ?? 0);
$this->activatePrepaidPlan($organization, 'pro', $months);
$branches = isset($metadata['billed_branches'])
? (int) $metadata['billed_branches']
: max(1, $plans->activeBranchCount($organization));
$this->activatePrepaidPlan($organization, $plan, $months, $branches);
$label = $plan === 'enterprise' ? 'Frontdesk Enterprise' : 'Frontdesk Pro';
return redirect()->route('frontdesk.pro.index')
->with('success', "Frontdesk Pro is active for {$months} months.");
->with('success', "{$label} is active for {$months} months.");
}
private function chargeMonthlyWallet(
@@ -156,6 +225,7 @@ class ProController extends Controller
string $reference,
string $description,
string $successMessage,
int $billedBranches,
): RedirectResponse {
try {
if (! $billing->canAfford($organization->owner_ref, $priceMinor)) {
@@ -184,23 +254,29 @@ 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('frontdesk.pro.period_days', 30))
->toIso8601String();
unset($settings['plan_renewal_error']);
unset($settings['plan_renewal_error'], $settings['enterprise_billed_branches']);
$organization->update(['settings' => $settings]);
return redirect()->route('frontdesk.pro.index')->with('success', $successMessage);
}
private function activatePrepaidPlan(Organization $organization, string $plan, int $months): void
{
private function activatePrepaidPlan(
Organization $organization,
string $plan,
int $months,
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();
unset($settings['plan_renewal_error']);
unset($settings['plan_renewal_error'], $settings['enterprise_billed_branches']);
$organization->update(['settings' => $settings]);
}
}