function sendEmail($reservationId)
 {
     $reservationService = new ReservationService();
     $reservationDetails = $reservationService->getReservation($reservationId);
     return EmailService::sendConfirmationEmail($reservationDetails);
 }
 function save()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN', true));
     $app = JFactory::getApplication();
     $model = $this->getModel('customeraccount');
     $post = JRequest::get('post');
     $data = JRequest::get('post');
     $context = 'com_jhotelreservation.edit.reservation';
     $task = $this->getTask();
     $recordId = JRequest::getInt('reservationId');
     if (!$model->save($post)) {
         // Save the data in the session.
         $app->setUserState('com_jhotelreservation.edit.reservation.data', $data);
         // Redirect back to the edit screen.
         $this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()), 'warning');
         $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&task=customeraccount.editreservation&reservationId=' . $recordId), true);
         return false;
     }
     $this->setMessage(JText::_('LNG_RESERVATION_SAVE_SUCCESS', true));
     $reservationService = new ReservationService();
     $reservationDetails = $reservationService->getReservation($recordId);
     $emailService = new EmailService();
     $emailService->sendConfirmationEmail($reservationDetails, true);
     return true;
 }
 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 sendConfirmationEmail($reservationDetails)
 {
     EmailService::sendConfirmationEmail($reservationDetails);
 }