billingSnapshot($account?->public_id); return view('hosting.account.wallet', [ 'balanceMinor' => $balanceMinor, 'spentMinor' => (int) ($ledger['spent_minor'] ?? 0), 'creditedMinor' => (int) ($ledger['credited_minor'] ?? 0), 'topupUrl' => $this->topupUrl(), ]); } public function billing(): View { $account = ladill_account(); [$balanceMinor, $ledger] = $this->billingSnapshot($account?->public_id); return view('hosting.account.billing', [ 'balanceMinor' => $balanceMinor, 'spentMinor' => (int) ($ledger['spent_minor'] ?? 0), 'creditedMinor' => (int) ($ledger['credited_minor'] ?? 0), 'topupUrl' => $this->topupUrl(), ]); } public function settings(): View { $account = ladill_account(); $settings = HostingSetting::firstOrNew(['user_id' => $account?->id]); return view('hosting.account.settings', [ 'account' => $account, 'settings' => $settings, ]); } public function updateSettings(Request $request): RedirectResponse { $account = ladill_account(); $data = $request->validate([ 'notify_email' => ['nullable', 'email', 'max:255'], 'product_updates' => ['nullable', 'boolean'], ]); HostingSetting::updateOrCreate( ['user_id' => $account->id], [ 'notify_email' => $data['notify_email'] ?? null, 'product_updates' => $request->boolean('product_updates'), ], ); return redirect()->route('account.settings')->with('success', 'Settings saved.'); } /** * @return array{0:int,1:array} [balanceMinor, ledger] */ private function billingSnapshot(?string $publicId): array { if (! $publicId) { return [0, []]; } try { return [ $this->wallet->balanceMinor(ladill_account()), $this->billing->serviceLedger($publicId, (string) config('billing.service', 'hosting')), ]; } catch (\Throwable $e) { report($e); return [0, []]; } } }