/** * Create a currency object, store it to the instances and return it. * * <code> * $currencyId = 1; * * $currency = VirtualCurrencyCurrency::getInstance(JFactory::getDbo(), $currencyId); * </code> * * @param JDatabaseDriver $db * @param integer $id * * @return null|self */ public static function getInstance($db, $id) { if (!isset(self::$instances[$id])) { $currency = new VirtualCurrencyCurrency($db); $currency->load($id); self::$instances[$id] = $currency; } return self::$instances[$id]; }
/** * @param JApplicationSite $app * @param array $paymentProcessData */ protected function prepareCurrency($app, $paymentProcessData) { // Load currencies $options = array("state" => 1); jimport("virtualcurrency.currencies"); $this->currencies = new VirtualCurrencyCurrencies(JFactory::getDbo()); $this->currencies->load($options); // Get amount from session $this->currencyAmount = $paymentProcessData["amount"]; // Get item if there is one $itemId = $paymentProcessData["item_id"]; if (!empty($itemId)) { $item = new VirtualCurrencyCurrency(JFactory::getDbo()); $item->load($itemId); // Compare amount with the minimum allowed amount. if ($this->currencyAmount < $item->getParam("minimum")) { // Reset payment data. $paymentProcessData = $this->paymentData; $app->setUserState("payment.data", $paymentProcessData); $this->layoutData->flagStep1 = false; } } // Check days left. If there is no days, disable the button. $this->disabledButton = ""; // Check for debug mode if ($this->params->get("debug_payment_disabled", 0)) { $msg = JString::trim($this->params->get("debug_disabled_functionality_msg")); if (!$msg) { $msg = JText::_("COM_VIRTUALCURRENCY_DEBUG_MODE_DEFAULT_MSG"); } $app->enqueueMessage($msg, "notice"); $this->disabledButton = 'disabled="disabled"'; } }
/** * Process step 1. */ public function step1() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $userId = JFactory::getUser()->get("id"); if (!$userId) { $redirectOptions = array("force_direction" => "login_form"); $this->displayNotice(JText::_('COM_VIRTUALCURRENCY_ERROR_NOT_LOG_IN'), $redirectOptions); return; } $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get the data from the form $itemId = $this->input->post->getInt('id', 0); $redirectOptionsError = array("view" => "peyment"); // Check for maintenance (debug) state $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ if ($this->inDebugMode($params)) { return; } // Check terms and use if ($params->get("ordering_service_terms", 0)) { $terms = $app->input->post->get("terms", 0); if (!$terms) { $this->displayNotice(JText::_("COM_VIRTUALCURRENCY_ERROR_TERMS_NOT_ACCEPTED"), $redirectOptionsError); return; } } // Check for valid number of units. $amount = $app->input->post->get("amount", 0, "float"); if (!$amount) { $this->displayNotice(JText::_('COM_VIRTUALCURRENCY_ERROR_INVALID_AMOUNT'), $redirectOptionsError); return; } // Check for valid item $item = new VirtualCurrencyCurrency(JFactory::getDbo()); $item->load($itemId); if (!$item->getId()) { $this->displayNotice(JText::_('COM_VIRTUALCURRENCY_ERROR_INVALID_CURRENCY'), $redirectOptionsError); return; } // Check for valid allowed items for buying if ($amount < $item->getParam("minimum")) { $this->displayNotice(JText::_('COM_VIRTUALCURRENCY_ERROR_INVALID_AMOUNT'), $redirectOptionsError); return; } $paymentProcessData = $app->getUserState("payment.data"); $paymentProcessData["item_id"] = $item->getId(); $paymentProcessData["amount"] = $amount; $paymentProcessData["step1"] = true; // Store data to temporary table $data = array("user_id" => $userId, "currency_id" => $item->getId(), "amount" => $amount); jimport("virtualcurrency.payment.session"); $paymentSession = new VirtualCurrencyPaymentSession(JFactory::getDbo()); if (!empty($paymentProcessData["payment_id"])) { $paymentSession->load($paymentProcessData["payment_id"]); } $paymentSession->bind($data); $paymentSession->store(); // Remove old payment session records $paymentSession->cleanOld(); $paymentProcessData["payment_id"] = $paymentSession->getId(); // Set payment data to the sessions $app->setUserState("payment.data", $paymentProcessData); // Redirect to next page $redirectOptions = array("view" => "payment", "layout" => "services"); $link = $this->prepareRedirectLink($redirectOptions); $this->setRedirect(JRoute::_($link, false)); }