Issues (5)

src/FetchCustomersDataFromStripeApi.php (1 issue)

Labels
Severity
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
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
            /** @scrutinizer ignore-call */ 
19
            config('dashboard.tiles.stripe.secret_key', env('STRIPE_SECRET'))
Loading history...
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