Advertisement
a6a51

Jobs command

Mar 20th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Jobs;
  4.  
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Queue\SerializesModels;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Contracts\Queue\ShouldQueue;
  9. use Illuminate\Foundation\Bus\Dispatchable;
  10. use App\PaymentConfirmation;
  11. use Carbon\Carbon;
  12. use App\Notifications\InvoicePaid;
  13. use App\TrainingOrder;
  14. use App\UserTicket;
  15.  
  16. class CheckPayment implements ShouldQueue
  17. {
  18.     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  19.  
  20.     protected $payment;
  21.  
  22.     public function __construct(PaymentConfirmation $payment)
  23.     {
  24.         $this->payment = $payment;
  25.     }
  26.  
  27.     /**
  28.      * Execute the job.
  29.      *
  30.      * @return void
  31.      */
  32.     public function handle()
  33.     {
  34.         if ($this->payment->created_at->diffInMinutes() >= 5) {
  35.             $this->payment->status = 2;
  36.             $this->payment->save();
  37.  
  38.             $training_order = TrainingOrder::findOrFail($this->payment->order_id);
  39.             $training_order->status = TrainingOrder::CANCEL;
  40.             $training_order->save();
  41.  
  42.             UserTicket::where('training_order_id', $training_order->id)
  43.                 ->update(['status' => UserTicket::CANCEL]);
  44.  
  45.             $user = $this->payment->order->user;
  46.             $user->trainings()
  47.                 ->where('training_id', $training_order->training_id)
  48.                 ->updateExistingPivot($training_order->training_id, ['type' => 'unconfirmed']);
  49.  
  50.             $this->payment->order->user->notify(new InvoicePaid($this->payment));
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement