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.'); ->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( return $this->chargeMonthlyWallet(
$organization, $organization,
$billing, $billing,
$plans->proPriceMinor($organization), $amountMinor,
'pro', 'pro',
'queue_pro', 'queue_pro',
'queue-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'), '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.', '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."); ->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( return $this->chargeMonthlyWallet(
$organization, $organization,
$billing, $billing,
$plans->enterprisePriceMinor($organization), $amountMinor,
'enterprise', 'enterprise',
'queue_enterprise', 'queue_enterprise',
'queue-enterprise-'.$organization->id.'-'.now()->format('Y-m-d-His'), '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.', 'Welcome to Queue Enterprise — active for one month.',
$plans->activeBranchCount($organization), $branches,
); );
} }
@@ -116,6 +130,7 @@ class ProController extends Controller
$validated = $request->validate([ $validated = $request->validate([
'plan' => ['required', 'in:pro,enterprise'], 'plan' => ['required', 'in:pro,enterprise'],
'months' => ['required', 'integer', 'in:6,12,24'], 'months' => ['required', 'integer', 'in:6,12,24'],
'branches' => ['required', 'integer', 'min:1', 'max:999'],
]); ]);
$organization = $this->organization($request); $organization = $this->organization($request);
@@ -134,11 +149,8 @@ class ProController extends Controller
->with('error', "Enterprise billing requires at least {$min} active branches."); ->with('error', "Enterprise billing requires at least {$min} active branches.");
} }
$monthlyMinor = $plan === 'enterprise' $branches = $plans->resolveCheckoutBranches($organization, (int) $validated['branches']);
? $plans->enterprisePriceMinor($organization) $amountMinor = $plans->priceForBranches($plan, $branches) * $months;
: $plans->proPriceMinor($organization);
$amountMinor = $monthlyMinor * $months;
$branches = $plans->activeBranchCount($organization);
$metadata = [ $metadata = [
'organization_id' => $organization->id, 'organization_id' => $organization->id,
+20 -5
View File
@@ -84,9 +84,7 @@ class PlanService
public function proPriceMinor(Organization $organization): int public function proPriceMinor(Organization $organization): int
{ {
$branches = max(1, $this->activeBranchCount($organization)); return $this->priceForBranches('pro', $this->activeBranchCount($organization));
return $branches * $this->proPricePerBranchMinor();
} }
public function enterprisePricePerBranchMinor(): int public function enterprisePricePerBranchMinor(): int
@@ -96,9 +94,26 @@ class PlanService
public function enterprisePriceMinor(Organization $organization): int 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 public function canSubscribeEnterprise(Organization $organization): bool
+52 -27
View File
@@ -1,12 +1,30 @@
<x-app-layout title="Plans" heading="Queue plans"> <x-app-layout title="Plans" heading="Queue plans">
@php @php
$proPerBranch = number_format($proPricePerBranchMinor / 100, 0); $proPerBranch = number_format($proPricePerBranchMinor / 100, 0);
$proTotal = number_format($proPriceMinor / 100, 0);
$enterprisePerBranch = number_format($enterprisePricePerBranchMinor / 100, 0); $enterprisePerBranch = number_format($enterprisePricePerBranchMinor / 100, 0);
$enterpriseTotal = number_format($enterprisePriceMinor / 100, 0); $initialBranches = max(1, (int) $branchCount);
@endphp @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')) @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> <div class="rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">{{ session('success') }}</div>
@endif @endif
@@ -18,10 +36,10 @@
<h1 class="text-2xl font-bold text-slate-900">Choose your Queue plan</h1> <h1 class="text-2xl font-bold text-slate-900">Choose your Queue plan</h1>
<p class="mt-1 text-sm text-slate-600"> <p class="mt-1 text-sm text-slate-600">
Pay monthly from your Ladill wallet, or prepay 6/12/24 months via Paystack. 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. 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> </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'" <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="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> 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="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> class="rounded-lg px-3 py-1.5 text-sm font-medium transition">{{ $months }} months · Paystack</button>
@endforeach @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> </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>
<div class="grid gap-5 lg:grid-cols-3"> <div class="grid gap-5 lg:grid-cols-3">
@@ -55,16 +86,12 @@
<x-plan-tier-price <x-plan-tier-price
:currency="$currency" :currency="$currency"
:monthly-minor="$proPricePerBranchMinor" :monthly-minor="$proPricePerBranchMinor"
:prepaid-minor="$proPriceMinor"
:monthly-display="$proPerBranch" :monthly-display="$proPerBranch"
monthly-suffix="/branch/mo" monthly-suffix="/branch/mo"
/> />
<p class="mt-1 text-sm text-slate-500" x-show="billing === 'monthly'"> <p class="mt-1 text-sm text-slate-500">
@if ($branchCount > 0) <span x-text="branchCount()"></span> branch(es) × {{ $currency }} {{ $proPerBranch }}/branch
{{ $branchCount }} active {{ str('branch')->plural($branchCount) }} = {{ $currency }} {{ $proTotal }}/mo = {{ $currency }} <span x-text="fmt(proTotal())"></span>/mo
@else
Per-branch billing
@endif
</p> </p>
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-700"> <ul class="mt-5 flex-1 space-y-2 text-sm text-slate-700">
<li>Advanced routing rules</li> <li>Advanced routing rules</li>
@@ -88,17 +115,18 @@
@elseif ($canManage) @elseif ($canManage)
<form x-show="billing === 'monthly'" method="post" action="{{ route('qms.pro.subscribe') }}"> <form x-show="billing === 'monthly'" method="post" action="{{ route('qms.pro.subscribe') }}">
@csrf @csrf
<button class="btn-primary w-full"> <input type="hidden" name="branches" :value="branchCount()">
Upgrade to Pro {{ $currency }} {{ $proTotal }}/mo wallet <button type="submit" class="btn-primary w-full"
</button> x-text="'Upgrade to Pro — {{ $currency }} ' + fmt(proTotal()) + '/mo'"></button>
</form> </form>
<template x-for="months in @js($prepaidMonths)" :key="months"> <template x-for="months in @js($prepaidMonths)" :key="months">
<form x-show="billing == months" method="post" action="{{ route('qms.pro.subscribe-prepaid') }}"> <form x-show="billing == months" method="post" action="{{ route('qms.pro.subscribe-prepaid') }}">
@csrf @csrf
<input type="hidden" name="plan" value="pro"> <input type="hidden" name="plan" value="pro">
<input type="hidden" name="months" :value="months"> <input type="hidden" name="months" :value="months">
<input type="hidden" name="branches" :value="branchCount()">
<button type="submit" class="btn-primary w-full" <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> </form>
</template> </template>
@else @else
@@ -113,17 +141,13 @@
<x-plan-tier-price <x-plan-tier-price
:currency="$currency" :currency="$currency"
:monthly-minor="$enterprisePricePerBranchMinor" :monthly-minor="$enterprisePricePerBranchMinor"
:prepaid-minor="$enterprisePriceMinor"
:monthly-display="$enterprisePerBranch" :monthly-display="$enterprisePerBranch"
monthly-suffix="/branch/mo" monthly-suffix="/branch/mo"
dark dark
/> />
<p class="mt-1 text-sm text-slate-300" x-show="billing === 'monthly'"> <p class="mt-1 text-sm text-slate-300">
@if ($branchCount > 0) <span x-text="branchCount()"></span> branch(es) × {{ $currency }} {{ $enterprisePerBranch }}/branch
{{ $branchCount }} active {{ str('branch')->plural($branchCount) }} = {{ $currency }} {{ $enterpriseTotal }}/mo = {{ $currency }} <span x-text="fmt(entTotal())"></span>/mo
@else
Per-branch billing for multi-site
@endif
</p> </p>
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-200"> <ul class="mt-5 flex-1 space-y-2 text-sm text-slate-200">
<li>Everything in Pro</li> <li>Everything in Pro</li>
@@ -147,17 +171,18 @@
@if ($canSubscribeEnterprise) @if ($canSubscribeEnterprise)
<form x-show="billing === 'monthly'" method="post" action="{{ route('qms.pro.subscribe-enterprise') }}"> <form x-show="billing === 'monthly'" method="post" action="{{ route('qms.pro.subscribe-enterprise') }}">
@csrf @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"> <input type="hidden" name="branches" :value="branchCount()">
Upgrade {{ $currency }} {{ $enterpriseTotal }}/mo wallet <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"
</button> x-text="'Upgrade — {{ $currency }} ' + fmt(entTotal()) + '/mo'"></button>
</form> </form>
<template x-for="months in @js($prepaidMonths)" :key="'ent-' + months"> <template x-for="months in @js($prepaidMonths)" :key="'ent-' + months">
<form x-show="billing == months" method="post" action="{{ route('qms.pro.subscribe-prepaid') }}"> <form x-show="billing == months" method="post" action="{{ route('qms.pro.subscribe-prepaid') }}">
@csrf @csrf
<input type="hidden" name="plan" value="enterprise"> <input type="hidden" name="plan" value="enterprise">
<input type="hidden" name="months" :value="months"> <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" <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> </form>
</template> </template>
@else @else
+26 -3
View File
@@ -54,6 +54,8 @@ class QmsProTest extends TestCase
->assertSee('GHS '.$proPerBranch) ->assertSee('GHS '.$proPerBranch)
->assertSee('GHS '.$enterprisePerBranch) ->assertSee('GHS '.$enterprisePerBranch)
->assertSee('/branch/mo') ->assertSee('/branch/mo')
->assertSee('Branches')
->assertSee('Minimum is your current active branch count')
->assertSee('Upgrade to Pro') ->assertSee('Upgrade to Pro')
->assertSee('Enterprise'); ->assertSee('Enterprise');
} }
@@ -109,7 +111,7 @@ class QmsProTest extends TestCase
]); ]);
$this->actingAs($this->owner) $this->actingAs($this->owner)
->post(route('qms.pro.subscribe')) ->post(route('qms.pro.subscribe'), ['branches' => 1])
->assertRedirect(route('qms.pro.index')) ->assertRedirect(route('qms.pro.index'))
->assertSessionHas('success'); ->assertSessionHas('success');
@@ -118,6 +120,26 @@ class QmsProTest extends TestCase
$this->assertSame(1, $settings['pro_billed_branches']); $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 public function test_subscribe_enterprise_requires_multiple_branches(): void
{ {
Http::fake([ Http::fake([
@@ -126,7 +148,7 @@ class QmsProTest extends TestCase
]); ]);
$this->actingAs($this->owner) $this->actingAs($this->owner)
->post(route('qms.pro.subscribe-enterprise')) ->post(route('qms.pro.subscribe-enterprise'), ['branches' => 1])
->assertRedirect(route('qms.pro.index')) ->assertRedirect(route('qms.pro.index'))
->assertSessionHas('error'); ->assertSessionHas('error');
@@ -138,7 +160,7 @@ class QmsProTest extends TestCase
]); ]);
$this->actingAs($this->owner) $this->actingAs($this->owner)
->post(route('qms.pro.subscribe-enterprise')) ->post(route('qms.pro.subscribe-enterprise'), ['branches' => 2])
->assertRedirect(route('qms.pro.index')) ->assertRedirect(route('qms.pro.index'))
->assertSessionHas('success'); ->assertSessionHas('success');
@@ -259,6 +281,7 @@ class QmsProTest extends TestCase
->post(route('qms.pro.subscribe-prepaid'), [ ->post(route('qms.pro.subscribe-prepaid'), [
'plan' => 'pro', 'plan' => 'pro',
'months' => 12, 'months' => 12,
'branches' => 1,
]) ])
->assertRedirect('https://checkout.paystack.test/pay'); ->assertRedirect('https://checkout.paystack.test/pay');
} }