Issues (7)

src/FetchSubscriptionsDataFromPaystackApi.php (3 issues)

1
<?php
2
3
namespace Digikraaft\PaystackSubscriptionsTile;
4
5
use Digikraaft\Paystack\Paystack;
6
use Digikraaft\Paystack\Subscription;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Carbon;
9
10
class FetchSubscriptionsDataFromPaystackApi extends Command
11
{
12
    protected $signature = 'dashboard:fetch-subscriptions-data-from-paystack-api';
13
14
    protected $description = 'Fetch data for paystack subscriptions tile';
15
16
    public function handle()
17
    {
18
        Paystack::setApiKey(config('dashboard.tiles.paystack.secret_key', env('PAYSTACK_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
        Paystack::setApiKey(/** @scrutinizer ignore-call */ config('dashboard.tiles.paystack.secret_key', env('PAYSTACK_SECRET')));
Loading history...
19
20
        $this->info('Fetching Paystack subscriptions ...');
21
22
        $subscriptions = Subscription::list(
23
            config('dashboard.tiles.paystack.subscriptions.params') ?? [
24
                'perPage' => 4,
25
            ]
26
        );
27
28
        $subscriptions = collect($subscriptions->data)
29
            ->map(function ($subscription) {
30
                return [
31
                    'customer' => $subscription->customer->email,
32
                    'plan' => $subscription->plan->name,
33
                    'plan_id' => $subscription->plan->id,
34
                    'plan_interval' => $subscription->plan->interval,
35
                    'status' => $subscription->status,
36
                    'start' => $subscription->start,
37
                    'quantity' => $subscription->quantity,
38
                    'currency' => $subscription->plan->currency,
39
                    'subsctiption_code' => $subscription->subscription_code,
40
                    'amount' => $this->formatMoney($subscription->amount),
41
                    'next_payment_date' => Carbon::parse($subscription->next_payment_date)
42
                        ->setTimezone('UTC')
43
                        ->format("d.m.Y"),
44
                    'id' => $subscription->id,
45
                    'createdAt' => Carbon::parse($subscription->createdAt)
46
                        ->setTimezone('UTC')
47
                        ->format("d.m.Y"),
48
                ];
49
            })->toArray();
50
51
        PaystackSubscriptionsStore::make()->setData($subscriptions);
52
53
        $this->info('All done!');
54
55
        return 0;
56
    }
57
58
    /**
59
     * @param string $amount
60
     * @return float
61
     */
62
    public function formatMoney(string $amount): string
63
    {
64
        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 ignore-type  annotation

64
        return number_format(/** @scrutinizer ignore-type */ ($amount), 2, '.', ',');
Loading history...
Bug Best Practice introduced by
The expression return number_format($amount, 2, '.', ',') returns the type string which is incompatible with the documented return type double.
Loading history...
65
    }
66
}
67