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");
 }
Example #2
0
 public function checkAvailability()
 {
     $hotelId = 110;
     $startDate = "2013-10-05";
     $endDate = "2013-10-07";
     $isHotelAvailable = HotelService::checkAvailability($hotelId, $startDate, $endDate);
     dmp($isHotelAvailable);
     if (!$isHotelAvailable) {
         EmailService::sendNoAvailabilityEmail($hotelId, $startDate, $endDate);
     }
 }