Add Queue Pro billing, renewal, and scheduler.
Deploy Ladill Queue / deploy (push) Successful in 42s
Deploy Ladill Queue / deploy (push) Successful in 42s
Organizations can upgrade from wallet with plan expiry enforcement and nightly qms:pro-renew charges. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Services\Qms\ProRenewalService;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class RenewProSubscriptionsCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'qms:pro-renew';
|
||||||
|
|
||||||
|
protected $description = 'Charge the Ladill wallet for due Queue Pro subscriptions (and downgrade after the grace window).';
|
||||||
|
|
||||||
|
public function handle(ProRenewalService $renewals): int
|
||||||
|
{
|
||||||
|
$due = $renewals->dueOrganizations();
|
||||||
|
$this->info("Renewing {$due->count()} due organization(s).");
|
||||||
|
$due->each(fn ($organization) => $renewals->renewIfDue($organization));
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Qms;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Controllers\Qms\Concerns\ScopesToAccount;
|
||||||
|
use App\Services\Billing\BillingClient;
|
||||||
|
use App\Services\Qms\PlanService;
|
||||||
|
use App\Services\Qms\QmsPermissions;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
class ProController extends Controller
|
||||||
|
{
|
||||||
|
use ScopesToAccount;
|
||||||
|
|
||||||
|
public function index(Request $request, PlanService $plans): View
|
||||||
|
{
|
||||||
|
$organization = $this->organization($request);
|
||||||
|
$canManage = app(QmsPermissions::class)->can($this->member($request), 'settings.manage');
|
||||||
|
$settings = $organization->settings ?? [];
|
||||||
|
$expiresAt = ! empty($settings['plan_expires_at'])
|
||||||
|
? Carbon::parse($settings['plan_expires_at'])
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return view('qms.pro.index', [
|
||||||
|
'organization' => $organization,
|
||||||
|
'isPro' => $plans->isPro($organization),
|
||||||
|
'canManage' => $canManage,
|
||||||
|
'priceMinor' => $plans->proPriceMinor(),
|
||||||
|
'currency' => (string) config('billing.currency', 'GHS'),
|
||||||
|
'planExpiresAt' => $expiresAt,
|
||||||
|
'proFeatures' => [
|
||||||
|
'Unlimited branches & queues',
|
||||||
|
'Advanced routing rules',
|
||||||
|
'Digital displays & kiosk devices',
|
||||||
|
'Appointment reminders',
|
||||||
|
'Analytics & report exports',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function subscribe(Request $request, PlanService $plans, BillingClient $billing): RedirectResponse
|
||||||
|
{
|
||||||
|
$this->authorizeAbility($request, 'settings.manage');
|
||||||
|
$organization = $this->organization($request);
|
||||||
|
|
||||||
|
if ($plans->isPro($organization)) {
|
||||||
|
return redirect()->route('qms.pro.index')
|
||||||
|
->with('success', 'Your organization is already on Queue Pro.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$priceMinor = $plans->proPriceMinor();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (! $billing->canAfford($organization->owner_ref, $priceMinor)) {
|
||||||
|
return redirect()->route('qms.pro.index')
|
||||||
|
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade to Pro.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$charged = $billing->debit(
|
||||||
|
$organization->owner_ref,
|
||||||
|
$priceMinor,
|
||||||
|
'queue_pro',
|
||||||
|
'queue-pro-'.$organization->id.'-'.now()->format('Y-m-d-His'),
|
||||||
|
'Ladill Queue Pro — monthly subscription',
|
||||||
|
);
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return redirect()->route('qms.pro.index')
|
||||||
|
->with('error', 'Could not process upgrade. Please try again.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $charged) {
|
||||||
|
return redirect()->route('qms.pro.index')
|
||||||
|
->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade to Pro.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = $organization->settings ?? [];
|
||||||
|
$settings['plan'] = 'pro';
|
||||||
|
$settings['auto_renew'] = true;
|
||||||
|
$settings['plan_expires_at'] = now()
|
||||||
|
->addDays((int) config('qms.pro.period_days', 30))
|
||||||
|
->toIso8601String();
|
||||||
|
unset($settings['plan_renewal_error']);
|
||||||
|
$organization->update(['settings' => $settings]);
|
||||||
|
|
||||||
|
return redirect()->route('qms.pro.index')
|
||||||
|
->with('success', 'Welcome to Queue Pro — active for one month.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,9 @@ namespace App\Providers;
|
|||||||
|
|
||||||
use App\Events\ServiceEventOccurred;
|
use App\Events\ServiceEventOccurred;
|
||||||
use App\Listeners\PlatformServiceEventListener;
|
use App\Listeners\PlatformServiceEventListener;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Services\Qms\OrganizationResolver;
|
||||||
|
use App\Services\Qms\PlanService;
|
||||||
use Illuminate\Cache\RateLimiting\Limit;
|
use Illuminate\Cache\RateLimiting\Limit;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
@@ -28,6 +31,21 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
return Limit::perMinute(30)->by((string) $key);
|
return Limit::perMinute(30)->by((string) $key);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
View::composer('partials.sidebar', function ($view) {
|
||||||
|
/** @var User|null $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$isPro = false;
|
||||||
|
|
||||||
|
if ($user) {
|
||||||
|
$organization = app(OrganizationResolver::class)->resolveForUser($user);
|
||||||
|
if ($organization) {
|
||||||
|
$isPro = app(PlanService::class)->isPro($organization);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$view->with('isPro', $isPro);
|
||||||
|
});
|
||||||
|
|
||||||
View::composer(['partials.topbar'], function ($view) {
|
View::composer(['partials.topbar'], function ($view) {
|
||||||
$view->with(\App\Support\MobileTopbar::resolve());
|
$view->with(\App\Support\MobileTopbar::resolve());
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,27 +3,42 @@
|
|||||||
namespace App\Services\Qms;
|
namespace App\Services\Qms;
|
||||||
|
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class PlanService
|
class PlanService
|
||||||
{
|
{
|
||||||
|
public function planKey(Organization $organization): string
|
||||||
|
{
|
||||||
|
$settings = $organization->settings ?? [];
|
||||||
|
$plan = (string) ($settings['plan'] ?? 'free');
|
||||||
|
|
||||||
|
if ($plan === 'pro' && ! empty($settings['plan_expires_at'])) {
|
||||||
|
if (Carbon::parse($settings['plan_expires_at'])->isPast()) {
|
||||||
|
return 'free';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_key_exists($plan, config('qms.plans', [])) ? $plan : 'free';
|
||||||
|
}
|
||||||
|
|
||||||
public function plan(Organization $organization): string
|
public function plan(Organization $organization): string
|
||||||
{
|
{
|
||||||
return (string) data_get($organization->settings, 'plan', 'free');
|
return $this->planKey($organization);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isPro(Organization $organization): bool
|
public function isPro(Organization $organization): bool
|
||||||
{
|
{
|
||||||
return $this->plan($organization) === 'pro';
|
return $this->planKey($organization) === 'pro';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function maxBranches(Organization $organization): ?int
|
public function maxBranches(Organization $organization): ?int
|
||||||
{
|
{
|
||||||
return config('qms.plans.'.$this->plan($organization).'.max_branches');
|
return config('qms.plans.'.$this->planKey($organization).'.max_branches');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function maxQueues(Organization $organization): ?int
|
public function maxQueues(Organization $organization): ?int
|
||||||
{
|
{
|
||||||
return config('qms.plans.'.$this->plan($organization).'.max_queues');
|
return config('qms.plans.'.$this->planKey($organization).'.max_queues');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canAddBranch(Organization $organization, int $currentCount): bool
|
public function canAddBranch(Organization $organization, int $currentCount): bool
|
||||||
@@ -39,4 +54,9 @@ class PlanService
|
|||||||
|
|
||||||
return $max === null || $currentCount < $max;
|
return $max === null || $currentCount < $max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function proPriceMinor(): int
|
||||||
|
{
|
||||||
|
return (int) config('qms.plans.pro.price_minor', 9900);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Qms;
|
||||||
|
|
||||||
|
use App\Models\Organization;
|
||||||
|
use App\Services\Billing\BillingClient;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
class ProRenewalService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly BillingClient $billing,
|
||||||
|
private readonly PlanService $plans,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/** @return Collection<int, Organization> */
|
||||||
|
public function dueOrganizations(): Collection
|
||||||
|
{
|
||||||
|
return Organization::query()
|
||||||
|
->where('settings->plan', 'pro')
|
||||||
|
->whereNotNull('settings->plan_expires_at')
|
||||||
|
->get()
|
||||||
|
->filter(fn (Organization $organization) => $this->isDue($organization));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDue(Organization $organization): bool
|
||||||
|
{
|
||||||
|
$settings = $organization->settings ?? [];
|
||||||
|
if (($settings['plan'] ?? '') !== 'pro') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (array_key_exists('auto_renew', $settings) && $settings['auto_renew'] === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (empty($settings['plan_expires_at'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Carbon::parse($settings['plan_expires_at'])->lte(now());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renewIfDue(Organization $organization): void
|
||||||
|
{
|
||||||
|
if (! $this->isDue($organization)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = $organization->settings ?? [];
|
||||||
|
$price = $this->plans->proPriceMinor();
|
||||||
|
$reference = 'queue-pro-'.$organization->id.'-'.now()->format('YmdHis');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$charged = $this->billing->debit(
|
||||||
|
$organization->owner_ref,
|
||||||
|
$price,
|
||||||
|
'queue_pro_renewal',
|
||||||
|
$reference,
|
||||||
|
'Ladill Queue Pro — monthly renewal',
|
||||||
|
);
|
||||||
|
} catch (\Throwable) {
|
||||||
|
$charged = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($charged) {
|
||||||
|
$settings['plan'] = 'pro';
|
||||||
|
$settings['auto_renew'] = true;
|
||||||
|
$settings['plan_expires_at'] = now()
|
||||||
|
->addDays((int) config('qms.pro.period_days', 30))
|
||||||
|
->toIso8601String();
|
||||||
|
unset($settings['plan_renewal_error']);
|
||||||
|
$organization->update(['settings' => $settings]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$expires = Carbon::parse($settings['plan_expires_at']);
|
||||||
|
$graceEnd = $expires->copy()->addDays((int) config('qms.pro.grace_days', 3));
|
||||||
|
if ($graceEnd->isPast()) {
|
||||||
|
$settings['plan'] = 'free';
|
||||||
|
unset($settings['plan_expires_at']);
|
||||||
|
$settings['plan_renewal_error'] = 'Suspended after failed renewal.';
|
||||||
|
} else {
|
||||||
|
$settings['plan_renewal_error'] = 'Renewal failed — top up your wallet.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$organization->update(['settings' => $settings]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -194,6 +194,11 @@ return [
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'pro' => [
|
||||||
|
'grace_days' => (int) env('QUEUE_PRO_GRACE_DAYS', 3),
|
||||||
|
'period_days' => (int) env('QUEUE_PRO_PERIOD_DAYS', 30),
|
||||||
|
],
|
||||||
|
|
||||||
'rule_types' => [
|
'rule_types' => [
|
||||||
'overflow' => 'Overflow routing',
|
'overflow' => 'Overflow routing',
|
||||||
'priority_boost' => 'Priority boost',
|
'priority_boost' => 'Priority boost',
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />'];
|
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingsActive = request()->routeIs('qms.settings.*');
|
$settingsActive = request()->routeIs('qms.settings.*') && ! request()->routeIs('qms.pro.*');
|
||||||
@endphp
|
@endphp
|
||||||
<nav class="flex-1 space-y-0.5 overflow-y-auto px-3 py-4">
|
<nav class="flex-1 space-y-0.5 overflow-y-auto px-3 py-4">
|
||||||
@foreach ($nav as $item)
|
@foreach ($nav as $item)
|
||||||
@@ -98,6 +98,19 @@
|
|||||||
</svg>
|
</svg>
|
||||||
<span>Settings</span>
|
<span>Settings</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
@php $proActive = request()->routeIs('qms.pro.*'); @endphp
|
||||||
|
@if (! empty($isPro))
|
||||||
|
<a href="{{ route('qms.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' }}">
|
||||||
|
<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>Queue Pro</span>
|
||||||
|
</a>
|
||||||
|
@else
|
||||||
|
<a href="{{ route('qms.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">
|
||||||
|
<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>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<x-app-layout title="Pro" heading="Queue Pro">
|
||||||
|
@php
|
||||||
|
$price = number_format($priceMinor / 100, 2);
|
||||||
|
@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 Queue Pro</h1>
|
||||||
|
<p class="mt-1 text-sm text-white/80">Unlimited branches, queues, and advanced queue management.</p>
|
||||||
|
<p class="mt-4 text-3xl font-bold">{{ $currency }} {{ $price }}<span class="text-base font-medium text-white/70"> / month</span></p>
|
||||||
|
</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
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="mt-6 border-t border-slate-100 pt-6">
|
||||||
|
@if ($isPro)
|
||||||
|
<div class="text-sm text-slate-600">
|
||||||
|
@if ($planExpiresAt)
|
||||||
|
Pro is active until <strong>{{ $planExpiresAt->format('d M Y') }}</strong>.
|
||||||
|
@else
|
||||||
|
Your organization is on Queue Pro.
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@elseif ($canManage)
|
||||||
|
<form method="post" action="{{ route('qms.pro.subscribe') }}">
|
||||||
|
@csrf
|
||||||
|
<button class="btn-primary w-full sm:w-auto">
|
||||||
|
Upgrade to Pro — {{ $currency }} {{ $price }}/mo from wallet
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<p class="mt-3 text-xs text-slate-400">Billed monthly from your Ladill wallet.</p>
|
||||||
|
@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>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-app-layout>
|
||||||
@@ -10,3 +10,4 @@ Artisan::command('inspire', function () {
|
|||||||
|
|
||||||
Schedule::command('qms:mark-devices-offline')->everyFiveMinutes();
|
Schedule::command('qms:mark-devices-offline')->everyFiveMinutes();
|
||||||
Schedule::command('qms:send-appointment-reminders')->everyFifteenMinutes();
|
Schedule::command('qms:send-appointment-reminders')->everyFifteenMinutes();
|
||||||
|
Schedule::command('qms:pro-renew')->dailyAt('02:40')->withoutOverlapping();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use App\Http\Controllers\Qms\MobileQueueController;
|
|||||||
use App\Http\Controllers\Qms\OnboardingController;
|
use App\Http\Controllers\Qms\OnboardingController;
|
||||||
use App\Http\Controllers\Qms\QueueBoardController;
|
use App\Http\Controllers\Qms\QueueBoardController;
|
||||||
use App\Http\Controllers\Qms\QueueRuleController;
|
use App\Http\Controllers\Qms\QueueRuleController;
|
||||||
|
use App\Http\Controllers\Qms\ProController;
|
||||||
use App\Http\Controllers\Qms\ReportController;
|
use App\Http\Controllers\Qms\ReportController;
|
||||||
use App\Http\Controllers\Qms\ServiceQueueController;
|
use App\Http\Controllers\Qms\ServiceQueueController;
|
||||||
use App\Http\Controllers\Qms\SettingsController;
|
use App\Http\Controllers\Qms\SettingsController;
|
||||||
@@ -168,5 +169,8 @@ Route::middleware(['auth', 'platform.session'])->group(function () {
|
|||||||
|
|
||||||
Route::get('/settings', [SettingsController::class, 'edit'])->name('qms.settings.edit');
|
Route::get('/settings', [SettingsController::class, 'edit'])->name('qms.settings.edit');
|
||||||
Route::put('/settings', [SettingsController::class, 'update'])->name('qms.settings.update');
|
Route::put('/settings', [SettingsController::class, 'update'])->name('qms.settings.update');
|
||||||
|
|
||||||
|
Route::get('/pro', [ProController::class, 'index'])->name('qms.pro.index');
|
||||||
|
Route::post('/pro/subscribe', [ProController::class, 'subscribe'])->name('qms.pro.subscribe');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Http\Middleware\EnsurePlatformSession;
|
||||||
|
use App\Models\Organization;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Services\Qms\OrganizationResolver;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class QmsProTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected User $owner;
|
||||||
|
|
||||||
|
protected Organization $organization;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||||
|
config(['billing.api_url' => 'https://billing.test']);
|
||||||
|
|
||||||
|
$this->owner = User::create([
|
||||||
|
'public_id' => 'queue-owner-001',
|
||||||
|
'name' => 'Owner',
|
||||||
|
'email' => 'owner@example.com',
|
||||||
|
'password' => bcrypt('password'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->organization = app(OrganizationResolver::class)->completeOnboarding($this->owner, [
|
||||||
|
'organization_name' => 'Queue Org',
|
||||||
|
'industry' => 'retail',
|
||||||
|
'appointment_mode' => 'hybrid',
|
||||||
|
'branch_name' => 'Main',
|
||||||
|
'timezone' => 'UTC',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_pro_page_renders_for_free_organization(): void
|
||||||
|
{
|
||||||
|
$this->actingAs($this->owner)
|
||||||
|
->get(route('qms.pro.index'))
|
||||||
|
->assertOk()
|
||||||
|
->assertSee('Ladill Queue Pro')
|
||||||
|
->assertSee('GHS 99')
|
||||||
|
->assertSee('Upgrade to Pro');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_subscribe_upgrades_organization(): void
|
||||||
|
{
|
||||||
|
Http::fake([
|
||||||
|
'billing.test/can-afford*' => Http::response(['affordable' => true]),
|
||||||
|
'billing.test/debit' => Http::response(['ok' => true]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($this->owner)
|
||||||
|
->post(route('qms.pro.subscribe'))
|
||||||
|
->assertRedirect(route('qms.pro.index'))
|
||||||
|
->assertSessionHas('success');
|
||||||
|
|
||||||
|
$this->assertSame('pro', $this->organization->fresh()->settings['plan']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_pro_renew_extends_subscription_when_wallet_charges(): void
|
||||||
|
{
|
||||||
|
$this->organization->update([
|
||||||
|
'settings' => array_merge($this->organization->settings ?? [], [
|
||||||
|
'plan' => 'pro',
|
||||||
|
'auto_renew' => true,
|
||||||
|
'plan_expires_at' => now()->subDay()->toIso8601String(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Http::fake([
|
||||||
|
'billing.test/debit' => Http::response(['ok' => true]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->artisan('qms:pro-renew')->assertSuccessful();
|
||||||
|
|
||||||
|
$settings = $this->organization->fresh()->settings;
|
||||||
|
$this->assertSame('pro', $settings['plan']);
|
||||||
|
$this->assertTrue(now()->parse($settings['plan_expires_at'])->isFuture());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user