1 | <?php |
||
2 | |||
3 | namespace Digikraaft\PaystackCustomersTile; |
||
4 | |||
5 | use Digikraaft\Paystack\Customer; |
||
6 | use Digikraaft\Paystack\Paystack; |
||
7 | use Illuminate\Console\Command; |
||
8 | use Illuminate\Support\Carbon; |
||
9 | |||
10 | class FetchCustomersDataFromPaystackApi extends Command |
||
11 | { |
||
12 | protected $signature = 'dashboard:fetch-customers-data-from-paystack-api'; |
||
13 | |||
14 | protected $description = 'Fetch data for paystack Customer tile'; |
||
15 | |||
16 | public function handle() |
||
17 | { |
||
18 | Paystack::setApiKey(config('dashboard.tiles.paystack.secret_key', env('PAYSTACK_SECRET'))); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
19 | |||
20 | $this->info('Fetching Paystack customers ...'); |
||
21 | |||
22 | $customers = Customer::list( |
||
23 | config('dashboard.tiles.paystack.customers.params') ?? [ |
||
24 | 'perPage' => 5, |
||
25 | ] |
||
26 | ); |
||
27 | |||
28 | $customers = collect($customers->data) |
||
29 | ->map(function ($customer) { |
||
30 | return [ |
||
31 | 'first_name' => $customer->first_name, |
||
32 | 'last_name' => $customer->last_name, |
||
33 | 'customer_code' => $customer->customer_code, |
||
34 | 'email' => $customer->email, |
||
35 | 'id' => $customer->id, |
||
36 | 'createdAt' => Carbon::parse($customer->createdAt) |
||
37 | ->setTimezone('UTC') |
||
38 | ->format("d.m.Y"), |
||
39 | ]; |
||
40 | })->toArray(); |
||
41 | |||
42 | PaystackCustomersStore::make()->setData($customers); |
||
43 | |||
44 | $this->info('All done!'); |
||
45 | |||
46 | return 0; |
||
47 | } |
||
48 | } |
||
49 |