protected function returnToStep1(&$paymentSession, $message = "") { // Reset the flag for step 1 $paymentSession->step1 = false; $this->app->setUserState($this->paymentSessionContext, $paymentSession); if (!empty($message)) { $this->app->enqueueMessage($message, "notice"); } $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false)); }
/** * Check the system for debug mode */ protected function prepareDebugMode(&$paymentSession) { // Check for maintenance (debug) state $params = $this->state->get("params"); if ($params->get("debug_payment_disabled", 0)) { $msg = JString::trim($params->get("debug_disabled_functionality_msg")); if (!$msg) { $msg = JText::_("COM_CROWDFUNDING_DEBUG_MODE_DEFAULT_MSG"); } $this->app->enqueueMessage($msg, "notice"); $this->disabledButton = 'disabled="disabled"'; // Store the new values of the payment process to the user sesstion. $paymentSession->step1 = false; $this->app->setUserState($this->paymentSessionContext, $paymentSession); } }
/** * Check for duplication of session ID. * If the session ID exists, generate new one. * * @param object $item */ protected function prepareSessionId(&$item) { // Get the payment session object and session ID. $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $item->id; $paymentSession = $this->app->getUserState($paymentSessionContext); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select("COUNT(*)")->from($db->quoteName("#__cfdata_records", "a"))->where("a.session_id = " . $db->quote($paymentSession->session_id)); $db->setQuery($query, 0, 1); $result = $db->loadResult(); if (!empty($result)) { // Create payment session ID. $sessionId = new Prism\String(); $sessionId->generateRandomString(32); $paymentSession->session_id = (string) $sessionId; $this->app->setUserState($paymentSessionContext, $paymentSession); } }
/** * This method prepares a code that will be included to step "Extras" on project wizard. * * @param string $context This string gives information about that where it has been executed the trigger. * @param stdClass $item A project data. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|string */ public function onExtrasDisplay($context, $item, $params) { if (strcmp('com_crowdfunding.project.extras', $context) !== 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('html', $docType) !== 0) { return null; } if (!isset($item->user_id) or !$item->user_id) { return null; } // A flag that shows the options are active. if (!$this->params->get('display_paypal', 0) and !$this->params->get('display_banktransfer', 0) and !$this->params->get('display_stripe', 0)) { return ''; } $activeTab = ''; if ($this->params->get('display_paypal', 0)) { $activeTab = 'paypal'; } elseif ($this->params->get('display_banktransfer', 0)) { $activeTab = 'banktransfer'; } elseif ($this->params->get('display_stripe', 0)) { $activeTab = 'stripe'; } $payout = new Crowdfundingfinance\Payout(JFactory::getDbo()); $payout->setSecretKey($this->app->get('secret')); $payout->load(array('project_id' => $item->id)); // Create payout record, if it does not exists. if (!$payout->getId()) { $payout->setProjectId($item->id); $payout->store(); } // Check if Stripe connected. if ($this->params->get('display_stripe', 0)) { $stripeWarning = null; $stripeButton = array(); $cfFinanceParams = JComponentHelper::getParams('com_crowdfundingfinance'); // Get keys. $apiKeys = Crowdfundingfinance\Stripe\Helper::getKeys($cfFinanceParams); if (!$apiKeys['client_id']) { $stripeWarning = JText::_('PLG_CROWDFUNDING_PAYOUTOPTIONS_ERROR_STRIPE_NOT_CONFIGURED'); } $token = Crowdfundingfinance\Stripe\Helper::getPayoutAccessToken($apiKeys, $payout, $cfFinanceParams->get('stripe_expiration_period', 7)); // Generate state HASH and use it as a session key that contains redirect URL. $state = Prism\Utilities\StringHelper::generateRandomString(32); $stateData = array('redirect_url' => base64_encode(JRoute::_(CrowdfundingHelperRoute::getFormRoute($item->id, 'extras'), false)), 'project_id' => $item->id); $this->app->setUserState($state, $stateData); if (!$token) { $stripeButton[] = '<div class="mt-20">'; $stripeButton[] = '<a href="https://connect.stripe.com/oauth/authorize?response_type=code&client_id=' . $apiKeys['client_id'] . '&scope=read_write&state=' . $state . '&redirect_uri=' . rawurlencode($this->params->get('stripe_redirect_uri')) . '">'; $stripeButton[] = '<img src="media/com_crowdfundingfinance/images/stripe/' . $cfFinanceParams->get('button', 'blue-on-dark') . '.png" width="190" height="33" />'; $stripeButton[] = '</a>'; $stripeButton[] = '</div>'; } else { $url = JRoute::_('index.php?option=com_crowdfundingfinance&task=payouts.deauthorize&payment_service=stripeconnect&pid=' . (int) $item->id . '&state=' . $state . '&' . JSession::getFormToken() . '=1'); $stripeButton[] = '<div class="mt-20">'; $stripeButton[] = '<p class="alert alert-info"><span class="fa fa-info-circle"></span> ' . JText::_('PLG_CROWDFUNDING_PAYOUTOPTIONS_STRIPE_CONNECTED') . '</p>'; $stripeButton[] = '<a href="' . $url . '" class="btn btn-danger" id="js-cff-btn-stripe-disconnect">'; $stripeButton[] = '<span class="fa fa-chain-broken"></span> ' . JText::_('PLG_CROWDFUNDING_PAYOUTOPTIONS_DISCONNECT_STRIPE'); $stripeButton[] = '</a>'; $stripeButton[] = '</div>'; } } // Load jQuery JHtml::_('jquery.framework'); JHtml::_('Prism.ui.pnotify'); JHtml::_('Prism.ui.joomlaHelper'); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('crowdfunding', 'payoutoptions')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); return $html; }
/** * @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"'; } }
/** * This method performs the transaction. * * @param string $context * @param Joomla\Registry\Registry $params * * @return null|array */ public function onPaymentNotify($context, &$params) { if (strcmp("com_crowdfunding.notify.banktransfer", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("raw", $docType) != 0) { return null; } $projectId = $this->app->input->getInt("pid"); $amount = $this->app->input->getFloat("amount"); // Prepare the array that will be returned by this method $result = array("project" => null, "reward" => null, "transaction" => null, "payment_session" => null, "redirect_url" => null, "message" => null); // Get project $project = new Crowdfunding\Project(JFactory::getDbo()); $project->load($projectId); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PROJECT_OBJECT"), $this->debugType, $project->getProperties()) : null; // Check for valid project if (!$project->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PROJECT"), $this->debugType, array("PROJECT OBJECT" => $project->getProperties(), "REQUEST METHOD" => $this->app->input->getMethod(), "_REQUEST" => $_REQUEST)); return null; } $currencyId = $params->get("project_currency"); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $currencyId, $params); // Prepare return URL $result["redirect_url"] = Joomla\String\String::trim($this->params->get('return_url')); if (!$result["redirect_url"]) { $filter = JFilterInput::getInstance(); $uri = JUri::getInstance(); $domain = $filter->clean($uri->toString(array("scheme", "host"))); $result["redirect_url"] = $domain . JRoute::_(CrowdfundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatslug(), "share"), false); } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RETURN_URL"), $this->debugType, $result["redirect_url"]) : null; // Payment Session $userId = JFactory::getUser()->get("id"); $aUserId = $this->app->getUserState("auser_id"); // Reset anonymous user hash ID, // because the payment session based in it will be removed when transaction completes. if (!empty($aUserId)) { $this->app->setUserState("auser_id", ""); } $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $project->getId(); $paymentSessionLocal = $this->app->getUserState($paymentSessionContext); $paymentSession = $this->getPaymentSession(array("session_id" => $paymentSessionLocal->session_id)); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYMENT_SESSION_OBJECT"), $this->debugType, $paymentSession->getProperties()) : null; // Validate payment session record. if (!$paymentSession->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PAYMENT_SESSION"), $this->debugType, $paymentSession->getProperties()); // Send response to the browser $response = array("success" => false, "title" => JText::_($this->textPrefix . "_FAIL"), "text" => JText::_($this->textPrefix . "_ERROR_INVALID_PROJECT")); return $response; } // Validate a reward and update the number of distributed ones. // If the user is anonymous, the system will store 0 for reward ID. // The anonymous users can't select rewards. $rewardId = $paymentSession->isAnonymous() ? 0 : (int) $paymentSession->getRewardId(); if (!empty($rewardId)) { $validData = array("reward_id" => $rewardId, "project_id" => $projectId, "txn_amount" => $amount); $reward = $this->updateReward($validData); // Validate the reward. if (!$reward) { $rewardId = 0; } } // Prepare transaction data $transactionId = new Prism\String(); $transactionId->generateRandomString(12, "BT"); $transactionId = Joomla\String\String::strtoupper($transactionId); $transactionData = array("txn_amount" => $amount, "txn_currency" => $currency->getCode(), "txn_status" => "pending", "txn_id" => $transactionId, "project_id" => $projectId, "reward_id" => $rewardId, "investor_id" => (int) $userId, "receiver_id" => (int) $project->getUserId(), "service_provider" => "Bank Transfer"); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_TRANSACTION_DATA"), $this->debugType, $transactionData) : null; // Auto complete transaction if ($this->params->get("auto_complete", 0)) { $transactionData["txn_status"] = "completed"; $project->addFunds($amount); $project->storeFunds(); } // Store transaction data $transaction = new Crowdfunding\Transaction(JFactory::getDbo()); $transaction->bind($transactionData); $transaction->store(); // Generate object of data, based on the transaction properties. $properties = $transaction->getProperties(); $result["transaction"] = Joomla\Utilities\ArrayHelper::toObject($properties); // Generate object of data, based on the project properties. $properties = $project->getProperties(); $result["project"] = Joomla\Utilities\ArrayHelper::toObject($properties); // Generate object of data, based on the reward properties. if (!empty($reward)) { $properties = $reward->getProperties(); $result["reward"] = Joomla\Utilities\ArrayHelper::toObject($properties); } // Generate data object, based on the payment session properties. $properties = $paymentSession->getProperties(); $result["payment_session"] = Joomla\Utilities\ArrayHelper::toObject($properties); // Set message to the user. $result["message"] = JText::sprintf($this->textPrefix . "_TRANSACTION_REGISTERED", $transaction->getTransactionId(), $transaction->getTransactionId()); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESULT_DATA"), $this->debugType, $result) : null; // Close payment session and remove payment session record. $txnStatus = isset($result["transaction"]->txn_status) ? $result["transaction"]->txn_status : null; $this->closePaymentSession($paymentSession, $txnStatus); return $result; }