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.'); } }