Add Care Enterprise per-branch billing and Paystack prepaid plans.
Deploy Ladill Care / deploy (push) Successful in 1m46s
Deploy Ladill Care / deploy (push) Successful in 1m46s
Mirrors Queue with GHS 499/branch Enterprise and 6/12/24 month Paystack checkout. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Care;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
|
||||
use App\Models\Organization;
|
||||
use App\Services\Billing\BillingClient;
|
||||
use App\Services\Care\CarePermissions;
|
||||
use App\Services\Care\PlanService;
|
||||
@@ -24,21 +25,28 @@ class ProController extends Controller
|
||||
$expiresAt = ! empty($settings['plan_expires_at'])
|
||||
? Carbon::parse($settings['plan_expires_at'])
|
||||
: null;
|
||||
$planKey = $plans->planKey($organization);
|
||||
$branchCount = $plans->activeBranchCount($organization);
|
||||
$enterprisePrice = $plans->enterprisePriceMinor($organization);
|
||||
|
||||
return view('care.pro.index', [
|
||||
'organization' => $organization,
|
||||
'isPro' => $plans->isPro($organization),
|
||||
'planKey' => $planKey,
|
||||
'isPro' => $planKey === 'pro',
|
||||
'isEnterprise' => $planKey === 'enterprise',
|
||||
'hasPaidPlan' => $plans->hasPaidPlan($organization),
|
||||
'canManage' => $canManage,
|
||||
'priceMinor' => $plans->proPriceMinor(),
|
||||
'proPriceMinor' => $plans->proPriceMinor(),
|
||||
'enterprisePricePerBranchMinor' => $plans->enterprisePricePerBranchMinor(),
|
||||
'enterprisePriceMinor' => $enterprisePrice,
|
||||
'branchCount' => $branchCount,
|
||||
'canSubscribeEnterprise' => $plans->canSubscribeEnterprise($organization),
|
||||
'enterpriseMinBranches' => (int) config('care.enterprise.min_branches', 2),
|
||||
'prepaidMonths' => (array) config('care.prepaid_months', [6, 12, 24]),
|
||||
'currency' => (string) config('billing.currency', 'GHS'),
|
||||
'planExpiresAt' => $expiresAt,
|
||||
'proFeatures' => [
|
||||
'Unlimited branches',
|
||||
'Full clinical workflows',
|
||||
'Laboratory & pharmacy modules',
|
||||
'Finance reports & audit exports',
|
||||
'Queue integration',
|
||||
],
|
||||
'enterpriseBilledBranches' => (int) ($settings['enterprise_billed_branches'] ?? $branchCount),
|
||||
'salesUrl' => ladill_platform_url('contact-sales'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -47,25 +55,177 @@ class ProController extends Controller
|
||||
$this->authorizeAbility($request, 'settings.manage');
|
||||
$organization = $this->organization($request);
|
||||
|
||||
if ($plans->isPro($organization)) {
|
||||
if ($plans->hasPaidPlan($organization)) {
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('success', 'Your organization is already on Care Pro.');
|
||||
->with('success', 'Your organization already has an active paid plan.');
|
||||
}
|
||||
|
||||
$priceMinor = $plans->proPriceMinor();
|
||||
return $this->chargeMonthlyWallet(
|
||||
$organization,
|
||||
$billing,
|
||||
$plans->proPriceMinor(),
|
||||
'pro',
|
||||
'care_pro',
|
||||
'care-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
|
||||
'Ladill Care Pro — monthly subscription',
|
||||
'Welcome to Care Pro — active for one month.',
|
||||
);
|
||||
}
|
||||
|
||||
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('care.pro.index')
|
||||
->with('success', 'Your organization already has an active paid plan.');
|
||||
}
|
||||
|
||||
if (! $plans->canSubscribeEnterprise($organization)) {
|
||||
$min = (int) config('care.enterprise.min_branches', 2);
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
return $this->chargeMonthlyWallet(
|
||||
$organization,
|
||||
$billing,
|
||||
$plans->enterprisePriceMinor($organization),
|
||||
'enterprise',
|
||||
'care_enterprise',
|
||||
'care-enterprise-'.$organization->id.'-'.now()->format('Y-m-d-His'),
|
||||
'Ladill Care Enterprise — monthly subscription',
|
||||
'Welcome to Care Enterprise — active for one month.',
|
||||
$plans->activeBranchCount($organization),
|
||||
);
|
||||
}
|
||||
|
||||
public function subscribePrepaid(Request $request, PlanService $plans, BillingClient $billing): RedirectResponse
|
||||
{
|
||||
$this->authorizeAbility($request, 'settings.manage');
|
||||
$validated = $request->validate([
|
||||
'plan' => ['required', 'in:pro,enterprise'],
|
||||
'months' => ['required', 'integer', 'in:6,12,24'],
|
||||
]);
|
||||
|
||||
$organization = $this->organization($request);
|
||||
if ($plans->hasPaidPlan($organization)) {
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('success', 'Your organization already has an active paid plan.');
|
||||
}
|
||||
|
||||
$plan = $validated['plan'];
|
||||
$months = (int) $validated['months'];
|
||||
|
||||
if ($plan === 'enterprise' && ! $plans->canSubscribeEnterprise($organization)) {
|
||||
$min = (int) config('care.enterprise.min_branches', 2);
|
||||
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('error', "Enterprise billing requires at least {$min} active branches.");
|
||||
}
|
||||
|
||||
$monthlyMinor = $plan === 'enterprise'
|
||||
? $plans->enterprisePriceMinor($organization)
|
||||
: $plans->proPriceMinor();
|
||||
$amountMinor = $monthlyMinor * $months;
|
||||
$branches = $plan === 'enterprise' ? $plans->activeBranchCount($organization) : null;
|
||||
|
||||
try {
|
||||
$checkout = $billing->initiatePlanCheckout(
|
||||
$organization->owner_ref,
|
||||
$plan,
|
||||
$months,
|
||||
$amountMinor,
|
||||
route('care.pro.paystack.callback'),
|
||||
array_filter([
|
||||
'organization_id' => $organization->id,
|
||||
'enterprise_billed_branches' => $branches,
|
||||
], static fn ($v) => $v !== null),
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('error', 'Could not start Paystack checkout. Please try again.');
|
||||
}
|
||||
|
||||
$url = trim((string) ($checkout['checkout_url'] ?? ''));
|
||||
if ($url === '') {
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('error', 'Paystack did not return a checkout URL.');
|
||||
}
|
||||
|
||||
return redirect()->away($url);
|
||||
}
|
||||
|
||||
public function paystackCallback(Request $request, BillingClient $billing, PlanService $plans): RedirectResponse
|
||||
{
|
||||
$reference = (string) $request->query('reference', '');
|
||||
if ($reference === '') {
|
||||
return redirect()->route('care.pro.index')->with('error', 'Missing payment reference.');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $billing->verifyPlanCheckout($reference);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('error', 'Could not verify payment. Contact support with reference: '.$reference);
|
||||
}
|
||||
|
||||
if (! ($result['paid'] ?? false)) {
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('error', 'Payment was not completed.');
|
||||
}
|
||||
|
||||
$metadata = (array) ($result['metadata'] ?? []);
|
||||
$organization = Organization::query()->find((int) ($metadata['organization_id'] ?? 0));
|
||||
if (! $organization) {
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('error', 'Organization not found for this payment.');
|
||||
}
|
||||
|
||||
$this->authorizeAbility($request, 'settings.manage');
|
||||
if ($this->organization($request)->id !== $organization->id) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$plan = (string) ($result['plan'] ?? 'pro');
|
||||
$months = (int) ($result['months'] ?? 0);
|
||||
$branches = isset($metadata['enterprise_billed_branches'])
|
||||
? (int) $metadata['enterprise_billed_branches']
|
||||
: null;
|
||||
|
||||
$this->activatePrepaidPlan($organization, $plan, $months, $branches);
|
||||
|
||||
$label = $plan === 'enterprise' ? 'Care Enterprise' : 'Care Pro';
|
||||
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('success', "{$label} is active for {$months} months.");
|
||||
}
|
||||
|
||||
private function chargeMonthlyWallet(
|
||||
Organization $organization,
|
||||
BillingClient $billing,
|
||||
int $priceMinor,
|
||||
string $plan,
|
||||
string $billingSource,
|
||||
string $reference,
|
||||
string $description,
|
||||
string $successMessage,
|
||||
?int $enterpriseBranches = null,
|
||||
): RedirectResponse {
|
||||
try {
|
||||
if (! $billing->canAfford($organization->owner_ref, $priceMinor)) {
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade to Pro.');
|
||||
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade.');
|
||||
}
|
||||
|
||||
$charged = $billing->debit(
|
||||
$organization->owner_ref,
|
||||
$priceMinor,
|
||||
'care_pro',
|
||||
'care-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
|
||||
'Ladill Care Pro — monthly subscription',
|
||||
$billingSource,
|
||||
$reference,
|
||||
$description,
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('care.pro.index')
|
||||
@@ -74,19 +234,40 @@ class ProController extends Controller
|
||||
|
||||
if (! $charged) {
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade to Pro.');
|
||||
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade.');
|
||||
}
|
||||
|
||||
$settings = $organization->settings ?? [];
|
||||
$settings['plan'] = 'pro';
|
||||
$settings['plan'] = $plan;
|
||||
$settings['auto_renew'] = true;
|
||||
$settings['billing_method'] = 'wallet_monthly';
|
||||
$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']);
|
||||
$organization->update(['settings' => $settings]);
|
||||
|
||||
return redirect()->route('care.pro.index')
|
||||
->with('success', 'Welcome to Care Pro — active for one month.');
|
||||
return redirect()->route('care.pro.index')->with('success', $successMessage);
|
||||
}
|
||||
|
||||
private function activatePrepaidPlan(
|
||||
Organization $organization,
|
||||
string $plan,
|
||||
int $months,
|
||||
?int $enterpriseBranches = null,
|
||||
): void {
|
||||
$settings = $organization->settings ?? [];
|
||||
$settings['plan'] = $plan;
|
||||
$settings['auto_renew'] = false;
|
||||
$settings['billing_method'] = 'paystack_prepaid';
|
||||
$settings['plan_expires_at'] = now()->addMonths($months)->toIso8601String();
|
||||
if ($enterpriseBranches !== null) {
|
||||
$settings['enterprise_billed_branches'] = $enterpriseBranches;
|
||||
}
|
||||
unset($settings['plan_renewal_error']);
|
||||
$organization->update(['settings' => $settings]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,28 @@ class AppServiceProvider extends ServiceProvider
|
||||
View::composer('partials.sidebar', function ($view) {
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$planKey = 'free';
|
||||
$isPro = false;
|
||||
$isEnterprise = false;
|
||||
$hasPaidPlan = false;
|
||||
|
||||
if ($user) {
|
||||
$organization = app(OrganizationResolver::class)->resolveForUser($user);
|
||||
if ($organization) {
|
||||
$isPro = app(PlanService::class)->isPro($organization);
|
||||
$plans = app(PlanService::class);
|
||||
$planKey = $plans->planKey($organization);
|
||||
$isPro = $planKey === 'pro';
|
||||
$isEnterprise = $planKey === 'enterprise';
|
||||
$hasPaidPlan = $plans->hasPaidPlan($organization);
|
||||
}
|
||||
}
|
||||
|
||||
$view->with('isPro', $isPro);
|
||||
$view->with([
|
||||
'planKey' => $planKey,
|
||||
'isPro' => $isPro,
|
||||
'isEnterprise' => $isEnterprise,
|
||||
'hasPaidPlan' => $hasPaidPlan,
|
||||
]);
|
||||
});
|
||||
|
||||
View::composer(['partials.topbar'], function ($view) {
|
||||
|
||||
@@ -61,4 +61,48 @@ class BillingClient
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $metadata
|
||||
* @return array{checkout_url: string, reference: string}
|
||||
*/
|
||||
public function initiatePlanCheckout(
|
||||
string $publicId,
|
||||
string $plan,
|
||||
int $months,
|
||||
int $amountMinor,
|
||||
string $returnUrl,
|
||||
array $metadata = [],
|
||||
): array {
|
||||
$res = Http::withToken($this->token())->acceptJson()->timeout(15)->post($this->base().'/plan-checkout', [
|
||||
'user' => $publicId,
|
||||
'app' => (string) config('billing.service', 'care'),
|
||||
'plan' => $plan,
|
||||
'months' => $months,
|
||||
'amount_minor' => $amountMinor,
|
||||
'return_url' => $returnUrl,
|
||||
'metadata' => $metadata,
|
||||
]);
|
||||
$res->throw();
|
||||
|
||||
return [
|
||||
'checkout_url' => (string) $res->json('checkout_url'),
|
||||
'reference' => (string) $res->json('reference'),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function verifyPlanCheckout(string $reference): array
|
||||
{
|
||||
$res = Http::withToken($this->token())->acceptJson()->timeout(15)->post($this->base().'/plan-checkout/verify', [
|
||||
'reference' => $reference,
|
||||
]);
|
||||
|
||||
if ($res->status() === 422) {
|
||||
return ['paid' => false, 'error' => $res->json('error')];
|
||||
}
|
||||
$res->throw();
|
||||
|
||||
return $res->json();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services\Care;
|
||||
|
||||
use App\Models\Branch;
|
||||
use App\Models\Organization;
|
||||
use Carbon\Carbon;
|
||||
|
||||
@@ -12,7 +13,7 @@ class PlanService
|
||||
$settings = $organization->settings ?? [];
|
||||
$plan = (string) ($settings['plan'] ?? 'free');
|
||||
|
||||
if ($plan === 'pro' && ! empty($settings['plan_expires_at'])) {
|
||||
if (in_array($plan, ['pro', 'enterprise'], true) && ! empty($settings['plan_expires_at'])) {
|
||||
if (Carbon::parse($settings['plan_expires_at'])->isPast()) {
|
||||
return 'free';
|
||||
}
|
||||
@@ -31,6 +32,24 @@ class PlanService
|
||||
return $this->planKey($organization) === 'pro';
|
||||
}
|
||||
|
||||
public function isEnterprise(Organization $organization): bool
|
||||
{
|
||||
return $this->planKey($organization) === 'enterprise';
|
||||
}
|
||||
|
||||
public function hasPaidPlan(Organization $organization): bool
|
||||
{
|
||||
return in_array($this->planKey($organization), ['pro', 'enterprise'], true);
|
||||
}
|
||||
|
||||
public function activeBranchCount(Organization $organization): int
|
||||
{
|
||||
return Branch::query()
|
||||
->where('organization_id', $organization->id)
|
||||
->where('is_active', true)
|
||||
->count();
|
||||
}
|
||||
|
||||
public function maxBranches(Organization $organization): ?int
|
||||
{
|
||||
$plan = config('care.plans.'.$this->planKey($organization));
|
||||
@@ -49,4 +68,21 @@ class PlanService
|
||||
{
|
||||
return (int) config('care.plans.pro.price_minor', 19900);
|
||||
}
|
||||
|
||||
public function enterprisePricePerBranchMinor(): int
|
||||
{
|
||||
return (int) config('care.plans.enterprise.price_minor_per_branch', 49900);
|
||||
}
|
||||
|
||||
public function enterprisePriceMinor(Organization $organization): int
|
||||
{
|
||||
$branches = max(1, $this->activeBranchCount($organization));
|
||||
|
||||
return $branches * $this->enterprisePricePerBranchMinor();
|
||||
}
|
||||
|
||||
public function canSubscribeEnterprise(Organization $organization): bool
|
||||
{
|
||||
return $this->activeBranchCount($organization) >= (int) config('care.enterprise.min_branches', 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class ProRenewalService
|
||||
public function dueOrganizations(): Collection
|
||||
{
|
||||
return Organization::query()
|
||||
->where('settings->plan', 'pro')
|
||||
->whereIn('settings->plan', ['pro', 'enterprise'])
|
||||
->whereNotNull('settings->plan_expires_at')
|
||||
->get()
|
||||
->filter(fn (Organization $organization) => $this->isDue($organization));
|
||||
@@ -27,7 +27,8 @@ class ProRenewalService
|
||||
public function isDue(Organization $organization): bool
|
||||
{
|
||||
$settings = $organization->settings ?? [];
|
||||
if (($settings['plan'] ?? '') !== 'pro') {
|
||||
$plan = (string) ($settings['plan'] ?? 'free');
|
||||
if (! in_array($plan, ['pro', 'enterprise'], true)) {
|
||||
return false;
|
||||
}
|
||||
if (array_key_exists('auto_renew', $settings) && $settings['auto_renew'] === false) {
|
||||
@@ -47,27 +48,37 @@ class ProRenewalService
|
||||
}
|
||||
|
||||
$settings = $organization->settings ?? [];
|
||||
$price = $this->plans->proPriceMinor();
|
||||
$reference = 'care-pro-'.$organization->id.'-'.now()->format('YmdHis');
|
||||
$plan = (string) ($settings['plan'] ?? 'free');
|
||||
$isEnterprise = $plan === 'enterprise';
|
||||
$price = $isEnterprise
|
||||
? $this->plans->enterprisePriceMinor($organization)
|
||||
: $this->plans->proPriceMinor();
|
||||
$reference = ($isEnterprise ? 'care-enterprise-' : 'care-pro-')
|
||||
.$organization->id.'-'.now()->format('YmdHis');
|
||||
|
||||
try {
|
||||
$charged = $this->billing->debit(
|
||||
$organization->owner_ref,
|
||||
$price,
|
||||
'care_pro_renewal',
|
||||
$isEnterprise ? 'care_enterprise_renewal' : 'care_pro_renewal',
|
||||
$reference,
|
||||
'Ladill Care Pro — monthly renewal',
|
||||
$isEnterprise
|
||||
? 'Ladill Care Enterprise — monthly renewal'
|
||||
: 'Ladill Care Pro — monthly renewal',
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
$charged = false;
|
||||
}
|
||||
|
||||
if ($charged) {
|
||||
$settings['plan'] = 'pro';
|
||||
$settings['plan'] = $plan;
|
||||
$settings['auto_renew'] = true;
|
||||
$settings['plan_expires_at'] = now()
|
||||
->addDays((int) config('care.pro.period_days', 30))
|
||||
->toIso8601String();
|
||||
if ($isEnterprise) {
|
||||
$settings['enterprise_billed_branches'] = $this->plans->activeBranchCount($organization);
|
||||
}
|
||||
unset($settings['plan_renewal_error']);
|
||||
$organization->update(['settings' => $settings]);
|
||||
|
||||
@@ -78,7 +89,7 @@ class ProRenewalService
|
||||
$graceEnd = $expires->copy()->addDays((int) config('care.pro.grace_days', 3));
|
||||
if ($graceEnd->isPast()) {
|
||||
$settings['plan'] = 'free';
|
||||
unset($settings['plan_expires_at']);
|
||||
unset($settings['plan_expires_at'], $settings['enterprise_billed_branches']);
|
||||
$settings['plan_renewal_error'] = 'Suspended after failed renewal.';
|
||||
} else {
|
||||
$settings['plan_renewal_error'] = 'Renewal failed — top up your wallet.';
|
||||
|
||||
@@ -215,8 +215,19 @@ return [
|
||||
'price_minor' => (int) env('CARE_PRO_PRICE_MINOR', 19900),
|
||||
'max_branches' => null,
|
||||
],
|
||||
'enterprise' => [
|
||||
'label' => 'Enterprise',
|
||||
'price_minor_per_branch' => (int) env('CARE_ENTERPRISE_PRICE_PER_BRANCH_MINOR', 49900),
|
||||
'max_branches' => null,
|
||||
],
|
||||
],
|
||||
|
||||
'enterprise' => [
|
||||
'min_branches' => (int) env('CARE_ENTERPRISE_MIN_BRANCHES', 2),
|
||||
],
|
||||
|
||||
'prepaid_months' => [6, 12, 24],
|
||||
|
||||
'pro' => [
|
||||
'grace_days' => (int) env('CARE_PRO_GRACE_DAYS', 3),
|
||||
'period_days' => (int) env('CARE_PRO_PERIOD_DAYS', 30),
|
||||
|
||||
@@ -1,51 +1,146 @@
|
||||
<x-app-layout title="Pro" heading="Care Pro">
|
||||
<x-app-layout title="Plans" heading="Care plans">
|
||||
@php
|
||||
$price = number_format($priceMinor / 100, 2);
|
||||
$proPrice = number_format($proPriceMinor / 100, 0);
|
||||
$enterprisePerBranch = number_format($enterprisePricePerBranchMinor / 100, 0);
|
||||
$enterpriseTotal = number_format($enterprisePriceMinor / 100, 0);
|
||||
@endphp
|
||||
|
||||
<div class="mx-auto max-w-2xl">
|
||||
<div class="overflow-hidden rounded-2xl border border-slate-200 bg-white">
|
||||
<div class="bg-gradient-to-r from-indigo-700 via-teal-600 to-cyan-500 px-6 py-7 text-white">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="rounded-md bg-white/20 px-2 py-0.5 text-[11px] font-semibold uppercase tracking-wide">Pro</span>
|
||||
@if ($isPro)
|
||||
<span class="rounded-md bg-emerald-400/90 px-2 py-0.5 text-[11px] font-semibold text-emerald-950">Active</span>
|
||||
@endif
|
||||
</div>
|
||||
<h1 class="mt-3 text-2xl font-bold">Ladill Care Pro</h1>
|
||||
<p class="mt-1 text-sm text-white/80">Unlimited branches and the full hospital management toolkit.</p>
|
||||
<p class="mt-4 text-3xl font-bold">{{ $currency }} {{ $price }}<span class="text-base font-medium text-white/70"> / month</span></p>
|
||||
<div class="mx-auto max-w-5xl space-y-6" x-data="{ billing: 'monthly' }">
|
||||
@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
|
||||
|
||||
<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.
|
||||
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">
|
||||
<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>
|
||||
@foreach ($prepaidMonths as $months)
|
||||
<button type="button" @click="billing = '{{ $months }}'"
|
||||
: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
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-5 lg:grid-cols-3">
|
||||
{{-- Free --}}
|
||||
<div class="flex flex-col rounded-2xl border border-slate-200 bg-white p-6 {{ $planKey === 'free' ? 'ring-2 ring-indigo-500' : '' }}">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Free</p>
|
||||
<p class="mt-2 text-3xl font-bold text-slate-900">GHS 0</p>
|
||||
<p class="mt-1 text-sm text-slate-500">1 branch</p>
|
||||
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-700">
|
||||
<li>Core patient records</li>
|
||||
<li>Appointments & consults</li>
|
||||
<li>Basic workflows</li>
|
||||
</ul>
|
||||
@if ($planKey === 'free')
|
||||
<p class="mt-6 text-sm font-medium text-indigo-700">Current plan</p>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="px-6 py-6">
|
||||
<ul class="grid gap-3 sm:grid-cols-2">
|
||||
@foreach ($proFeatures as $feature)
|
||||
<li class="flex items-start gap-2 text-sm text-slate-700">
|
||||
<svg class="mt-0.5 h-4 w-4 shrink-0 text-emerald-500" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5"/></svg>
|
||||
<span>{{ $feature }}</span>
|
||||
</li>
|
||||
@endforeach
|
||||
{{-- Pro --}}
|
||||
<div class="flex flex-col rounded-2xl border border-slate-200 bg-white p-6 {{ $planKey === 'pro' ? 'ring-2 ring-indigo-500' : '' }}">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-indigo-600">Pro</p>
|
||||
<p class="mt-2 text-3xl font-bold text-slate-900">{{ $currency }} {{ $proPrice }}<span class="text-base font-medium text-slate-500">/mo</span></p>
|
||||
<p class="mt-1 text-sm text-slate-500" x-show="billing !== 'monthly'" x-cloak>
|
||||
<span x-text="billing === 'monthly' ? '' : '{{ $currency }} ' + ({{ $proPriceMinor }} * billing / 100).toLocaleString() + ' total'"></span>
|
||||
</p>
|
||||
<p class="mt-1 text-sm text-slate-500" x-show="billing === 'monthly'">Unlimited branches</p>
|
||||
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-700">
|
||||
<li>Full clinical workflows</li>
|
||||
<li>Laboratory & pharmacy</li>
|
||||
<li>Encounter billing</li>
|
||||
<li>Queue integration</li>
|
||||
</ul>
|
||||
|
||||
<div class="mt-6 border-t border-slate-100 pt-6">
|
||||
@if ($isPro)
|
||||
<div class="text-sm text-slate-600">
|
||||
<div class="mt-6">
|
||||
@if ($planKey === 'pro')
|
||||
<p class="text-sm text-slate-600">
|
||||
Active
|
||||
@if ($planExpiresAt)
|
||||
Pro is active until <strong>{{ $planExpiresAt->format('d M Y') }}</strong>.
|
||||
@else
|
||||
Your organization is on Care Pro.
|
||||
until <strong>{{ $planExpiresAt->format('d M Y') }}</strong>
|
||||
@endif
|
||||
</div>
|
||||
.
|
||||
</p>
|
||||
@elseif ($canManage)
|
||||
<form method="post" action="{{ route('care.pro.subscribe') }}">
|
||||
<form x-show="billing === 'monthly'" method="post" action="{{ route('care.pro.subscribe') }}">
|
||||
@csrf
|
||||
<button class="btn-primary w-full sm:w-auto">
|
||||
Upgrade to Pro — {{ $currency }} {{ $price }}/mo from wallet
|
||||
</button>
|
||||
<button class="btn-primary w-full">Upgrade to Pro — monthly wallet</button>
|
||||
</form>
|
||||
<p class="mt-3 text-xs text-slate-400">Billed monthly from your Ladill wallet.</p>
|
||||
<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">
|
||||
<button type="submit" class="btn-primary w-full" x-text="'Pay ' + months + ' months via Paystack'"></button>
|
||||
</form>
|
||||
</template>
|
||||
@else
|
||||
<p class="rounded-xl bg-slate-50 px-4 py-3 text-sm text-slate-500">Ask an organization administrator to upgrade this workspace to Pro.</p>
|
||||
<p class="text-sm text-slate-500">Ask an admin to upgrade.</p>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Enterprise --}}
|
||||
<div class="flex flex-col rounded-2xl border border-slate-200 bg-gradient-to-b from-slate-900 to-slate-800 p-6 text-white {{ $planKey === 'enterprise' ? 'ring-2 ring-amber-400' : '' }}">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-amber-300">Enterprise</p>
|
||||
<p class="mt-2 text-3xl font-bold">{{ $currency }} {{ $enterprisePerBranch }}<span class="text-base font-medium text-slate-300">/branch/mo</span></p>
|
||||
<p class="mt-1 text-sm text-slate-300">
|
||||
@if ($branchCount > 0)
|
||||
{{ $branchCount }} active {{ str('branch')->plural($branchCount) }} = {{ $currency }} {{ $enterpriseTotal }}/mo
|
||||
@else
|
||||
Per-branch billing for multi-site
|
||||
@endif
|
||||
</p>
|
||||
<ul class="mt-5 flex-1 space-y-2 text-sm text-slate-200">
|
||||
<li>Everything in Pro</li>
|
||||
<li>Multi-department workflows</li>
|
||||
<li>Consolidated reporting</li>
|
||||
<li>Dedicated onboarding (setup fee)</li>
|
||||
</ul>
|
||||
<div class="mt-6 space-y-2">
|
||||
@if ($planKey === 'enterprise')
|
||||
<p class="text-sm text-slate-200">
|
||||
Active
|
||||
@if ($planExpiresAt)
|
||||
until <strong class="text-white">{{ $planExpiresAt->format('d M Y') }}</strong>
|
||||
@endif
|
||||
@if ($enterpriseBilledBranches > 0)
|
||||
· billed for {{ $enterpriseBilledBranches }} {{ str('branch')->plural($enterpriseBilledBranches) }}
|
||||
@endif
|
||||
.
|
||||
</p>
|
||||
@elseif ($canManage)
|
||||
@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>
|
||||
</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">
|
||||
<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>
|
||||
</form>
|
||||
</template>
|
||||
@else
|
||||
<p class="text-sm text-slate-300">Add at least {{ $enterpriseMinBranches }} active branches, or choose Pro for a single site.</p>
|
||||
@endif
|
||||
<a href="{{ $salesUrl }}" target="_blank" rel="noopener" class="block text-center text-xs text-amber-200 underline hover:text-white">Contact sales for setup & SLA</a>
|
||||
@else
|
||||
<p class="text-sm text-slate-300">Ask an admin to upgrade.</p>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -112,13 +112,13 @@
|
||||
@endif
|
||||
|
||||
@php $proActive = request()->routeIs('care.pro.*'); @endphp
|
||||
@if (! empty($isPro))
|
||||
<a href="{{ route('care.pro.index') }}" class="group mt-0.5 flex items-center gap-3 rounded-lg px-3 py-2 text-[13px] transition {{ $proActive ? 'bg-indigo-50 text-indigo-700 font-semibold' : 'text-slate-600 hover:bg-slate-50 hover:text-slate-900' }}">
|
||||
@if (! empty($hasPaidPlan))
|
||||
<a href="{{ route('care.pro.index') }}" class="group {{ $permissions->can($member, 'settings.view') ? 'mt-0.5' : '' }} flex items-center gap-3 rounded-lg px-3 py-2 text-[13px] transition {{ $proActive ? 'bg-indigo-50 text-indigo-700 font-semibold' : 'text-slate-600 hover:bg-slate-50 hover:text-slate-900' }}">
|
||||
<svg class="h-[18px] w-[18px] shrink-0 text-amber-500" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2.25c.3 0 .58.18.7.46l2.36 5.5 5.96.5a.75.75 0 0 1 .43 1.31l-4.53 3.9 1.36 5.83a.75.75 0 0 1-1.12.81L12 17.77l-5.16 3a.75.75 0 0 1-1.12-.81l1.36-5.83-4.53-3.9a.75.75 0 0 1 .43-1.31l5.96-.5 2.36-5.5c.12-.28.4-.46.7-.46Z"/></svg>
|
||||
<span>Care Pro</span>
|
||||
<span>{{ ! empty($isEnterprise) ? 'Care Enterprise' : 'Care Pro' }}</span>
|
||||
</a>
|
||||
@else
|
||||
<a href="{{ route('care.pro.index') }}" class="group mt-0.5 flex items-center gap-3 rounded-lg bg-gradient-to-r from-indigo-600 to-emerald-500 px-3 py-2 text-[13px] font-semibold text-white shadow-sm transition hover:opacity-95">
|
||||
<a href="{{ route('care.pro.index') }}" class="group {{ $permissions->can($member, 'settings.view') ? 'mt-0.5' : '' }} flex items-center gap-3 rounded-lg bg-gradient-to-r from-indigo-600 to-emerald-500 px-3 py-2 text-[13px] font-semibold text-white shadow-sm transition hover:opacity-95">
|
||||
<svg class="h-[18px] w-[18px] shrink-0" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2.25c.3 0 .58.18.7.46l2.36 5.5 5.96.5a.75.75 0 0 1 .43 1.31l-4.53 3.9 1.36 5.83a.75.75 0 0 1-1.12.81L12 17.77l-5.16 3a.75.75 0 0 1-1.12-.81l1.36-5.83-4.53-3.9a.75.75 0 0 1 .43-1.31l5.96-.5 2.36-5.5c.12-.28.4-.46.7-.46Z"/></svg>
|
||||
<span>Upgrade to Pro</span>
|
||||
</a>
|
||||
|
||||
@@ -133,6 +133,9 @@ Route::middleware(['auth', 'platform.session'])->group(function () {
|
||||
|
||||
Route::get('/pro', [ProController::class, 'index'])->name('care.pro.index');
|
||||
Route::post('/pro/subscribe', [ProController::class, 'subscribe'])->name('care.pro.subscribe');
|
||||
Route::post('/pro/subscribe-enterprise', [ProController::class, 'subscribeEnterprise'])->name('care.pro.subscribe-enterprise');
|
||||
Route::post('/pro/subscribe-prepaid', [ProController::class, 'subscribePrepaid'])->name('care.pro.subscribe-prepaid');
|
||||
Route::get('/pro/paystack/callback', [ProController::class, 'paystackCallback'])->name('care.pro.paystack.callback');
|
||||
|
||||
Route::get('/branches', [BranchController::class, 'index'])->name('care.branches.index');
|
||||
Route::get('/branches/create', [BranchController::class, 'create'])->name('care.branches.create');
|
||||
|
||||
@@ -53,17 +53,27 @@ class CareProTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_pro_page_renders_for_free_organization(): void
|
||||
public function test_pro_page_renders_three_tier_pricing(): void
|
||||
{
|
||||
$this->actingAs($this->owner)
|
||||
->get(route('care.pro.index'))
|
||||
->assertOk()
|
||||
->assertSee('Ladill Care Pro')
|
||||
->assertSee('Choose your Care plan')
|
||||
->assertSee('GHS 199')
|
||||
->assertSee('GHS 499')
|
||||
->assertSee('Upgrade to Pro')
|
||||
->assertSee('Enterprise');
|
||||
}
|
||||
|
||||
public function test_sidebar_shows_upgrade_to_pro_on_dashboard(): void
|
||||
{
|
||||
$this->actingAs($this->owner)
|
||||
->get(route('care.dashboard'))
|
||||
->assertOk()
|
||||
->assertSee('Upgrade to Pro');
|
||||
}
|
||||
|
||||
public function test_subscribe_upgrades_organization(): void
|
||||
public function test_subscribe_upgrades_organization_to_pro(): void
|
||||
{
|
||||
Http::fake([
|
||||
'billing.test/can-afford*' => Http::response(['affordable' => true]),
|
||||
@@ -75,7 +85,77 @@ class CareProTest extends TestCase
|
||||
->assertRedirect(route('care.pro.index'))
|
||||
->assertSessionHas('success');
|
||||
|
||||
$this->assertSame('pro', $this->organization->fresh()->settings['plan']);
|
||||
$settings = $this->organization->fresh()->settings;
|
||||
$this->assertSame('pro', $settings['plan']);
|
||||
$this->assertSame('wallet_monthly', $settings['billing_method']);
|
||||
}
|
||||
|
||||
public function test_subscribe_enterprise_requires_multiple_branches(): void
|
||||
{
|
||||
Http::fake([
|
||||
'billing.test/can-afford*' => Http::response(['affordable' => true]),
|
||||
'billing.test/debit' => Http::response(['ok' => true]),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->post(route('care.pro.subscribe-enterprise'))
|
||||
->assertRedirect(route('care.pro.index'))
|
||||
->assertSessionHas('error');
|
||||
|
||||
Branch::create([
|
||||
'owner_ref' => $this->organization->owner_ref,
|
||||
'organization_id' => $this->organization->id,
|
||||
'name' => 'Second',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->post(route('care.pro.subscribe-enterprise'))
|
||||
->assertRedirect(route('care.pro.index'))
|
||||
->assertSessionHas('success');
|
||||
|
||||
$settings = $this->organization->fresh()->settings;
|
||||
$this->assertSame('enterprise', $settings['plan']);
|
||||
$this->assertSame(2, $settings['enterprise_billed_branches']);
|
||||
}
|
||||
|
||||
public function test_subscribe_prepaid_redirects_to_paystack(): void
|
||||
{
|
||||
Http::fake([
|
||||
'billing.test/plan-checkout' => Http::response([
|
||||
'checkout_url' => 'https://checkout.paystack.com/test',
|
||||
'reference' => 'ref-123',
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->post(route('care.pro.subscribe-prepaid'), [
|
||||
'plan' => 'pro',
|
||||
'months' => 12,
|
||||
])
|
||||
->assertRedirect('https://checkout.paystack.com/test');
|
||||
}
|
||||
|
||||
public function test_paystack_callback_activates_prepaid_pro(): void
|
||||
{
|
||||
Http::fake([
|
||||
'billing.test/plan-checkout/verify' => Http::response([
|
||||
'paid' => true,
|
||||
'plan' => 'pro',
|
||||
'months' => 12,
|
||||
'metadata' => ['organization_id' => $this->organization->id],
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->get(route('care.pro.paystack.callback', ['reference' => 'ref-123']))
|
||||
->assertRedirect(route('care.pro.index'))
|
||||
->assertSessionHas('success');
|
||||
|
||||
$settings = $this->organization->fresh()->settings;
|
||||
$this->assertSame('pro', $settings['plan']);
|
||||
$this->assertFalse($settings['auto_renew']);
|
||||
$this->assertSame('paystack_prepaid', $settings['billing_method']);
|
||||
}
|
||||
|
||||
public function test_pro_renew_extends_subscription_when_wallet_charges(): void
|
||||
@@ -100,4 +180,37 @@ class CareProTest extends TestCase
|
||||
$this->assertSame('pro', $settings['plan']);
|
||||
$this->assertTrue(now()->parse($settings['plan_expires_at'])->isFuture());
|
||||
}
|
||||
|
||||
public function test_enterprise_renew_charges_per_active_branch(): void
|
||||
{
|
||||
Branch::create([
|
||||
'owner_ref' => $this->organization->owner_ref,
|
||||
'organization_id' => $this->organization->id,
|
||||
'name' => 'Second',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->organization->update([
|
||||
'settings' => array_merge($this->organization->settings ?? [], [
|
||||
'plan' => 'enterprise',
|
||||
'auto_renew' => true,
|
||||
'enterprise_billed_branches' => 2,
|
||||
'plan_expires_at' => now()->subDay()->toIso8601String(),
|
||||
]),
|
||||
]);
|
||||
|
||||
Http::fake([
|
||||
'billing.test/debit' => function ($request) {
|
||||
$this->assertSame(99800, (int) $request['amount_minor']);
|
||||
|
||||
return Http::response(['ok' => true]);
|
||||
},
|
||||
]);
|
||||
|
||||
$this->artisan('care:pro-renew')->assertSuccessful();
|
||||
|
||||
$settings = $this->organization->fresh()->settings;
|
||||
$this->assertSame('enterprise', $settings['plan']);
|
||||
$this->assertSame(2, $settings['enterprise_billed_branches']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user