Add branch count control to Queue plans page.
Deploy Ladill Queue / deploy (push) Successful in 33s

Match Care/Frontdesk: branches stepper next to billing period, live
totals, and checkout charges for the selected seat count.
This commit is contained in:
isaacclad
2026-07-16 09:36:36 +00:00
parent 8892316664
commit 8be3eaeb4b
4 changed files with 121 additions and 46 deletions
+23 -11
View File
@@ -67,16 +67,23 @@ class ProController extends Controller
->with('success', 'Your organization already has an active paid plan.');
}
$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($organization),
$amountMinor,
'pro',
'queue_pro',
'queue-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
'Ladill Queue Pro — monthly subscription',
'Ladill Queue Pro — '.$branches.' branch(es) monthly',
'Welcome to Queue Pro — active for one month.',
$plans->activeBranchCount($organization),
$branches,
);
}
@@ -97,16 +104,23 @@ class ProController extends Controller
->with('error', "Enterprise billing requires at least {$min} active branches. Add another branch or choose Pro for a single site.");
}
$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,
$plans->enterprisePriceMinor($organization),
$amountMinor,
'enterprise',
'queue_enterprise',
'queue-enterprise-'.$organization->id.'-'.now()->format('Y-m-d-His'),
'Ladill Queue Enterprise — monthly subscription',
'Ladill Queue Enterprise — '.$branches.' branch(es) monthly',
'Welcome to Queue Enterprise — active for one month.',
$plans->activeBranchCount($organization),
$branches,
);
}
@@ -116,6 +130,7 @@ class ProController extends Controller
$validated = $request->validate([
'plan' => ['required', 'in:pro,enterprise'],
'months' => ['required', 'integer', 'in:6,12,24'],
'branches' => ['required', 'integer', 'min:1', 'max:999'],
]);
$organization = $this->organization($request);
@@ -134,11 +149,8 @@ class ProController extends Controller
->with('error', "Enterprise billing requires at least {$min} active branches.");
}
$monthlyMinor = $plan === 'enterprise'
? $plans->enterprisePriceMinor($organization)
: $plans->proPriceMinor($organization);
$amountMinor = $monthlyMinor * $months;
$branches = $plans->activeBranchCount($organization);
$branches = $plans->resolveCheckoutBranches($organization, (int) $validated['branches']);
$amountMinor = $plans->priceForBranches($plan, $branches) * $months;
$metadata = [
'organization_id' => $organization->id,
+20 -5
View File
@@ -84,9 +84,7 @@ class PlanService
public function proPriceMinor(Organization $organization): int
{
$branches = max(1, $this->activeBranchCount($organization));
return $branches * $this->proPricePerBranchMinor();
return $this->priceForBranches('pro', $this->activeBranchCount($organization));
}
public function enterprisePricePerBranchMinor(): int
@@ -96,9 +94,26 @@ class PlanService
public function enterprisePriceMinor(Organization $organization): int
{
$branches = max(1, $this->activeBranchCount($organization));
return $this->priceForBranches('enterprise', $this->activeBranchCount($organization));
}
return $branches * $this->enterprisePricePerBranchMinor();
/** Fixed branch count × per-branch rate (checkout when the user picks seats). */
public function priceForBranches(string $plan, int $branches): int
{
$branches = max(1, $branches);
$rate = $plan === 'enterprise'
? $this->enterprisePricePerBranchMinor()
: $this->proPricePerBranchMinor();
return $branches * $rate;
}
public function resolveCheckoutBranches(Organization $organization, int $requested): int
{
$branches = max(1, min(999, $requested));
$active = max(1, $this->activeBranchCount($organization));
return max($branches, $active);
}
public function canSubscribeEnterprise(Organization $organization): bool
+52 -27
View File
@@ -1,12 +1,30 @@
<x-app-layout title="Plans" heading="Queue plans">
@php
$proPerBranch = number_format($proPricePerBranchMinor / 100, 0);
$proTotal = number_format($proPriceMinor / 100, 0);
$enterprisePerBranch = number_format($enterprisePricePerBranchMinor / 100, 0);
$enterpriseTotal = number_format($enterprisePriceMinor / 100, 0);
$initialBranches = max(1, (int) $branchCount);
@endphp
<div class="mx-auto max-w-5xl space-y-6" x-data="{ billing: 'monthly' }">
<div class="mx-auto max-w-5xl space-y-6"
x-data="{
billing: 'monthly',
branches: {{ $initialBranches }},
proPerBranch: {{ (int) $proPricePerBranchMinor }},
entPerBranch: {{ (int) $enterprisePricePerBranchMinor }},
minBranches: {{ $initialBranches }},
proTotal() {
return this.proPerBranch * Math.max(this.minBranches, parseInt(this.branches) || this.minBranches);
},
entTotal() {
return this.entPerBranch * Math.max(this.minBranches, parseInt(this.branches) || this.minBranches);
},
branchCount() {
return Math.max(this.minBranches, parseInt(this.branches) || this.minBranches);
},
fmt(minor) {
return (minor / 100).toLocaleString();
}
}">
@if (session('success'))
<div class="rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">{{ session('success') }}</div>
@endif
@@ -18,10 +36,10 @@
<h1 class="text-2xl font-bold text-slate-900">Choose your Queue plan</h1>
<p class="mt-1 text-sm text-slate-600">
Pay monthly from your Ladill wallet, or prepay 6/12/24 months via Paystack.
Pro and Enterprise are billed per active branch.
Pro and Enterprise are billed per branch set how many branches to include below.
Enterprise includes a one-time setup fee <a href="{{ $salesUrl }}" class="font-medium text-indigo-600 hover:text-indigo-800" target="_blank" rel="noopener">contact sales</a> for onboarding.
</p>
<div class="mt-4 flex flex-wrap gap-2">
<div class="mt-4 flex flex-wrap items-center gap-2">
<button type="button" @click="billing = 'monthly'"
:class="billing === 'monthly' ? 'bg-indigo-600 text-white' : 'bg-slate-100 text-slate-700 hover:bg-slate-200'"
class="rounded-lg px-3 py-1.5 text-sm font-medium transition">Monthly · wallet</button>
@@ -30,7 +48,20 @@
:class="billing === '{{ $months }}' ? 'bg-indigo-600 text-white' : 'bg-slate-100 text-slate-700 hover:bg-slate-200'"
class="rounded-lg px-3 py-1.5 text-sm font-medium transition">{{ $months }} months · Paystack</button>
@endforeach
<label class="inline-flex items-center gap-2 rounded-lg border border-slate-200 bg-slate-50 px-3 py-1.5 text-sm text-slate-700">
<span class="font-medium text-slate-600">Branches</span>
<input type="number"
min="{{ $initialBranches }}"
max="999"
x-model.number="branches"
@change="if (branches < minBranches) branches = minBranches"
class="w-16 rounded-md border-slate-300 py-0.5 text-center text-sm focus:border-indigo-500 focus:ring-indigo-500">
</label>
</div>
<p class="mt-2 text-xs text-slate-500">
Minimum is your current active branch count ({{ $initialBranches }}). Totals update live for Pro and Enterprise.
</p>
</div>
<div class="grid gap-5 lg:grid-cols-3">
@@ -55,16 +86,12 @@
<x-plan-tier-price
:currency="$currency"
:monthly-minor="$proPricePerBranchMinor"
:prepaid-minor="$proPriceMinor"
:monthly-display="$proPerBranch"
monthly-suffix="/branch/mo"
/>
<p class="mt-1 text-sm text-slate-500" x-show="billing === 'monthly'">
@if ($branchCount > 0)
{{ $branchCount }} active {{ str('branch')->plural($branchCount) }} = {{ $currency }} {{ $proTotal }}/mo
@else
Per-branch billing
@endif
<p class="mt-1 text-sm text-slate-500">
<span x-text="branchCount()"></span> branch(es) × {{ $currency }} {{ $proPerBranch }}/branch
= {{ $currency }} <span x-text="fmt(proTotal())"></span>/mo
</p>
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-700">
<li>Advanced routing rules</li>
@@ -88,17 +115,18 @@
@elseif ($canManage)
<form x-show="billing === 'monthly'" method="post" action="{{ route('qms.pro.subscribe') }}">
@csrf
<button class="btn-primary w-full">
Upgrade to Pro {{ $currency }} {{ $proTotal }}/mo wallet
</button>
<input type="hidden" name="branches" :value="branchCount()">
<button type="submit" class="btn-primary w-full"
x-text="'Upgrade to Pro — {{ $currency }} ' + fmt(proTotal()) + '/mo'"></button>
</form>
<template x-for="months in @js($prepaidMonths)" :key="months">
<form x-show="billing == months" method="post" action="{{ route('qms.pro.subscribe-prepaid') }}">
@csrf
<input type="hidden" name="plan" value="pro">
<input type="hidden" name="months" :value="months">
<input type="hidden" name="branches" :value="branchCount()">
<button type="submit" class="btn-primary w-full"
x-text="'Pay ' + months + ' months via Paystack — {{ $currency }} ' + ({{ $proPriceMinor }} * months / 100).toLocaleString()"></button>
x-text="'Pay ' + months + ' months via Paystack — {{ $currency }} ' + fmt(proTotal() * months)"></button>
</form>
</template>
@else
@@ -113,17 +141,13 @@
<x-plan-tier-price
:currency="$currency"
:monthly-minor="$enterprisePricePerBranchMinor"
:prepaid-minor="$enterprisePriceMinor"
:monthly-display="$enterprisePerBranch"
monthly-suffix="/branch/mo"
dark
/>
<p class="mt-1 text-sm text-slate-300" x-show="billing === 'monthly'">
@if ($branchCount > 0)
{{ $branchCount }} active {{ str('branch')->plural($branchCount) }} = {{ $currency }} {{ $enterpriseTotal }}/mo
@else
Per-branch billing for multi-site
@endif
<p class="mt-1 text-sm text-slate-300">
<span x-text="branchCount()"></span> branch(es) × {{ $currency }} {{ $enterprisePerBranch }}/branch
= {{ $currency }} <span x-text="fmt(entTotal())"></span>/mo
</p>
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-200">
<li>Everything in Pro</li>
@@ -147,17 +171,18 @@
@if ($canSubscribeEnterprise)
<form x-show="billing === 'monthly'" method="post" action="{{ route('qms.pro.subscribe-enterprise') }}">
@csrf
<button class="w-full rounded-xl bg-amber-400 px-4 py-2.5 text-sm font-semibold text-slate-900 hover:bg-amber-300">
Upgrade {{ $currency }} {{ $enterpriseTotal }}/mo wallet
</button>
<input type="hidden" name="branches" :value="branchCount()">
<button type="submit" class="w-full rounded-xl bg-amber-400 px-4 py-2.5 text-sm font-semibold text-slate-900 hover:bg-amber-300"
x-text="'Upgrade — {{ $currency }} ' + fmt(entTotal()) + '/mo'"></button>
</form>
<template x-for="months in @js($prepaidMonths)" :key="'ent-' + months">
<form x-show="billing == months" method="post" action="{{ route('qms.pro.subscribe-prepaid') }}">
@csrf
<input type="hidden" name="plan" value="enterprise">
<input type="hidden" name="months" :value="months">
<input type="hidden" name="branches" :value="branchCount()">
<button type="submit" class="w-full rounded-xl bg-amber-400 px-4 py-2.5 text-sm font-semibold text-slate-900 hover:bg-amber-300"
x-text="'Pay ' + months + ' months via Paystack — {{ $currency }} ' + ({{ $enterprisePriceMinor }} * months / 100).toLocaleString()"></button>
x-text="'Pay ' + months + ' months via Paystack — {{ $currency }} ' + fmt(entTotal() * months)"></button>
</form>
</template>
@else
+26 -3
View File
@@ -54,6 +54,8 @@ class QmsProTest extends TestCase
->assertSee('GHS '.$proPerBranch)
->assertSee('GHS '.$enterprisePerBranch)
->assertSee('/branch/mo')
->assertSee('Branches')
->assertSee('Minimum is your current active branch count')
->assertSee('Upgrade to Pro')
->assertSee('Enterprise');
}
@@ -109,7 +111,7 @@ class QmsProTest extends TestCase
]);
$this->actingAs($this->owner)
->post(route('qms.pro.subscribe'))
->post(route('qms.pro.subscribe'), ['branches' => 1])
->assertRedirect(route('qms.pro.index'))
->assertSessionHas('success');
@@ -118,6 +120,26 @@ class QmsProTest extends TestCase
$this->assertSame(1, $settings['pro_billed_branches']);
}
public function test_subscribe_pro_uses_selected_branch_count(): void
{
Http::fake([
'billing.test/can-afford*' => Http::response(['affordable' => true]),
'billing.test/debit' => function ($request) {
$expected = 3 * (int) config('qms.plans.pro.price_minor_per_branch');
$this->assertSame($expected, (int) $request['amount_minor']);
return Http::response(['ok' => true]);
},
]);
$this->actingAs($this->owner)
->post(route('qms.pro.subscribe'), ['branches' => 3])
->assertRedirect(route('qms.pro.index'))
->assertSessionHas('success');
$this->assertSame(3, $this->organization->fresh()->settings['pro_billed_branches']);
}
public function test_subscribe_enterprise_requires_multiple_branches(): void
{
Http::fake([
@@ -126,7 +148,7 @@ class QmsProTest extends TestCase
]);
$this->actingAs($this->owner)
->post(route('qms.pro.subscribe-enterprise'))
->post(route('qms.pro.subscribe-enterprise'), ['branches' => 1])
->assertRedirect(route('qms.pro.index'))
->assertSessionHas('error');
@@ -138,7 +160,7 @@ class QmsProTest extends TestCase
]);
$this->actingAs($this->owner)
->post(route('qms.pro.subscribe-enterprise'))
->post(route('qms.pro.subscribe-enterprise'), ['branches' => 2])
->assertRedirect(route('qms.pro.index'))
->assertSessionHas('success');
@@ -259,6 +281,7 @@ class QmsProTest extends TestCase
->post(route('qms.pro.subscribe-prepaid'), [
'plan' => 'pro',
'months' => 12,
'branches' => 1,
])
->assertRedirect('https://checkout.paystack.test/pay');
}