Add freemium plans, wallet-billed host notifications, and Pro upgrades.
Deploy Ladill Frontdesk / deploy (push) Successful in 44s
Deploy Ladill Frontdesk / deploy (push) Successful in 44s
Host alerts use email/phone on the host record without requiring a Ladill account link; SMS and over-quota emails debit the org wallet at platform rates. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -38,6 +38,14 @@ class BranchController extends Controller
|
||||
$this->authorizeAbility($request, 'admin.branches.manage');
|
||||
$organization = $this->organization($request);
|
||||
|
||||
$currentCount = Branch::owned($this->ownerRef($request))
|
||||
->where('organization_id', $organization->id)
|
||||
->count();
|
||||
|
||||
if (! app(\App\Services\Frontdesk\PlanService::class)->canAddBranch($organization, $currentCount)) {
|
||||
return back()->withInput()->with('error', 'Your plan allows one branch. Upgrade to Frontdesk Pro for unlimited branches.');
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'code' => ['nullable', 'string', 'max:50'],
|
||||
|
||||
@@ -61,6 +61,10 @@ class DeviceController extends Controller
|
||||
'reception_desk_id' => ['nullable', 'integer'],
|
||||
]);
|
||||
|
||||
if ($validated['type'] === 'kiosk' && ! app(\App\Services\Frontdesk\PlanService::class)->canAddKiosk($organization)) {
|
||||
return back()->withInput()->with('error', 'Your plan allows one kiosk device. Upgrade to Frontdesk Pro for unlimited kiosks.');
|
||||
}
|
||||
|
||||
$token = in_array($validated['type'], config('frontdesk.device_token_types', []), true)
|
||||
? $devices->generateToken()
|
||||
: null;
|
||||
|
||||
@@ -17,6 +17,15 @@ class IntegrationController extends Controller
|
||||
{
|
||||
$this->authorizeAbility($request, 'settings.view');
|
||||
$organization = $this->organization($request);
|
||||
$plans = app(\App\Services\Frontdesk\PlanService::class);
|
||||
|
||||
if (! $plans->hasFeature($organization, 'integrations')) {
|
||||
return view('frontdesk.integrations.upgrade', [
|
||||
'organization' => $organization,
|
||||
'proPriceMinor' => $plans->proPriceMinor(),
|
||||
]);
|
||||
}
|
||||
|
||||
$canManage = app(\App\Services\Frontdesk\FrontdeskPermissions::class)
|
||||
->isAdmin($this->member($request));
|
||||
|
||||
@@ -39,6 +48,10 @@ class IntegrationController extends Controller
|
||||
$this->authorizeAbility($request, 'settings.manage');
|
||||
$organization = $this->organization($request);
|
||||
|
||||
if (! app(\App\Services\Frontdesk\PlanService::class)->hasFeature($organization, 'integrations')) {
|
||||
return back()->with('error', 'Webhooks and calendar feeds require Frontdesk Pro.');
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'webhook_url' => ['nullable', 'url', 'max:500'],
|
||||
'webhook_secret' => ['nullable', 'string', 'max:128'],
|
||||
|
||||
@@ -77,6 +77,7 @@ class KioskController extends Controller
|
||||
'awaiting_approval' => $visit->awaitingApproval(),
|
||||
'checked_in_at' => $visit->checked_in_at?->toIso8601String(),
|
||||
'badge_url' => $visit->isInside() ? route('frontdesk.visits.badge', $visit) : null,
|
||||
'host_notified' => (bool) ($visit->host_notified ?? false),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ class KioskDeviceController extends Controller
|
||||
'awaiting_approval' => $visit->awaitingApproval(),
|
||||
'checked_in_at' => $visit->checked_in_at?->toIso8601String(),
|
||||
'badge_url' => $visit->isInside() ? route('frontdesk.visits.badge', $visit) : null,
|
||||
'host_notified' => (bool) ($visit->host_notified ?? false),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
||||
use App\Models\Branch;
|
||||
use App\Services\Frontdesk\FrontdeskPermissions;
|
||||
use App\Services\Frontdesk\NotificationPricingService;
|
||||
use App\Services\Frontdesk\NotificationUsageService;
|
||||
use App\Services\Frontdesk\PlanService;
|
||||
use App\Support\OrganizationBranding;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -15,7 +18,7 @@ class SettingsController extends Controller
|
||||
{
|
||||
use ScopesToAccount;
|
||||
|
||||
public function edit(Request $request): View
|
||||
public function edit(Request $request, PlanService $plans, NotificationUsageService $usage, NotificationPricingService $pricing): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'settings.view');
|
||||
$organization = $this->organization($request);
|
||||
@@ -25,6 +28,10 @@ class SettingsController extends Controller
|
||||
->where('organization_id', $organization->id)
|
||||
->count();
|
||||
|
||||
$monthlyUsage = $usage->forOrganization($organization);
|
||||
$plan = $plans->plan($organization);
|
||||
$freeEmailAllowance = $plans->freeEmailsPerMonth($organization);
|
||||
|
||||
return view('frontdesk.settings.edit', [
|
||||
'organization' => $organization,
|
||||
'canManage' => $canManage,
|
||||
@@ -33,6 +40,15 @@ class SettingsController extends Controller
|
||||
'deviceTypes' => config('frontdesk.device_types'),
|
||||
'notificationChannels' => config('frontdesk.notification_channels'),
|
||||
'notificationEvents' => config('frontdesk.notification_events'),
|
||||
'plan' => $plan,
|
||||
'isPro' => $plans->isPro($organization),
|
||||
'proPriceMinor' => $plans->proPriceMinor(),
|
||||
'monthlyUsage' => $monthlyUsage,
|
||||
'freeEmailAllowance' => $freeEmailAllowance,
|
||||
'emailCostFormatted' => $pricing->formatMinor($pricing->emailCostMinor()),
|
||||
'smsCostFormatted' => $pricing->formatMinor(
|
||||
$pricing->smsCostMinor('Sample SMS message for pricing display.'),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Frontdesk;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
||||
use App\Services\Billing\BillingClient;
|
||||
use App\Services\Frontdesk\PlanService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class WalletController extends Controller
|
||||
{
|
||||
use ScopesToAccount;
|
||||
|
||||
public function balance(Request $request, BillingClient $billing): JsonResponse
|
||||
{
|
||||
$publicId = (string) $request->user()->public_id;
|
||||
|
||||
$minor = Cache::remember("frontdesk_wallet_balance:{$publicId}", now()->addSeconds(30), function () use ($billing, $publicId) {
|
||||
try {
|
||||
return $billing->balanceMinor($publicId);
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
if ($minor === null) {
|
||||
return response()->json(['available' => false]);
|
||||
}
|
||||
|
||||
$currency = (string) config('billing.currency', 'GHS');
|
||||
|
||||
return response()->json([
|
||||
'available' => true,
|
||||
'balance_minor' => $minor,
|
||||
'currency' => $currency,
|
||||
'formatted' => $currency.' '.number_format($minor / 100, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
public function upgrade(Request $request, PlanService $plans, BillingClient $billing): RedirectResponse
|
||||
{
|
||||
$this->authorizeAbility($request, 'settings.manage');
|
||||
$organization = $this->organization($request);
|
||||
|
||||
if ($plans->isPro($organization)) {
|
||||
return back()->with('success', 'Your organization is already on Frontdesk Pro.');
|
||||
}
|
||||
|
||||
$priceMinor = $plans->proPriceMinor();
|
||||
$ownerRef = $organization->owner_ref;
|
||||
|
||||
try {
|
||||
if (! $billing->canAfford($ownerRef, $priceMinor)) {
|
||||
return back()->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade to Pro.');
|
||||
}
|
||||
|
||||
$charged = $billing->debit(
|
||||
$ownerRef,
|
||||
$priceMinor,
|
||||
'frontdesk_pro',
|
||||
'frontdesk-pro-'.$organization->id.'-'.now()->format('Y-m'),
|
||||
'Ladill Frontdesk Pro — monthly subscription',
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
return back()->with('error', 'Could not process upgrade. Please try again.');
|
||||
}
|
||||
|
||||
if (! $charged) {
|
||||
return back()->with('error', 'Insufficient wallet balance. Top up your Ladill wallet to upgrade to Pro.');
|
||||
}
|
||||
|
||||
$settings = $organization->settings ?? [];
|
||||
$settings['plan'] = 'pro';
|
||||
$settings['plan_expires_at'] = now()->addMonth()->toIso8601String();
|
||||
$organization->update(['settings' => $settings]);
|
||||
|
||||
return back()->with('success', 'Upgraded to Frontdesk Pro for one month.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user