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