function checkout() { $session = JFactory::getSession(); $app = JFactory::getApplication(); $Itemid = JRequest::getInt("Itemid", 0); $processor = JRequest::getVar("processor", ''); $session->set('processor', $processor); $returnpage = JRequest::getVar("returnpage", ""); $_Itemid = $Itemid; $user = JFactory::getUser(); $cart = $this->_model; $plugins_enabled = $cart->getPluginList(); // set default redirect url $uri = JURI::getInstance(); //echo $uri->toString();die; $return = base64_encode($uri->toString()); // Check Login if (!$user->id or $this->_customer->_user->id < 1) { $this->setRedirect(JRoute::_("index.php?option=com_digicom&view=register&layout=register_cart&return=" . $return)); return true; } // Check Payment Plugin installed if (empty($plugins_enabled)) { $msg = JText::_('COM_DIGICOM_PAYMENT_PLUGIN_NOT_INSTALLED'); $this->setRedirect(JRoute::_("index.php?option=com_digicom&view=cart"), $msg); return; } $customer = $this->_customer; $configs = $this->_config; $askforbilling = $configs->get('askforbilling', 0); // return -1 for not found core info, 2 for missing billing info, 1 for has core info $res = DigiComSiteHelperDigiCom::checkProfileCompletion($customer, $askforbilling); //if username, firstname, email, id not found for user if ($res < 1) { $this->setRedirect("index.php?option=com_digicom&view=profile&layout=edit&processor=" . $processor . '&return=' . $return); } $plugin = JPluginHelper::getPlugin('digicom_pay', $processor); $pluginParams = json_decode($plugin->params); if ($askforbilling != 0 && $res == 2 or isset($pluginParams->askforbilling) && $pluginParams->askforbilling && $res == 2) { $this->setRedirect("index.php?option=com_digicom&view=profile&layout=edit&processor=" . $processor . '&return=' . $return); JFactory::getApplication()->enqueueMessage(JText::_('COM_DIGICOM_BILLING_INFO_REQUIRED')); return true; } if ($res == 1) { $fromsum = JRequest::getVar('fromsum', '0'); if (!$fromsum) { $this->setRedirect(JRoute::_("index.php?option=com_digicom&view=cart&layout=summary&processor=" . $processor)); return true; } $name = $this->_customer->_user->name; $name_array = explode(" ", $name); $first_name = ""; $last_name = ""; if (count($name_array) == 1) { $first_name = $name; $last_name = $name; } else { $last_name = $name_array[count($name_array) - 1]; unset($name_array[count($name_array) - 1]); $first_name = implode(" ", $name_array); } $db = JFactory::getDBO(); $sql = "SELECT `firstname`, `lastname` FROM #__digicom_customers WHERE id=" . intval($this->_customer->_user->id); $db->setQuery($sql); $db->query(); $result = $db->loadObject(); if (isset($result) && (trim($result->firstname) == "" || trim($result->lastname) == "")) { $sql = "UPDATE #__digicom_customers set `firstname`='" . addslashes(trim($first_name)) . "', `lastname`='" . addslashes(trim($last_name)) . "' where id=" . intval($this->_customer->_user->id); } elseif (!$result) { $sql = "INSERT INTO #__digicom_customers(`id`, `firstname`, `lastname`) VALUES (" . intval($this->_customer->_user->id) . ", '" . addslashes(trim($first_name)) . "', '" . addslashes(trim($last_name)) . "')"; } $db->setQuery($sql); $db->query(); $this->_customer = new DigiComSiteHelperSession(); $customer = $this->_customer; } $menu = $app->getMenu()->getItems('link', 'index.php?option=com_digicom&view=orders', true); $Itemid = isset($item->id) ? '&Itemid=' . $item->id : ''; $total = 0; $fromsum = JRequest::getVar('fromsum', '0'); $items = $cart->getCartItems($customer, $configs); $tax = $cart->calc_price($items, $customer, $configs); $total = $tax['taxed']; $now = time(); if ((double) $total == 0) { if (count($items) != "0") { $orderid = $cart->addFreeProduct($items, $customer, $tax); // Order complete, now redirect to the original page if ($configs->get('afterpurchase', 1) == 1) { $link = 'index.php?option=com_digicom&view=orders' . $Itemid; } else { $item = $app->getMenu()->getItems('link', 'index.php?option=com_digicom&view=downloads', true); $Itemid = isset($item->id) ? '&Itemid=' . $item->id : ''; $link = 'index.php?option=com_digicom&view=downloads' . $Itemid; } $this->setRedirect($link, JText::_("COM_DIGICOM_PAYMENT_FREE_PRUCHASE_COMPLETE_MESSAGE")); } } else { $db = JFactory::getDBO(); $profile = ""; $sql = "update #__digicom_session set transaction_details='" . base64_encode(serialize($customer)) . "' where sid=" . $customer->_sid; $db->setQuery($sql); $db->query(); $sql = "select processor from #__digicom_session where sid='" . $this->_customer->_sid . "'"; $db->setQuery($sql); $prosessor = $db->loadResult(); if (!isset($prosessor) || trim($prosessor) == "") { $prosessor = $processor; } //store order $order_id = $cart->addOrderInfo($items, $customer, $tax, $status = 'Pending', $prosessor); $cart->getFinalize($this->_customer->_sid, $msg = '', $order_id, $type = 'new_order'); /* Prepare params*/ $params = array(); $params['user_id'] = $this->_customer->_user->id; if (isset($this->_customer) && isset($this->_customer->_customer)) { $this->_customer->_customer->id = $user->id; $user = JFactory::getUser(); $params['customer'] = new stdClass(); $params['customer']->id = $user->id; $params['customer']->email = $user->get('email'); } $params['products'] = $items; // array of products $params['processor'] = $prosessor; //JRequest::getVar('processor'); //'payauthorize'; $gataways = JPluginHelper::getPlugin('digicom_pay', $params['processor']); if (is_array($gataways)) { foreach ($gataways as $gw) { if ($gw->name == $prosessor) { $params['params'] = $gw->params; break; } } } else { $params['params'] = $gataways->params; } $params['order_id'] = $order_id; $params['sid'] = $this->_customer->_sid; $params['order_amount'] = $items[-2]['taxed']; $params['order_currency'] = $items[-2]['currency']; $cart->storeOrderParams($user->id, $order_id, $params); $this->setRedirect(JRoute::_("index.php?option=com_digicom&view=checkout&order_id=" . $order_id . "&processor=" . $params['processor'])); } return true; }