Exemplo n.º 1
0
 public function fire($job, $emergencyId)
 {
     Log::debug($emergencyId);
     $this->login = getenv('SMS_LOGIN');
     $this->pass = getenv('SMS_PASS');
     $emergency = Emergency::find($emergencyId);
     if (!$emergency) {
         return $job->delete();
     }
     if ($emergency->delivered_at) {
         return $job->delete();
     }
     $createdAt = Carbon::createFromTimestamp($emergency->created_at);
     // Check feedback only if 30 seconds passed
     if ($createdAt->diffInSeconds(Carbon::now()) > 30) {
         $this->checkResults($emergency, function (Response $response) use($emergency, $job) {
             //				var_dump($response->xml());
             Log::debug('SMS Checker', ['sms']);
             Log::debug($response->getBody(true), ['sms']);
             $payload = $response->xml()->httpOut->sms;
             if ($payload['delivered_date'] && (int) $payload['result_id'] != 7) {
                 $emergency->delivered_at = Carbon::parse((string) $payload['delivered_date']);
                 $emergency->via_sms = true;
                 $emergency->getMembersTokens()->each(function ($token) use($emergency) {
                     $state = new StateSender($token->auth_token);
                     $state->updateCounts('emergencies', $emergency->id);
                     $state->setEmergencyAsDelivered($emergency->id, $emergency->delivered_at, true);
                     $state->send();
                 });
             }
             if (!in_array((int) $payload['result_id'], [2, 3, 4, 6, 8])) {
                 $emergency->failed = true;
                 $emergency->delivered_at = null;
             }
             $job->delete();
             return $emergency->save();
         });
     } else {
         $job->release(10);
     }
 }
Exemplo n.º 2
0
 private function updateCounts(StateSender $state, $chat)
 {
     $state->updateCounts('carChats', $chat->id);
 }
Exemplo n.º 3
0
 private function updateCounts($chat)
 {
     Auth::user()->devices->map(function ($device) use($chat) {
         $state = new StateSender($device->auth_token);
         $state->updateCounts('chats', $chat->id);
         $state->send();
     });
 }