Пример #1
0
 public function checkReservation($params)
 {
     /**
      * @var Response $response
      */
     $output = new \stdClass();
     try {
         $apartmentId = $this->getApartmentId($params);
         $generator = new RoomInformationGenerator();
         $xml = $generator->generateRI(['credentials' => $this->getCredentials($apartmentId), 'params' => $params]);
         if ($xml === false) {
             $errorMessage = 'Cannot generate xml: ' . $generator->getErrors();
             $this->gr2crit('Cannot generate XML', ['full_message' => $generator->getErrors()]);
             throw new \Exception($errorMessage);
         }
         try {
             if (!ChannelManager::dontLogThatYouDontWantYouToLog($xml)) {
                 $this->gr2debug('Cubilis XML: ' . ChannelManager::LOGGING_REQUEST, ['xml' => ChannelManager::replaceSensitiveData($xml), 'apartment_id' => $apartmentId, 'request_type' => ChannelManager::REQUEST_RESERVATION]);
             }
         } catch (\Exception $ex) {
             $this->gr2logException($ex, 'Cubilis: XML Request logging failed', $params);
         }
         $this->client->setUri($this->getUrl('get_reservation'));
         $this->client->setRawBody($xml);
         $response = $this->client->send();
         if ($response->getStatusCode() == 200) {
             try {
                 if (!ChannelManager::dontLogThatYouDontWantYouToLog($response->getBody())) {
                     $this->gr2debug('Cubilis XML: ' . ChannelManager::LOGGING_RESPONSE, ['xml' => ChannelManager::replaceSensitiveData($response->getBody()), 'apartment_id' => $apartmentId, 'request_type' => ChannelManager::REQUEST_RESERVATION]);
                 }
             } catch (\Exception $ex) {
                 $this->gr2logException($ex, 'Cubilis: XML Request logging failed', $params);
             }
             $parser = new ReservationCubilisXMLParser($response->getBody());
             if ($parser->isSuccess()) {
                 $output->status = CivilResponder::STATUS_SUCCESS;
                 $output->message = 'Check successfull.';
                 $output->data = $parser->getReservationList();
             } else {
                 $output->status = CivilResponder::STATUS_ERROR;
                 $output->message = $parser->getError()->message;
                 $output->code = $parser->getError()->code;
             }
         } else {
             $this->gr2alert('Cubilis is down.', ['response_code' => $response->getStatusCode()]);
             throw new \Exception('Cubilis is down. Page status code: ' . $response->getStatusCode());
         }
     } catch (\Exception $ex) {
         $output->status = CivilResponder::STATUS_ERROR;
         $output->message = "Reservation check failed: {$ex->getMessage()}";
         $output->code = $ex->getCode();
     }
     return $output;
 }