Set Pro to GHS 100/mo and add sidebar Go Pro UI like Accounting.
Deploy Ladill Frontdesk / deploy (push) Successful in 33s
Deploy Ladill Frontdesk / deploy (push) Successful in 33s
Adds a dedicated Pro page with wallet upgrade, gradient Upgrade to Pro button in the sidebar footer, and view composer for plan status. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?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\FrontdeskPermissions;
|
||||
use App\Services\Frontdesk\PlanService;
|
||||
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(FrontdeskPermissions::class)->isAdmin($this->member($request));
|
||||
$settings = $organization->settings ?? [];
|
||||
$expiresAt = ! empty($settings['plan_expires_at'])
|
||||
? Carbon::parse($settings['plan_expires_at'])
|
||||
: null;
|
||||
|
||||
return view('frontdesk.pro.index', [
|
||||
'organization' => $organization,
|
||||
'isPro' => $plans->isPro($organization),
|
||||
'canManage' => $canManage,
|
||||
'priceMinor' => $plans->proPriceMinor(),
|
||||
'currency' => (string) config('billing.currency', 'GHS'),
|
||||
'planExpiresAt' => $expiresAt,
|
||||
'proFeatures' => [
|
||||
'Unlimited branches & kiosk devices',
|
||||
'Unlimited host email alerts',
|
||||
'Webhooks & calendar (iCal) feeds',
|
||||
'Scheduled report exports',
|
||||
'Custom badge templates',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
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('frontdesk.pro.index')
|
||||
->with('success', 'Your organization is already on Frontdesk Pro.');
|
||||
}
|
||||
|
||||
$priceMinor = $plans->proPriceMinor();
|
||||
$ownerRef = $organization->owner_ref;
|
||||
|
||||
try {
|
||||
if (! $billing->canAfford($ownerRef, $priceMinor)) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->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-d-His'),
|
||||
'Ladill Frontdesk Pro — monthly subscription',
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->with('error', 'Could not process upgrade. Please try again.');
|
||||
}
|
||||
|
||||
if (! $charged) {
|
||||
return redirect()->route('frontdesk.pro.index')
|
||||
->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 redirect()->route('frontdesk.pro.index')
|
||||
->with('success', 'Welcome to Frontdesk Pro — active for one month.');
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,7 @@ 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\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
@@ -39,44 +38,4 @@ class WalletController extends Controller
|
||||
'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.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Frontdesk\OrganizationResolver;
|
||||
use App\Services\Frontdesk\PlanService;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -29,5 +33,20 @@ class AppServiceProvider extends ServiceProvider
|
||||
RateLimiter::for('device-heartbeat', function (Request $request) {
|
||||
return Limit::perMinute(60)->by((string) ($request->header('X-Device-Token') ?? $request->ip()));
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,6 @@ class PlanService
|
||||
|
||||
public function proPriceMinor(): int
|
||||
{
|
||||
return (int) config('frontdesk.plans.pro.price_minor', 9900);
|
||||
return (int) config('frontdesk.plans.pro.price_minor', 10000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user