diff --git a/resources/views/components/⚡stripe-payout.blade.php b/resources/views/components/⚡stripe-payout.blade.php new file mode 100644 index 0000000..a62803f --- /dev/null +++ b/resources/views/components/⚡stripe-payout.blade.php @@ -0,0 +1,106 @@ +loadPayout(); + } + + public function loadPayout(): void + { + try { + $this->payout = Cache::remember('stripe_latest_payout', now()->addMinutes(15), function () { + Stripe::setApiKey(config('services.stripe.secret')); + $payouts = Payout::all(['limit' => 1]); + + if (empty($payouts->data)) { + return null; + } + + $payout = $payouts->data[0]; + + return [ + 'amount' => $payout->amount / 100, + 'currency' => strtoupper($payout->currency), + 'status' => $payout->status, + 'arrival_date' => $payout->arrival_date, + 'created' => $payout->created, + ]; + }); + $this->error = null; + } catch (\Exception $e) { + $this->error = 'Unable to fetch payout'; + $this->payout = null; + } + } + + public function refresh(): void + { + Cache::forget('stripe_latest_payout'); + $this->loadPayout(); + } + + public function statusColor(): string + { + return match($this->payout['status'] ?? '') { + 'paid' => 'green', + 'pending' => 'yellow', + 'in_transit' => 'blue', + 'canceled', 'failed' => 'red', + default => 'gray', + }; + } +}; +?> + +
+
+

Latest Payout

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

{{ $error }}

+
+ @elseif($payout) +
+
+

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

+
+
+ {{ ucfirst($payout['status']) }} +
+

+ @if($payout['status'] === 'paid') + Arrived {{ \Carbon\Carbon::createFromTimestamp($payout['arrival_date'])->format('M j, Y') }} + @else + Expected {{ \Carbon\Carbon::createFromTimestamp($payout['arrival_date'])->format('M j, Y') }} + @endif +

+
+ @elseif($payout === null && !$error) +
+

No payouts yet

+
+ @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 262c0b7..47b2ffe 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -4,8 +4,8 @@
-
- +
+