1 | <?php |
||
2 | |||
3 | namespace Digikraaft\StripeCustomersTile; |
||
4 | |||
5 | use Illuminate\Console\Command; |
||
6 | use Illuminate\Support\Carbon; |
||
7 | use Stripe\StripeClient; |
||
8 | |||
9 | class FetchCustomersDataFromStripeApi extends Command |
||
10 | { |
||
11 | protected $signature = 'dashboard:fetch-customers-data-from-stripe-api'; |
||
12 | |||
13 | protected $description = 'Fetch data for Stripe Customers tile'; |
||
14 | |||
15 | public function handle() |
||
16 | { |
||
17 | $stripe = new StripeClient( |
||
18 | config('dashboard.tiles.stripe.secret_key', env('STRIPE_SECRET')) |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
19 | ); |
||
20 | |||
21 | $this->info('Fetching Stripe customers ...'); |
||
22 | |||
23 | $customers = $stripe->customers->all( |
||
24 | config('dashboard.tiles.stripe.customers.params') ?? ['limit' => 5] |
||
25 | ); |
||
26 | |||
27 | $customers = collect($customers->data) |
||
28 | ->map(function ($customer) { |
||
29 | return [ |
||
30 | 'name' => $customer->name, |
||
31 | 'customer_id' => $customer->id, |
||
32 | 'email' => $customer->email, |
||
33 | 'createdAt' => Carbon::parse($customer->created) |
||
34 | ->format("d.m.Y"), |
||
35 | ]; |
||
36 | })->toArray(); |
||
37 | |||
38 | StripeCustomersStore::make()->setData($customers); |
||
39 | |||
40 | $this->info('All done!'); |
||
41 | |||
42 | return 0; |
||
43 | } |
||
44 | } |
||
45 |