Example #1
0
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Get user ID.
     $this->userId = JFactory::getUser()->get("id");
     // Get reward ID.
     $rewardId = $app->input->getInt("id");
     // Validate reward owner
     jimport("crowdfunding.validator.reward.owner");
     $validator = new CrowdFundingValidatorRewardOwner(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 ? false : true;
     // Load reward data.
     jimport("crowdfunding.reward");
     $this->reward = new CrowdFundingReward(JFactory::getDbo());
     $this->reward->load($rewardId);
     // Prepare reward delivery date.
     $dateValidator = new ITPrismValidatorDate($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 (!empty($socialPlatform)) {
         $this->prepareSocialIntegration($socialPlatform);
     }
     $this->prepareDocument();
     $this->version = new CrowdFundingVersion();
     parent::display($tpl);
 }
Example #2
0
 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 = $this->input->get("amount", 0, "float");
     // 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 = JString::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 = CrowdFundingConstants::PAYMENT_SESSION_CONTEXT . $item->id;
     $paymentSession = $app->getUserState($paymentSessionContext);
     $paymentSession->step1 = true;
     $paymentSession->amount = $amount;
     $paymentSession->rewardId = $rewardId;
     $app->setUserState($paymentSessionContext, $paymentSession);
     // Create an intention.
     // Generate hash user ID used for anonymous payment.
     if (!$userId) {
         $aUserId = $app->getUserState("auser_id");
         if (!$aUserId) {
             // Generate a hash ID for anonymous user.
             jimport("itprism.string");
             $anonymousUserId = new ITPrismString();
             $anonymousUserId->generateRandomString(32);
             $aUserId = (string) $anonymousUserId;
             $app->setUserState("auser_id", $aUserId);
         }
         $intentionKeys = array("auser_id" => $aUserId, "project_id" => $item->id);
     } else {
         $intentionKeys = array("user_id" => $userId, "project_id" => $item->id);
     }
     jimport("crowdfunding.intention");
     $intention = new CrowdFundingIntention(JFactory::getDbo());
     $intention->load($intentionKeys);
     $date = new JDate();
     $custom = array("user_id" => $userId, "auser_id" => $aUserId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql(), "session_id" => $paymentSession->session_id);
     $intention->bind($custom);
     $intention->store();
     // Redirect to next page
     $link = CrowdFundingHelperRoute::getBackingRoute($item->slug, $item->catslug, "payment");
     $this->setRedirect(JRoute::_($link, false));
 }
Example #3
0
 public function display($tpl = null)
 {
     // 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;
     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 = CrowdFundingConstants::PAYMENT_SESSION_CONTEXT . $this->item->id;
     $paymentSession = $this->app->getUserState($this->paymentSessionContext);
     // Create payment session object.
     if (!$paymentSession) {
         $paymentSession = new JData();
         $paymentSession->step1 = false;
     }
     // Images
     $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding");
     // Get currency
     jimport("crowdfunding.currency");
     $currencyId = $this->params->get("project_currency");
     $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params);
     // 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 params
     $params = JComponentHelper::getParams("com_crowdfunding");
     // Get wizard type
     $this->wizardType = $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)) {
         jimport("crowdfunding.type");
         $type = new CrowdFundingType(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();
     $this->version = new CrowdFundingVersion();
     parent::display($tpl);
 }
Example #4
0
 public function docheckout()
 {
     // 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"));
     }
     $output = array();
     // Get the name of the payment service.
     $paymentService = $this->paymentProcess->paymentService;
     // Trigger the event
     try {
         // Create project object.
         $item = $this->prepareItem($this->projectId, $params);
         $context = 'com_crowdfunding.payments.docheckout.' . JString::strtolower($paymentService);
         // Import CrowdFunding Payment Plugins
         $dispatcher = JEventDispatcher::getInstance();
         JPluginHelper::importPlugin('crowdfundingpayment');
         // Trigger onContentPreparePayment event.
         $results = $dispatcher->trigger("onPaymentsDoCheckout", array($context, &$item, &$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_DOCHECKOUT_ERROR", $e->getMessage());
         throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM"));
     }
     $redirectUrl = JArrayHelper::getValue($output, "redirect_url");
     if (!$redirectUrl) {
         throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REDIRECT_URL"));
     }
     $this->setRedirect($redirectUrl);
 }
Example #5
0
 protected function prepareManager()
 {
     $model = JModelLegacy::getInstance("Manager", "CrowdFundingModel", $config = array('ignore_request' => false));
     /** @var $model CrowdFundingModelManager */
     // Get state
     /** @var  $state Joomla\Registry\Registry */
     $this->state = $model->getState();
     // Get params
     /** @var  $params Joomla\Registry\Registry */
     $params = $this->state->get("params");
     $this->params = $params;
     $this->imageWidth = $this->params->get("image_width", 200);
     $this->imageHeight = $this->params->get("image_height", 200);
     $this->titleLength = $this->params->get("discover_title_length", 0);
     $this->descriptionLength = $this->params->get("discover_description_length", 0);
     // Get the folder with images
     $this->imageFolder = $params->get("images_directory", "images/crowdfunding");
     // Filter the URL.
     $uri = JUri::getInstance();
     $filter = JFilterInput::getInstance();
     $this->returnUrl = $filter->clean($uri->toString());
     // Get item
     $itemId = $this->state->get('manager.id');
     // Create a currency object.
     jimport("crowdfunding.currency");
     $currencyId = $this->params->get("project_currency");
     $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params);
     $this->item = $model->getItem($itemId, $this->userId);
     if (empty($this->item->id)) {
         $app = JFactory::getApplication();
         /** $app JApplicationSite */
         $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_SOMETHING_WRONG"), "notice");
         $app->redirect(JRoute::_(CrowdFundingHelperRoute::getDiscoverRoute()));
         return;
     }
     jimport("crowdfunding.statistics.project");
     $statistics = new CrowdFundingStatisticsProject(JFactory::getDbo(), $this->item->id);
     $this->statistics = array("updates" => $statistics->getUpdatesNumber(), "comments" => $statistics->getCommentsNumber(), "funders" => $statistics->getTransactionsNumber());
     // Get rewards
     jimport("crowdfunding.rewards");
     $this->rewards = new CrowdFundingRewards(JFactory::getDbo());
     $this->rewards->load($this->item->id);
     $this->pathwayName = JText::_("COM_CROWDFUNDING_STEP_MANAGER");
 }