| 1 | <?php |
||
| 2 | |||
| 3 | namespace Digikraaft\StripeBalancesTile; |
||
| 4 | |||
| 5 | use Illuminate\Console\Command; |
||
| 6 | use Stripe\Balance; |
||
| 7 | use Stripe\Stripe; |
||
| 8 | |||
| 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')) |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 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) |
||
| 41 | { |
||
| 42 | return $baseAmount / 100; |
||
| 43 | } |
||
| 44 | } |
||
| 45 |