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');
}
}
}