/** * Remove a payment session record or change the state of a payment session record. * * @param VirtualCurrencyPaymentSession $paymentSession * @param string $txnStatus */ protected function removePaymentSession($paymentSession, $txnStatus) { // If status is NOT completed set the state of the session to pending. /** @todo do it in next release */ if (strcmp("completed", $txnStatus) != 0) { // If transaction status is completed, remove the record. } elseif (strcmp("completed", $txnStatus) == 0) { $paymentSession->delete(); } }
/** * 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)); }