GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/console.fixgini.com/app/Jobs/CompleteBookingJob.php
<?php

namespace App\Jobs;

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\BookingForm;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\SerializesModels;

class CompleteBookingJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

        public $bookingId;

    public function __construct($bookingId)
    {
        $this->bookingId = $bookingId;
    }

   public function handle()
    {
        $booking = BookingForm::find($this->bookingId);
        if ($booking && $booking->status !== 'completed') {
            // Call the completeBooking logic here
            $booking->update(['status' => 'completed']);

            // Credit service provider logic
            $payment = $booking->payment;
            $toCredit = $payment && $payment->payment_status === 'completed' ? $payment->amount : 0;
            $provider_wallet = $booking->gig->user->wallet;

            if ($provider_wallet) {
                $provider_wallet->update([
                    'balance' => $provider_wallet->available + $toCredit,
                    'pending' => $provider_wallet->pending - $toCredit,
                ]);
            }
            info('Booking completed automatically');
        }
    }
}