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(); + } +}; +?> + +
{{ $error }}
+Available
++ ${{ number_format($available['amount'], 2) }} + {{ $available['currency'] }} +
+Pending
++ ${{ number_format($pending['amount'], 2) }} + {{ $pending['currency'] }} +
+Cached for 15 min
+