public function testPullReservation() { $output = new \stdClass(); $files = ['reservation.xml', 'modification.xml', 'cancellation.xml']; foreach ($files as $file) { $xmlFile = __DIR__ . '/../../../../../../data/xmlFiles/' . $file; $xml = file_get_contents($xmlFile); $this->assertTrue(file_exists($xmlFile), "XML sample file not found"); $parser = new ReservationCubilisXMLParser($xml); $this->assertTrue($parser->isSuccess(), "Problem in xml parser"); if ($parser->isSuccess()) { $output->status = 'success'; $output->message = 'Check successfull.'; $output->data = $parser->getReservationList(); } else { $output->status = 'error'; $output->message = $parser->getError()->message; $output->code = $parser->getError()->code; } if ($output->status == 'success') { $reservation = $output->data; // test for apartment reservation $this->handleReservations($reservation, 42, false); // test for apartel reservation $this->handleReservations($reservation, 1, true); } } }
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; }