From e4bb06b19dec338ff16e1813fcacd5d1a03fae32 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Fri, 30 Jan 2026 17:56:01 -0600 Subject: [PATCH] Show stripe balance on dashboard --- .../components/⚡stripe-balance.blade.php | 92 +++++++++++++++++++ resources/views/dashboard.blade.php | 4 +- 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 resources/views/components/⚡stripe-balance.blade.php diff --git a/resources/views/components/⚡stripe-balance.blade.php b/resources/views/components/⚡stripe-balance.blade.php new file mode 100644 index 0000000..6212b36 --- /dev/null +++ b/resources/views/components/⚡stripe-balance.blade.php @@ -0,0 +1,92 @@ +loadBalance(); + } + + public function loadBalance(): void + { + try { + $this->balance = Cache::remember('stripe_balance', now()->addMinutes(15), function () { + Stripe::setApiKey(config('services.stripe.secret')); + $balance = Balance::retrieve(); + + return [ + 'available' => collect($balance->available)->map(fn($b) => [ + 'amount' => $b->amount / 100, + 'currency' => strtoupper($b->currency), + ])->toArray(), + 'pending' => collect($balance->pending)->map(fn($b) => [ + 'amount' => $b->amount / 100, + 'currency' => strtoupper($b->currency), + ])->toArray(), + ]; + }); + $this->error = null; + } catch (\Exception $e) { + $this->error = 'Unable to fetch Stripe balance'; + $this->balance = null; + } + } + + public function refresh(): void + { + Cache::forget('stripe_balance'); + $this->loadBalance(); + } +}; +?> + +
+
+

Stripe Balance

+ +
+ + @if($error) +
+

{{ $error }}

+
+ @elseif($balance) +
+ @foreach($balance['available'] as $available) +
+

Available

+

+ ${{ number_format($available['amount'], 2) }} + {{ $available['currency'] }} +

+
+ @endforeach + @foreach($balance['pending'] as $pending) + @if($pending['amount'] > 0) +
+

Pending

+

+ ${{ number_format($pending['amount'], 2) }} + {{ $pending['currency'] }} +

+
+ @endif + @endforeach +
+ @else +
+ +
+ @endif + +

Cached for 15 min

+
\ No newline at end of file diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 8f08c05..262c0b7 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -1,8 +1,8 @@
-
- +
+