<label><?php echo JText::sprintf("COM_VIRTUALCURRENCY_NUMBER_OF_CURRENCY", $this->escape($currency->getTitle())); ?> </label> <?php echo JHtml::_("virtualcurrency.inputAmount", $this->currencyAmount, $currency_, array("name" => "amount")); ?> <span class="help-block"> <?php echo JText::sprintf("COM_VIRTUALCURRENCY_HELP_MIN_AMOUNT", $this->escape($currency->getTitle()), $currency->getParam("minimum")); ?> </span> <input type="hidden" name="id" value="<?php echo $currency->getId(); ?> "/> <input type="hidden" name="task" value="payment.step1"/> <?php echo JHtml::_('form.token'); ?> <?php if ($this->params->get("ordering_service_terms", 0)) { ?> <input type="hidden" name="terms" value="0" class="vc-terms"/> <?php } ?>
/** * 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)); }