function processAutomaticResponse() { $this->log->LogDebug("process automatic response"); $data = JRequest::get('post'); $this->log->LogDebug(serialize($data)); $processorType = JRequest::getVar("processor"); $processor = PaymentService::createPaymentProcessor($processorType); $paymentDetails = $processor->processResponse($data); $this->log->LogDebug("Payment Details: " . serialize($paymentDetails)); if (empty($paymentDetails->confirmation_id)) { return; } $intialPaymentDetails = PaymentService::getConfirmationPaymentDetails($paymentDetails->confirmation_id); $this->log->LogDebug("Initial payment details: " . serialize($intialPaymentDetails)); if ($intialPaymentDetails->payment_status == PAYMENT_STATUS_PAID) { return; } //prevent e-mails to be send again to hotels and customers if ($intialPaymentDetails->payment_status == $paymentDetails->payment_status) { header("HTTP/1.1 200 OK"); return; } //check if the response is a reponse for a waiting transaction $sendMailOnlyToAdmin = $intialPaymentDetails->payment_status == PAYMENT_STATUS_WAITING && $paymentDetails->payment_status == PAYMENT_STATUS_PAID; $this->log->LogDebug("Send only to admin " . serialize($sendMailOnlyToAdmin)); PaymentService::updatePayment($paymentDetails); if ($paymentDetails->status == PAYMENT_CANCELED || $paymentDetails->status == PAYMENT_ERROR) { BookingService::cancelReservation($paymentDetails->confirmation_id); } else { $confirmationModel = $this->getModel("Confirmation"); $reservationDetails = $confirmationModel->getReservation($paymentDetails->confirmation_id); EmailService::sendConfirmationEmail($reservationDetails, $sendMailOnlyToAdmin); //check if hotels has more rooms available $hotelId = $reservationDetails->reservationData->userData->hotelId; $startDate = $reservationDetails->reservationData->userData->start_date; $endDate = $reservationDetails->reservationData->userData->end_date; $isHotelAvailable = HotelService::checkAvailability($hotelId, $startDate, $endDate); if (!$isHotelAvailable) { EmailService::sendNoAvailabilityEmail($hotelId, $startDate, $endDate); } } //http_response_code(200); header("HTTP/1.1 200 OK"); }
function getReservation($reservationId = null, $hotelId = null, $checkAvailability = true) { if (!isset($reservationId)) { $reservationId = JRequest::getInt("reservationId"); } $confirmationTable = JTable::getInstance('Confirmations', 'Table', array()); $reservation = $confirmationTable->getReservationData($reservationId); if (!$reservationId) { $reservation = UserDataService::createUserData(array()); $reservation->hotelId = $hotelId; } else { $reservation->reservedItems = explode(",", $reservation->items_reserved); $reservation->extraOptionIds = explode(",", $reservation->extraOptionIds); $reservation->hotelId = $reservation->hotel_id; $reservation->guestDetails = $this->prepareGuestDetails($reservation->guestDetails); $reservation->roomGuests = explode(",", $reservation->total_adults); $reservation->total_adults = 0; if (isset($reservation->roomGuests) && count($reservation->roomGuests) >= 1) { foreach ($reservation->roomGuests as $guestPerRoom) { $values = explode("|", $guestPerRoom); $reservation->total_adults += $values[0]; } } $reservation->roomGuestsChildren = explode(",", $reservation->children); $reservation->total_children = 0; if (isset($reservation->roomGuestsChildren) && count($reservation->roomGuestsChildren) >= 1) { foreach ($reservation->roomGuestsChildren as $guestPerRoom) { $values = explode("|", $guestPerRoom); $reservation->total_children += $values[0]; } } } //dmp($reservation->total_adults); //dmp($reservation->roomGuests); //dmp($reservation); if (!isset($reservation->totalPaid)) { $reservation->totalPaid = 0; } $hotel = HotelService::getHotel($reservation->hotelId); $reservation->currency = HotelService::getHotelCurrency($hotel); $reservationData = new stdClass(); $reservationData->userData = $reservation; $reservationData->appSettings = JHotelUtil::getInstance()->getApplicationSettings(); $reservationData->hotel = $hotel; $extraOptionIds = isset($reservationData->userData->extraOptionIds) ? $reservationData->userData->extraOptionIds : null; $extraOptions = array(); if (is_array($extraOptionIds) && count($extraOptionIds) > 0) { foreach ($extraOptionIds as $key => $value) { if (strlen($value) > 1) { $extraOption = explode("|", $value); $extraOptions[$key] = $extraOption; } } } //dmp($_SESSION["extras"]); $reservationData->extraOptions = ExtraOptionsService::getHotelExtraOptions($reservationData->userData->hotelId, $reservationData->userData->start_date, $reservationData->userData->end_date, $_SESSION["extras"], 0, 0, false); $reservationDetails = new stdClass(); if ($reservationId) { $reservationDetails = $this->generateReservationSummary($reservationData, $checkAvailability); } $reservationDetails->reservationData = $reservationData; $reservationDetails->billingInformation = $this->getBillingInformation($reservationData->userData, $reservationData->appSettings->hide_user_email); $reservationDetails->confirmation_id = $reservation->confirmation_id; $paymentDetails = PaymentService::getConfirmationPaymentDetails($reservation->confirmation_id); if (isset($paymentDetails) && $paymentDetails->confirmation_id != 0) { $reservationDetails->paymentInformation = $this->getPaymentInformation($paymentDetails, $reservationDetails->total, $reservationDetails->cost); } //dmp($reservationDetails); return $reservationDetails; }