Add branch seat selector on Care plan checkout.
Deploy Ladill Care / deploy (push) Successful in 40s
Deploy Ladill Care / deploy (push) Successful in 40s
Let operators pick how many branches to bill next to the monthly/prepaid toggles so Pro and Enterprise totals and charges use branches × per-branch rate.
This commit is contained in:
@@ -62,12 +62,17 @@ class ProController extends Controller
|
||||
->with('success', 'Your organization already has an active paid plan.');
|
||||
}
|
||||
|
||||
$branches = max(1, $plans->activeBranchCount($organization));
|
||||
$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->proPriceTotalMinor($organization),
|
||||
$amountMinor,
|
||||
'pro',
|
||||
'care_pro',
|
||||
'care-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
|
||||
@@ -94,12 +99,17 @@ class ProController extends Controller
|
||||
->with('error', "Enterprise requires at least {$min} active branch. Contact sales for custom multi-site onboarding.");
|
||||
}
|
||||
|
||||
$branches = max(1, $plans->activeBranchCount($organization));
|
||||
$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',
|
||||
'care_enterprise',
|
||||
'care-enterprise-'.$organization->id.'-'.now()->format('Y-m-d-His'),
|
||||
@@ -115,6 +125,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);
|
||||
@@ -133,8 +144,8 @@ class ProController extends Controller
|
||||
->with('error', "Enterprise requires at least {$min} active branch.");
|
||||
}
|
||||
|
||||
$branches = max(1, $plans->activeBranchCount($organization));
|
||||
$monthlyMinor = $plans->monthlyPriceMinor($organization, $plan);
|
||||
$branches = $plans->resolveCheckoutBranches($organization, (int) $validated['branches']);
|
||||
$monthlyMinor = $plans->priceForBranches($plan, $branches);
|
||||
$amountMinor = $monthlyMinor * $months;
|
||||
|
||||
try {
|
||||
|
||||
@@ -117,20 +117,38 @@ class PlanService
|
||||
/** 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();
|
||||
return $this->priceForBranches('pro', $this->activeBranchCount($organization));
|
||||
}
|
||||
|
||||
/** Total monthly amount for Enterprise = active branches × per-branch rate (min 1). */
|
||||
public function enterprisePriceMinor(Organization $organization): int
|
||||
{
|
||||
return max(1, $this->activeBranchCount($organization)) * $this->enterprisePricePerBranchMinor();
|
||||
return $this->priceForBranches('enterprise', $this->activeBranchCount($organization));
|
||||
}
|
||||
|
||||
public function monthlyPriceMinor(Organization $organization, string $plan): int
|
||||
{
|
||||
return $plan === 'enterprise'
|
||||
? $this->enterprisePriceMinor($organization)
|
||||
: $this->proPriceTotalMinor($organization);
|
||||
return $this->priceForBranches($plan, $this->activeBranchCount($organization));
|
||||
}
|
||||
|
||||
/** Fixed branch count × per-branch rate (for checkout when the user picks branch 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, $requested);
|
||||
// Don't under-bill vs sites already configured in the account.
|
||||
$active = max(1, $this->activeBranchCount($organization));
|
||||
|
||||
return max($branches, $active);
|
||||
}
|
||||
|
||||
public function canSubscribeEnterprise(Organization $organization): bool
|
||||
|
||||
@@ -1,26 +1,48 @@
|
||||
<x-app-layout title="Plans" heading="Care 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
|
||||
@if (session('error'))
|
||||
<div class="rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-800">{{ session('error') }}</div>
|
||||
@endif
|
||||
@if (session('upsell'))
|
||||
<div class="rounded-xl border border-indigo-200 bg-indigo-50 px-4 py-3 text-sm text-indigo-900">{{ session('upsell') }}</div>
|
||||
@endif
|
||||
|
||||
<div class="rounded-2xl border border-slate-200 bg-white px-6 py-5">
|
||||
<h1 class="text-2xl font-bold text-slate-900">Choose your Care 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 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>
|
||||
@@ -29,7 +51,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">
|
||||
@@ -57,8 +92,9 @@
|
||||
:monthly-display="$proPerBranch"
|
||||
monthly-suffix="/branch/mo"
|
||||
/>
|
||||
<p class="mt-1 text-sm text-slate-500" x-show="billing === 'monthly'">
|
||||
Unlimited branches · {{ $branchCount }} active = {{ $currency }} {{ $proTotal }}/mo
|
||||
<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>Everything in Free</li>
|
||||
@@ -83,15 +119,18 @@
|
||||
@elseif ($canManage)
|
||||
<form x-show="billing === 'monthly'" method="post" action="{{ route('care.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 wallet'"></button>
|
||||
</form>
|
||||
<template x-for="months in @js($prepaidMonths)" :key="months">
|
||||
<form x-show="billing == months" method="post" action="{{ route('care.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
|
||||
@@ -110,8 +149,9 @@
|
||||
monthly-suffix="/branch/mo"
|
||||
dark
|
||||
/>
|
||||
<p class="mt-1 text-sm text-slate-300" x-show="billing === 'monthly'">
|
||||
Unlimited branches · {{ $branchCount }} active = {{ $currency }} {{ $enterpriseTotal }}/mo
|
||||
<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>
|
||||
@@ -136,17 +176,18 @@
|
||||
@if ($canSubscribeEnterprise)
|
||||
<form x-show="billing === 'monthly'" method="post" action="{{ route('care.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 wallet'"></button>
|
||||
</form>
|
||||
<template x-for="months in @js($prepaidMonths)" :key="'ent-' + months">
|
||||
<form x-show="billing == months" method="post" action="{{ route('care.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
|
||||
|
||||
@@ -129,11 +129,12 @@ class CareProTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->post(route('care.pro.subscribe-enterprise'))
|
||||
->post(route('care.pro.subscribe-enterprise'), ['branches' => 1])
|
||||
->assertRedirect(route('care.pro.index'))
|
||||
->assertSessionHas('success');
|
||||
|
||||
$this->assertSame('enterprise', $this->organization->fresh()->settings['plan']);
|
||||
$this->assertSame(1, $this->organization->fresh()->settings['billed_branches']);
|
||||
}
|
||||
|
||||
public function test_sidebar_shows_upgrade_to_pro_on_dashboard(): void
|
||||
@@ -185,13 +186,35 @@ class CareProTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->post(route('care.pro.subscribe'))
|
||||
->post(route('care.pro.subscribe'), ['branches' => 1])
|
||||
->assertRedirect(route('care.pro.index'))
|
||||
->assertSessionHas('success');
|
||||
|
||||
$settings = $this->organization->fresh()->settings;
|
||||
$this->assertSame('pro', $settings['plan']);
|
||||
$this->assertSame('wallet_monthly', $settings['billing_method']);
|
||||
$this->assertSame(1, $settings['billed_branches']);
|
||||
}
|
||||
|
||||
public function test_subscribe_charges_selected_branch_count(): void
|
||||
{
|
||||
$perBranch = (int) config('care.plans.pro.price_minor_per_branch');
|
||||
|
||||
Http::fake([
|
||||
'billing.test/can-afford*' => Http::response(['affordable' => true]),
|
||||
'billing.test/debit' => function ($request) use ($perBranch) {
|
||||
$this->assertSame($perBranch * 3, (int) $request['amount_minor']);
|
||||
|
||||
return Http::response(['ok' => true]);
|
||||
},
|
||||
]);
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->post(route('care.pro.subscribe'), ['branches' => 3])
|
||||
->assertRedirect(route('care.pro.index'))
|
||||
->assertSessionHas('success');
|
||||
|
||||
$this->assertSame(3, $this->organization->fresh()->settings['billed_branches']);
|
||||
}
|
||||
|
||||
public function test_subscribe_prepaid_redirects_to_paystack(): void
|
||||
@@ -207,8 +230,29 @@ class CareProTest extends TestCase
|
||||
->post(route('care.pro.subscribe-prepaid'), [
|
||||
'plan' => 'pro',
|
||||
'months' => 12,
|
||||
'branches' => 2,
|
||||
])
|
||||
->assertRedirect('https://checkout.paystack.com/test');
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
if (! str_contains($request->url(), 'plan-checkout')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$perBranch = (int) config('care.plans.pro.price_minor_per_branch');
|
||||
|
||||
return (int) $request['amount_minor'] === $perBranch * 2 * 12
|
||||
&& (int) ($request['metadata']['billed_branches'] ?? 0) === 2;
|
||||
});
|
||||
}
|
||||
|
||||
public function test_plans_page_shows_branch_selector(): void
|
||||
{
|
||||
$this->actingAs($this->owner)
|
||||
->get(route('care.pro.index'))
|
||||
->assertOk()
|
||||
->assertSee('Branches')
|
||||
->assertSee('x-model.number="branches"', false);
|
||||
}
|
||||
|
||||
public function test_paystack_callback_activates_prepaid_pro(): void
|
||||
|
||||
Reference in New Issue
Block a user