| Total Complexity | 2 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class FetchBalancesDataFromStripeApi extends Command |
||
| 10 | { |
||
| 11 | protected $signature = 'dashboard:fetch-balances-data-from-stripe-api'; |
||
| 12 | |||
| 13 | protected $description = 'Fetch data for Stripe balances tile'; |
||
| 14 | |||
| 15 | public function handle() |
||
| 16 | { |
||
| 17 | Stripe::setApiKey( |
||
| 18 | config('dashboard.tiles.stripe.secret_key', env('STRIPE_SECRET')) |
||
|
|
|||
| 19 | ); |
||
| 20 | |||
| 21 | $this->info('Fetching Stripe balances ...'); |
||
| 22 | |||
| 23 | $balances = Balance::retrieve(); |
||
| 24 | |||
| 25 | $balances = collect($balances->available) |
||
| 26 | ->map(function ($balance) { |
||
| 27 | return [ |
||
| 28 | 'amount' => $this->toReadableAmount($balance->amount), |
||
| 29 | 'currency' => strtoupper($balance->currency), |
||
| 30 | ]; |
||
| 31 | })->toArray(); |
||
| 32 | |||
| 33 | StripeBalancesStore::make()->setData($balances); |
||
| 34 | |||
| 35 | $this->info('All done!'); |
||
| 36 | |||
| 37 | return 0; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function toReadableAmount($baseAmount) |
||
| 43 | } |
||
| 44 | } |
||
| 45 |