SendOrderNotifications.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\RestoSMSs;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use Illuminate\Support\Facades\Http;
  10. use Illuminate\Support\Facades\Log;
  11. class SendOrderNotifications implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. private $params;
  15. /**
  16. * Create a new job instance.
  17. *
  18. * @return void
  19. */
  20. public function __construct($params)
  21. {
  22. $this->params = $params;
  23. }
  24. /**
  25. * Execute the job.
  26. *
  27. * @return void
  28. */
  29. public function handle()
  30. {
  31. //
  32. $url = $this->params['url'];
  33. $message_data = $this->params['message_data'];
  34. $sms_id = $this->params['sms_id'];
  35. $response = Http::acceptJson()->post($url,$message_data);
  36. $response = $response->json();
  37. $response = json_encode($response);
  38. Log::info('TRACK_ORDER_SMS Response: '.$response);
  39. Log::info('Job Started: '.$sms_id);
  40. $sms = RestoSMSs::find($sms_id);
  41. $sms->otp_req = json_encode($message_data);
  42. $resp = json_decode($response);
  43. $sms->otp_req_status = strtoupper($resp->status)=="ACCEPTED"?"SUCCESS":"FAIL";
  44. $sms->otp_res = $response;
  45. $sms->save();
  46. }
  47. }