function processPayment()
 {
     $appSettings = JHotelUtil::getInstance()->getApplicationSettings();
     $paymentMethod = JRequest::getVar("payment_method");
     if (!$appSettings->is_enable_payment) {
         $paymentMethod = "cash";
     }
     $paymentModel = $this->getModel("PaymentOptions");
     $reservationDetails = $paymentModel->getReservationDetails();
     $reservationDetails->paymentMethod = $paymentMethod;
     $confirmationModel = $this->getModel("Confirmation");
     $confirmationId = $confirmationModel->saveConfirmation($reservationDetails);
     $reservationDetails->confirmation_id = $confirmationId;
     if ($confirmationId == -1) {
         $this->setMessage(JText::_('LNG_NO_ROOMS_AVAILABLE', true));
         $this->setRedirect(JRoute::_('index.php?option=com_jhotelreservation&view=paymentoptions', $msg));
         return;
     }
     $processor = PaymentService::createPaymentProcessor($paymentMethod);
     $paymentDetails = $processor->processTransaction($reservationDetails);
     PaymentService::addPayment($paymentDetails);
     if ($paymentDetails->status == PAYMENT_REDIRECT) {
         $document = JFactory::getDocument();
         $viewType = $document->getType();
         $view = $this->getView("paymentoptions", $viewType, '', array('base_path' => $this->basePath, 'layout' => "redirect"));
         $view->paymentProcessor = $processor;
         $view->display("redirect");
     } else {
         if ($paymentDetails->status == PAYMENT_IFRAME) {
             $document = JFactory::getDocument();
             $viewType = $document->getType();
             $view = $this->getView("paymentoptions", $viewType, '', array('base_path' => $this->basePath, 'layout' => "iframe"));
             $view->paymentProcessor = $processor;
             $view->display("iframe");
         } else {
             if ($paymentDetails->status == PAYMENT_SUCCESS) {
                 $reservationDetails = $confirmationModel->getReservation($confirmationId);
                 $confirmationModel->sendConfirmationEmail($reservationDetails);
                 UserDataService::initializeReservationData();
                 UserDataService::initializeExcursions();
                 $this->setRedirect(JRoute::_('index.php?option=com_jhotelreservation&task=confirmation.viewConfirmation&reservationId=' . $confirmationId, false));
             } else {
                 if ($paymentDetails->status == PAYMENT_WAITING) {
                     $reservationDetails = $confirmationModel->getReservation($confirmationId);
                     $confirmationModel->sendConfirmationEmail($reservationDetails);
                     UserDataService::initializeReservationData();
                     UserDataService::initializeExcursions();
                     $this->setRedirect(JRoute::_('index.php?option=com_jhotelreservation&task=confirmation.viewConfirmation&reservationId=' . $confirmationId, false));
                 } else {
                     if ($paymentDetails->status == PAYMENT_ERROR) {
                         $app = JFactory::getApplication();
                         $app->enqueueMessage($paymentDetails->error_message, 'warning');
                         JRequest::setVar("view", "paymentoptions");
                         parent::display();
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
 function processTransaction()
 {
     $appSettings = JBusinessUtil::getInstance()->getApplicationSettings();
     $paymentMethod = JRequest::getVar("payment_method", "nopayment");
     $paymentModel = $this->getModel("Payment");
     $order_id = JRequest::getVar("orderId", null);
     $paymentModel->setState('payment.orderId', $order_id);
     //create and login user(if not created)
     $user = JFactory::getUser();
     $companyId = JRequest::getVar("companyId");
     $orderModel = $this->getModel("Orders");
     $order = $orderModel->getOrder($order_id);
     $orderModel->saveOrder($order);
     $processor = PaymentService::createPaymentProcessor($paymentMethod);
     $paymentDetails = $processor->processTransaction($order);
     $paymentDetails->details = $processor->getPaymentDetails($paymentDetails);
     PaymentService::addPayment($paymentDetails);
     if ($paymentDetails->status == PAYMENT_REDIRECT) {
         $document = JFactory::getDocument();
         $viewType = $document->getType();
         $view = $this->getView("payment", $viewType, '', array('base_path' => $this->basePath, 'layout' => "redirect"));
         $view->paymentProcessor = $processor;
         $view->display("redirect");
     } else {
         if ($paymentDetails->status == PAYMENT_SUCCESS) {
             $orderModel = $this->getModel("Orders");
             $order = $orderModel->updateOrder($paymentDetails, $processor);
             $msg = JText::_("LNG_PAYMENT_PROCESSED_SUCCESSFULLY");
             $paymentModel->sendPaymentEmail($paymentDetails);
             $this->setRedirect(JRoute::_('index.php?option=com_jbusinessdirectory&view=orders', false), $msg);
         } else {
             if ($paymentDetails->status == PAYMENT_WAITING) {
                 $msg = JText::_("LNG_PAYMENT_WAITING");
                 $paymentModel->sendPaymentDetailsEmail($paymentDetails);
                 $this->setRedirect(JRoute::_('index.php?option=com_jbusinessdirectory&view=orders', false), $msg);
             } else {
                 if ($paymentDetails->status == PAYMENT_ERROR) {
                     JRequest::setVar("view", "payment");
                     parent::display();
                 }
             }
         }
     }
 }
 /**
  * Method to save the form data.
  *
  * @param   array  The form data.
  * @return  boolean  True on success.
  */
 public function save($data)
 {
     $id = !empty($data['reservationId']) ? $data['reservationId'] : (int) $this->getState('reservation.id');
     $isNew = empty($id);
     $reservationDetails = $this->getReservationDetails($data);
     //dmp($reservationDetails);
     //exit;
     require_once JPATH_COMPONENT_SITE . '/models/confirmation.php';
     $confirmationModel = new JHotelReservationModelConfirmation();
     $reservaitonId = $confirmationModel->saveConfirmation($reservationDetails);
     if ($isNew && $reservaitonId != -1) {
         $reservationDetails->confirmation_id = $reservaitonId;
         $processor = PaymentService::createPaymentProcessor(PROCESSOR_CASH);
         $paymentDetails = $processor->processTransaction($reservationDetails);
         PaymentService::addPayment($paymentDetails);
     }
     if ($reservaitonId != -1) {
         $this->setState('reservation.id', $reservaitonId);
     } else {
         $this->setState('reservation.id', $id);
         $this->setError($confirmationModel->getError());
         return false;
     }
     // Clean the cache
     $this->cleanCache();
     return true;
 }