public function display($tpl = null) { $this->app = JFactory::getApplication(); /** @var $this->app JApplicationSite */ $this->option = JFactory::getApplication()->input->get('option'); $this->state = $this->get('State'); $this->item = $this->get('Item'); // Get params $this->params = $this->state->get('params'); /** @var $this->params Joomla\Registry\Registry */ $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding'); if (!$this->item) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), 'notice'); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } $container = Prism\Container::getContainer(); $this->money = $this->getMoneyFormatter($container, $this->params); // Integrate with social profile. $this->displayCreator = $this->params->get('integration_display_creator', true); // Prepare integration. Load avatars and profiles. if ($this->displayCreator and (is_object($this->item) and $this->item->user_id > 0)) { $socialProfile = CrowdfundingHelper::prepareIntegration($this->params->get('integration_social_platform'), $this->item->user_id); $this->socialProfileLink = !$socialProfile ? null : $socialProfile->getLink(); } // Set a link to project page $uri = JUri::getInstance(); $host = $uri->toString(array('scheme', 'host')); $this->item->link = $host . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false); // Set a link to image $this->item->link_image = $host . '/' . $this->imageFolder . '/' . $this->item->image; $this->embedCode = $this->prepareEmbedCode($this->item, $host); $this->prepareDocument(); parent::display($tpl); }
public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get model state. $this->state = $this->get('State'); $this->item = $this->get("Item"); // Get params /** @var $params Joomla\Registry\Registry */ $params = $this->state->get("params"); $this->params = $params; $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding"); if (!$this->item) { $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT"), "notice"); $app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } // Get currency // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); // Integrate with social profile. $this->displayCreator = $this->params->get("integration_display_creator", true); // Prepare integration. Load avatars and profiles. if ($this->displayCreator and !empty($this->item->user_id)) { $socialProfilesBuilder = new Prism\Integration\Profile\Builder(array("social_platform" => $this->params->get("integration_social_platform"), "user_id" => $this->item->user_id)); $socialProfilesBuilder->build(); $socialProfile = $socialProfilesBuilder->getProfile(); $this->socialProfileLink = !$socialProfile ? null : $socialProfile->getLink(); } // Set a link to project page $uri = JUri::getInstance(); $host = $uri->toString(array("scheme", "host")); $this->item->link = $host . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false); // Set a link to image $this->item->link_image = $host . "/" . $this->imageFolder . "/" . $this->item->image; $layout = $this->getLayout(); switch ($layout) { case "email": if (!$this->params->get("security_display_friend_form", 0)) { $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_CANT_SEND_MAIL"), "notice"); $app->redirect(JRoute::_($this->item->link, false)); return; } $this->prepareEmailForm($this->item); break; default: // Embed HTML code $this->embedCode = $this->prepareEmbedCode($this->item, $host); break; } $this->prepareDocument(); parent::display($tpl); }
public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $this->option = JFactory::getApplication()->input->get('option'); $this->state = $this->get('State'); $this->item = $this->get('Item'); // Get params $this->params = $this->state->get('params'); /** @var $this->params Joomla\Registry\Registry */ $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding'); if (!$this->item) { $app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), 'notice'); $app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } // Get currency // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); // Integrate with social profile. $this->displayCreator = $this->params->get('integration_display_creator', true); // Prepare integration. Load avatars and profiles. if ($this->displayCreator and (is_object($this->item) and $this->item->user_id > 0)) { $socialProfilesBuilder = new Prism\Integration\Profile\Builder(array('social_platform' => $this->params->get('integration_social_platform'), 'user_id' => $this->item->user_id)); $socialProfilesBuilder->build(); $socialProfile = $socialProfilesBuilder->getProfile(); $this->socialProfileLink = !$socialProfile ? null : $socialProfile->getLink(); } // Set a link to project page $uri = JUri::getInstance(); $host = $uri->toString(array('scheme', 'host')); $this->item->link = $host . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false); // Set a link to image $this->item->link_image = $host . '/' . $this->imageFolder . '/' . $this->item->image; $layout = $this->getLayout(); if ($this->getLayout() === 'email') { if (!$this->params->get('security_display_friend_form', 0)) { $app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_CANT_SEND_MAIL'), 'notice'); $app->redirect(JRoute::_($this->item->link, false)); return; } $this->prepareEmailForm($this->item); } else { $this->embedCode = $this->prepareEmbedCode($this->item, $host); } $this->prepareDocument(); parent::display($tpl); }
public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $this->option = JFactory::getApplication()->input->get('option'); // Get user ID. $this->userId = JFactory::getUser()->get('id'); // Get reward ID. $rewardId = $app->input->getInt('id'); // Validate reward owner $validator = new Crowdfunding\Validator\Reward\Owner(JFactory::getDbo(), $rewardId, $this->userId); if (!$validator->isValid()) { $app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARD'), 'notice'); $app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute())); return; } $this->items = $this->get('Items'); $this->state = $this->get('State'); $this->pagination = $this->get('Pagination'); // Get params /** @var $params Joomla\Registry\Registry */ $params = $this->state->get('params'); $this->params = $params; // Prepare an URL where user will be redirected when change the state of a reward. $this->redirectUrl = 'index.php?option=com_crowdfunding&view=reward&id=' . $rewardId; // Prepare filters $this->listOrder = $this->escape($this->state->get('list.ordering')); $this->listDirn = $this->escape($this->state->get('list.direction')); $this->saveOrder = strcmp($this->listOrder, 'a.ordering') === 0; // Load reward data. $this->reward = new Crowdfunding\Reward(JFactory::getDbo()); $this->reward->load($rewardId); // Prepare reward delivery date. $dateValidator = new Prism\Validator\Date($this->reward->getDeliveryDate()); $this->deliveryDate = $dateValidator->isValid() ? JHtml::_('date', $this->reward->getDeliveryDate(), JText::_('DATE_FORMAT_LC3')) : '--'; // Get images folder. $this->imagesFolder = CrowdfundingHelper::getImagesFolderUri($this->userId); // Get social profile $socialPlatform = $this->params->get('integration_social_platform'); if (JString::strlen($socialPlatform) > 0) { $this->prepareSocialIntegration($socialPlatform); } $this->prepareDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->app = JFactory::getApplication(); /** @var $this->app JApplicationSite */ $this->option = JFactory::getApplication()->input->get('option'); $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->form = $this->get('Form'); // Get params $this->params = $this->state->get('params'); /** @var $this->params Joomla\Registry\Registry */ if (!$this->item) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), 'notice'); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } if (!$this->params->get('security_display_friend_form', 0)) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_CANT_SEND_MAIL'), 'notice'); $this->app->redirect(JRoute::_($this->item->link, false)); return; } $this->prepareDocument(); parent::display($tpl); }
/** * Disconnect user from payment gateway. * * @param string $context * @param Joomla\Registry\Registry $params * * @return null|array */ public function onPayoutsDeauthorize($context, $params) { if (strcmp('com_crowdfundingfinance.payouts.deauthorize.stripeconnect', $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; } // Prepare output data. $output = array('redirect_url' => '', 'message' => ''); $errorOutput = array('redirect_url' => JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()), 'message' => ''); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_GET_RESPONSE_AUTHORIZE'), $this->debugType, $_GET) : null; $userId = JFactory::getUser()->get('id'); if (!$userId) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_NOT_REGISTERED_USER'); return $errorOutput; } // Get token $state = $this->app->input->get('state'); if (!$state) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_AUTHORIZATION_DATA'); return $errorOutput; } // Get project ID and redirect URL from the session. $stateData = $this->app->getUserState($state); if (count($stateData) === 0 or (!$stateData['redirect_url'] or !$stateData['project_id'])) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_AUTHORIZATION_DATA'); return $errorOutput; } $cfFinanceParams = JComponentHelper::getParams('com_crowdfundingfinance'); $apiKeys = Crowdfundingfinance\Stripe\Helper::getKeys($cfFinanceParams); if (!$apiKeys['client_id'] or !$apiKeys['secret_key']) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_CONFIGURATION'); return $errorOutput; } $payout = new Crowdfundingfinance\Payout(JFactory::getDbo()); $payout->setSecretKey($this->app->get('secret')); $payout->load(array('project_id' => (int) $stateData['project_id'])); if (!$payout->getId()) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_PAYOUT'); return $errorOutput; } $alias = !$apiKeys['test'] ? 'production' : 'test'; $stripeData = $payout->getStripe(); if (!$stripeData->get('stripeconnect.' . $alias . '.account_id')) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_NOT_CONNECTED'); return $errorOutput; } Crowdfundingfinance\Stripe\Helper::deauthorize($apiKeys, $stripeData->get('stripeconnect.' . $alias . '.account_id')); $stripeData->set('stripeconnect.' . $alias . '.access_token', ''); $stripeData->set('stripeconnect.' . $alias . '.refresh_token', ''); $stripeData->set('stripeconnect.' . $alias . '.account_id', ''); $stripeData->set('stripeconnect.' . $alias . '.expires', 0); $payout->setStripe($stripeData); $payout->storeStripe(); // Get next URL. $output['redirect_url'] = base64_decode($stateData['redirect_url']); return $output; }
public function display($tpl = null) { // Get model state. $this->state = $this->get('State'); $this->item = $this->get("Item"); // Get params $this->params = $this->state->get("params"); if (!$this->item) { $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT"), "notice"); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } // Create an object that will contain the data during the payment process. $this->paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $this->item->id; $paymentSession = $this->app->getUserState($this->paymentSessionContext); // Create payment session object. if (!$paymentSession or !isset($paymentSession->step1)) { $paymentSession = new JData(); $paymentSession->step1 = false; } // Images $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding"); // Get currency $this->currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($this->currency); // Set a link that points to project page $filter = JFilterInput::getInstance(); $host = JUri::getInstance()->toString(array('scheme', 'host')); $host = $filter->clean($host); $this->item->link = $host . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false); // Set a link to image $this->item->link_image = $host . "/" . $this->imageFolder . "/" . $this->item->image; // Get wizard type $this->wizardType = $this->params->get("backing_wizard_type", "three_steps"); $this->fourSteps = strcmp("four_steps", $this->wizardType) != 0 ? false : true; // Import "crowdfundingpayment" plugins. JPluginHelper::importPlugin('crowdfundingpayment'); $this->layout = $this->getLayout(); switch ($this->layout) { case "step2": $this->prepareStep2(); break; case "payment": $this->preparePayment($paymentSession); break; case "share": $this->prepareShare($paymentSession); break; default: // Pledge and Rewards $this->prepareRewards($paymentSession); break; } // Get project type and check for enabled rewards. $this->rewardsEnabled = true; if (!empty($this->item->type_id)) { $type = new Crowdfunding\Type(JFactory::getDbo()); $type->load($this->item->type_id); if ($type->getId() and !$type->isRewardsEnabled()) { $this->rewardsEnabled = false; } } // Check days left. If there is no days, disable the button. $this->disabledButton = ""; if (!$this->item->days_left) { $this->disabledButton = 'disabled="disabled"'; } $this->paymentSession = $paymentSession; // Prepare the data of the layout $this->layoutData = new JData(array("layout" => $this->layout, "item" => $this->item, "paymentSession" => $paymentSession)); $this->prepareDebugMode($paymentSession); $this->prepareDocument(); parent::display($tpl); }
public function process() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Check for request forgeries. $requestMethod = $app->input->getMethod(); if (strcmp("POST", $requestMethod) == 0) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); } else { JSession::checkToken("get") or jexit(JText::_('JINVALID_TOKEN')); } // Get params $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Get the data from the form $itemId = $this->input->getInt('id', 0); $rewardId = $this->input->getInt('rid', 0); // Get amount $amount = CrowdfundingHelper::parseAmount($this->input->getString("amount")); // Get user ID $user = JFactory::getUser(); $userId = (int) $user->get("id"); // Anonymous user ID $aUserId = ""; $model = $this->getModel(); /** @var $model CrowdfundingModelBacking */ // Get the item $item = $model->getItem($itemId); $returnUrl = CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug); // Authorise the user if (!$user->authorise("crowdfunding.donate", "com_crowdfunding")) { $this->setRedirect(JRoute::_($returnUrl, false), JText::_('COM_CROWDFUNDING_ERROR_NO_PERMISSIONS'), "notice"); return; } // Check for valid project if (empty($item->id)) { $this->setRedirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()), JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), "notice"); return; } // Check for maintenance (debug) state. if ($params->get("debug_payment_disabled", 0)) { $msg = Joomla\String\String::trim($params->get("debug_disabled_functionality_msg")); if (!$msg) { $msg = JText::_("COM_CROWDFUNDING_DEBUG_MODE_DEFAULT_MSG"); } $this->setRedirect(JRoute::_($returnUrl, false), $msg, "notice"); return; } // Check for agreed conditions from the user. if ($params->get("backing_terms", 0)) { $terms = $this->input->get("terms", 0, "int"); if (!$terms) { $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_TERMS_NOT_ACCEPTED"), "notice"); return; } } // Check for valid amount. if (!$amount) { $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice"); return; } // Store payment process data // Get the payment process object and // store the selected data from the user. $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $item->id; $paymentSessionLocal = $app->getUserState($paymentSessionContext); $paymentSessionLocal->step1 = true; $paymentSessionLocal->amount = $amount; $paymentSessionLocal->rewardId = $rewardId; $app->setUserState($paymentSessionContext, $paymentSessionLocal); // Generate hash user ID used for anonymous payment. if (!$userId) { $aUserId = $app->getUserState("auser_id"); if (!$aUserId) { // Generate a hash ID for anonymous user. $anonymousUserId = new Prism\String(); $anonymousUserId->generateRandomString(32); $aUserId = (string) $anonymousUserId; $app->setUserState("auser_id", $aUserId); } } $date = new JDate(); // Create an intention record. $intentionId = 0; if (!empty($userId)) { $intentionKeys = array("user_id" => $userId, "project_id" => $item->id); $intention = new Crowdfunding\Intention(JFactory::getDbo()); $intention->load($intentionKeys); $intentionData = array("user_id" => $userId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql()); $intention->bind($intentionData); $intention->store(); $intentionId = $intention->getId(); } // Create a payment session. $paymentSessionDatabase = new Crowdfunding\Payment\Session(JFactory::getDbo()); $paymentSessionData = array("user_id" => $userId, "auser_id" => $aUserId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql(), "session_id" => $paymentSessionLocal->session_id, "intention_id" => $intentionId); $paymentSessionDatabase->bind($paymentSessionData); $paymentSessionDatabase->store(); // Redirect to next page $link = CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug, "payment"); $this->setRedirect(JRoute::_($link, false)); }
/** * Task used for processing events. * * @throws Exception */ public function process() { // Get the task. $task = JString::strtolower($this->input->getCmd('task')); if (!$task) { throw new Exception(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_INVALID_TASK')); } // Check for request forgeries. if (in_array($task, $this->tokenTasks, true)) { if (strcmp('POST', $this->app->input->getMethod()) !== 0) { JSession::checkToken('GET') or jexit(JText::_('JINVALID_TOKEN')); } else { JSession::checkToken('POST') or jexit(JText::_('JINVALID_TOKEN')); } } // Get component parameters $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ // Check for disabled payment functionality if ($params->get('debug_payment_disabled', 0)) { throw new Exception(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE')); } // Get payment gateway name. $paymentService = $this->input->getCmd('payment_service'); if (!$paymentService) { throw new UnexpectedValueException(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_INVALID_PAYMENT_GATEWAY')); } $output = array(); // Trigger the event try { $context = 'com_crowdfundingfinance.payouts.' . $task . '.' . JString::strtolower($paymentService); // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfunding'); // Trigger the event. $results = $dispatcher->trigger('onPayouts' . JString::ucwords($task), array($context, &$params)); // Get the result, that comes from the plugin. if (is_array($results) and count($results) > 0) { foreach ($results as $result) { if ($result !== null and is_array($result)) { $output = $result; break; } } } } catch (UnexpectedValueException $e) { $this->setMessage($e->getMessage(), 'notice'); $this->setRedirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } catch (Exception $e) { // Store log data in the database JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM')); } $redirectUrl = Joomla\Utilities\ArrayHelper::getValue($output, 'redirect_url'); $message = Joomla\Utilities\ArrayHelper::getValue($output, 'message'); if (!$redirectUrl) { throw new UnexpectedValueException(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_INVALID_REDIRECT_URL')); } if (!$message) { $this->setRedirect($redirectUrl); } else { $this->setRedirect($redirectUrl, $message, 'notice'); } }
/** * Check if item exists. * * @return bool */ protected function isValid() { if (!$this->item->id or $this->item->user_id != $this->userId) { $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_SOMETHING_WRONG"), "notice"); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute())); return false; } return true; }
/** * Invoke the plugin method onPaymentsCompleteCheckout. * * @throws UnexpectedValueException * @throws Exception */ public function completeCheckout() { // Get component parameters $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Check for disabled payment functionality if ($params->get("debug_payment_disabled", 0)) { throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE")); } $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $output = array(); // Get payment gateway name. $paymentService = $this->input->get("payment_service"); if (!$paymentService) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PAYMENT_GATEWAY")); } // Set the name of the payment service to session. $this->paymentProcess->paymentService = $paymentService; // Trigger the event try { $context = 'com_crowdfunding.payments.completeCheckout.' . Joomla\String\String::strtolower($paymentService); // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onContentPreparePayment event. $results = $dispatcher->trigger("onPaymentsCompleteCheckout", array($context, &$params)); // Get the result, that comes from the plugin. if (!empty($results)) { foreach ($results as $result) { if (!is_null($result) and is_array($result)) { $output =& $result; break; } } } } catch (UnexpectedValueException $e) { $this->setMessage($e->getMessage(), "notice"); $this->setRedirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } catch (Exception $e) { // Store log data in the database $this->log->add(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM"), "CONTROLLER_PAYMENTS_CHECKOUT_ERROR", $e->getMessage()); throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); } $redirectUrl = Joomla\Utilities\ArrayHelper::getValue($output, "redirect_url"); $message = Joomla\Utilities\ArrayHelper::getValue($output, "message"); if (!$redirectUrl) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REDIRECT_URL")); } // Store the payment process data into the session. $app->setUserState($this->paymentProcessContext, $this->paymentProcess); if (!$message) { $this->setRedirect($redirectUrl); } else { $this->setRedirect($redirectUrl, $message, "notice"); } }
protected function prepareExtras() { $model = JModelLegacy::getInstance('Extras', 'CrowdfundingModel', $config = array('ignore_request' => false)); /** @var $model CrowdfundingModelExtras */ // Get state /** @var $state Joomla\Registry\Registry */ $this->state = $model->getState(); // Get item $itemId = $this->state->get('extras.id'); $this->item = $model->getItem($itemId, $this->userId); // Check if the item exists. if (!CrowdfundingHelper::isAuthorized($this->userId, $this->item, 'extras')) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_SOMETHING_WRONG'), 'notice'); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute())); return; } $this->pathwayName = JText::_('COM_CROWDFUNDING_STEP_EXTRAS'); // Events JPluginHelper::importPlugin('crowdfunding'); $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onExtrasDisplay', array('com_crowdfunding.project.extras', &$this->item, &$this->params)); $this->item->event = new stdClass(); $this->item->event->onExtrasDisplay = trim(implode("\n", $results)); }
/** * Process action triggering an event that comes from remote server. * * Actions: * * authorize - Authorize or obtain access token from payment gateways. * * doCheckout - Authorize or obtain access token from payment gateways. * * @throws Exception */ public function process() { // Get the task. $task = strtolower($this->input->getCmd('task')); if (!$task) { throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TASK')); } // Check for request forgeries. if (in_array($task, $this->tokenTasks, true)) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); } // Get component parameters $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ // Check for disabled payment functionality if ($params->get('debug_payment_disabled', 0)) { throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE')); } // Get payment gateway name. $paymentService = $this->input->getCmd('payment_service'); if (!$paymentService and !$this->paymentSessionLocal->paymentService) { throw new UnexpectedValueException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PAYMENT_GATEWAY')); } // Set the name of the payment service to session. if ($paymentService !== null and $paymentService !== '') { $this->paymentSessionLocal->paymentService = $paymentService; // Store the payment process data in the session. $this->app->setUserState($this->paymentSessionContext, $this->paymentSessionLocal); } $paymentResult = null; $redirectUrl = null; $message = null; $triggerEvents = false; $model = $this->getModel(); // Trigger the event try { // Prepare project object. $item = $model->prepareItem($this->projectId, $params, $this->paymentSessionLocal); $context = 'com_crowdfunding.payments.' . $task . '.' . strtolower($this->paymentSessionLocal->paymentService); // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger the event. $results = $dispatcher->trigger('onPayments' . ucwords($task), array($context, &$item, &$params)); // Get the result, that comes from the plugin. if (is_array($results) and count($results) > 0) { foreach ($results as $result) { if ($result !== null and is_object($result)) { $paymentResult = $result; $redirectUrl = isset($result->redirectUrl) ? $result->redirectUrl : null; $message = isset($result->message) ? $result->message : null; $triggerEvents = isset($result->triggerEvents) ? (bool) $result->triggerEvents : false; break; } } } if ($triggerEvents) { // Trigger the event onAfterPaymentNotify $dispatcher->trigger('onAfterPaymentNotify', array($context, &$paymentResult, &$params)); // Trigger the event onAfterPayment $dispatcher->trigger('onAfterPayment', array($context, &$paymentResult, &$params)); } } catch (UnexpectedValueException $e) { $this->setMessage($e->getMessage(), 'notice'); $this->setRedirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } catch (Exception $e) { $this->log->add(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'), 'ERROR_CONTROLLER_PAYMENTS_PROCESS', $e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } if (!$redirectUrl) { throw new UnexpectedValueException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REDIRECT_URL')); } if (!$message) { $this->setRedirect($redirectUrl); } else { $this->setRedirect($redirectUrl, $message, 'warning'); } }
public function display($tpl = null) { $this->app = JFactory::getApplication(); $this->option = $this->app->input->get('option'); $this->state = $this->get('State'); $this->item = $this->get('Item'); // Get params $this->params = $this->state->get('params'); if (!$this->item) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), 'notice'); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } // Create an object that will contain the data during the payment process. $this->paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $this->item->id; $paymentSession = $this->app->getUserState($this->paymentSessionContext); // Create payment session object. if (!$paymentSession or !isset($paymentSession->step1)) { $paymentSession = $this->createPaymentSession(); } // Images $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding'); // Get currency $this->currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($this->currency); // Set a link that points to project page $filter = JFilterInput::getInstance(); $host = JUri::getInstance()->toString(array('scheme', 'host')); $host = $filter->clean($host); $this->item->link = $host . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false); // Set a link to image $this->item->link_image = $host . '/' . $this->imageFolder . '/' . $this->item->image; // Get wizard type $this->wizardType = $this->params->get('backing_wizard_type', 'three_steps'); $this->fourSteps = strcmp('four_steps', $this->wizardType) === 0; // Import 'crowdfundingpayment' plugins. JPluginHelper::importPlugin('crowdfundingpayment'); $this->layout = $this->getLayout(); switch ($this->layout) { case 'step2': // Step 2 on wizard in four steps. $this->prepareStep2(); break; case 'payment': // Step 2 $paymentSession = $this->preparePayment($paymentSession); break; case 'share': // Step 3 $paymentSession = $this->prepareShare($paymentSession); break; default: // Step 1 ( Rewards ) $paymentSession = $this->prepareRewards($paymentSession); break; } // Get project type and check for enabled rewards. $this->rewardsEnabled = CrowdfundingHelper::isRewardsEnabled($this->item->id); // Check days left. If there is no days, disable the button. $this->disabledButton = ''; if (!$this->item->days_left) { $this->disabledButton = 'disabled="disabled"'; } // Prepare the data of the layout $this->layoutData = new JData(array('layout' => $this->layout, 'item' => $this->item, 'paymentSession' => $paymentSession, 'rewards_enabled' => $this->rewardsEnabled)); $this->prepareDebugMode($paymentSession); $this->prepareDocument(); $this->paymentSession = $paymentSession; // Store the new values of the payment process to the user session. $this->app->setUserState($this->paymentSessionContext, $paymentSession); parent::display($tpl); }