| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Digikraaft\PaystackTransactionsTile; |
||||
| 4 | |||||
| 5 | use Digikraaft\Paystack\Paystack; |
||||
| 6 | use Digikraaft\Paystack\Transaction; |
||||
| 7 | use Illuminate\Console\Command; |
||||
| 8 | use Illuminate\Support\Carbon; |
||||
| 9 | |||||
| 10 | class FetchTransactionsDataFromPaystackApi extends Command |
||||
| 11 | { |
||||
| 12 | protected $signature = 'dashboard:fetch-transactions-data-from-paystack-api'; |
||||
| 13 | |||||
| 14 | protected $description = 'Fetch data for paystack transactions 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
Loading history...
|
|||||
| 19 | |||||
| 20 | $this->info('Fetching Paystack transactions ...'); |
||||
| 21 | |||||
| 22 | $transactions = Transaction::list( |
||||
| 23 | config('dashboard.tiles.paystack.transactions.params') ?? [ |
||||
| 24 | 'perPage' => 5, |
||||
| 25 | ] |
||||
| 26 | ); |
||||
| 27 | |||||
| 28 | $transactions = collect($transactions->data) |
||||
| 29 | ->map(function ($transaction) { |
||||
| 30 | return [ |
||||
| 31 | 'amount' => $this->formatMoney($transaction->amount), |
||||
| 32 | 'currency' => $transaction->currency, |
||||
| 33 | 'reference' => $transaction->reference, |
||||
| 34 | 'status' => $transaction->status, |
||||
| 35 | 'customer' => $transaction->customer->email, |
||||
| 36 | 'id' => $transaction->id, |
||||
| 37 | 'createdAt' => Carbon::parse($transaction->created_at) |
||||
| 38 | ->setTimezone('UTC') |
||||
| 39 | ->format("d.m.Y"), |
||||
| 40 | ]; |
||||
| 41 | })->toArray(); |
||||
| 42 | |||||
| 43 | PaystackTransactionsStore::make()->setData($transactions); |
||||
| 44 | |||||
| 45 | $this->info('All done!'); |
||||
| 46 | |||||
| 47 | return 0; |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | /** |
||||
| 51 | * @param string $amount |
||||
| 52 | * @return float |
||||
| 53 | */ |
||||
| 54 | public function formatMoney(string $amount): string |
||||
| 55 | { |
||||
| 56 | return number_format(($amount), 2, '.', ','); |
||||
|
0 ignored issues
–
show
$amount of type string is incompatible with the type double expected by parameter $number of number_format().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 57 | } |
||||
| 58 | } |
||||
| 59 |