public function display($tpl = null) { $this->option = JFactory::getApplication()->input->get('option'); $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->params = $this->state->get('params'); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->state->params->get('project_currency')); // Create object 'Amount'. $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); // Get projects IDs $projectsIds = array(); foreach ($this->items as $item) { $projectsIds[] = $item->id; } // Get number of rewards. $projects = new Crowdfunding\Projects(JFactory::getDbo()); $this->rewards = $projects->getRewardsNumber($projectsIds); // Prepare sorting data $this->prepareSorting(); if ($this->getLayout() !== 'modal') { // Prepare actions $this->addToolbar(); $this->addSidebar(); } $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { // Initialise variables $this->state = $this->get("State"); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); // Get params $this->params = $this->state->get("params"); /** @var $this->params Joomla\Registry\Registry */ $this->numberInRow = $this->params->get("items_row", 3); $this->items = CrowdfundingHelper::prepareItems($this->items, $this->numberInRow); // Get the folder with images $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding"); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); $this->displayCreator = $this->params->get("integration_display_creator", true); // Prepare social integration. if (!empty($this->displayCreator)) { $socialProfilesBuilder = new Prism\Integration\Profiles\Builder(array("social_platform" => $this->params->get("integration_social_platform"), "users_ids" => CrowdfundingHelper::fetchUserIds($this->items))); $socialProfilesBuilder->build(); $this->socialProfiles = $socialProfilesBuilder->getProfiles(); } $this->layoutData = array("items" => $this->items, "params" => $this->params, "amount" => $this->amount, "socialProfiles" => $this->socialProfiles, "imageFolder" => $this->imageFolder, "titleLength" => $this->params->get("discover_title_length", 0), "descriptionLength" => $this->params->get("discover_description_length", 0), "span" => !empty($this->numberInRow) ? round(12 / $this->numberInRow) : 4); $this->prepareDocument(); parent::display($tpl); }
public function display($tpl = null) { $userId = JFactory::getUser()->get("id"); if (!$userId) { $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_NOT_LOG_IN"), "notice"); $this->app->redirect(JRoute::_("index.php?option=com_users&view=login", false)); return; } // Initialise variables $this->items = $this->get('Items'); $this->state = $this->get('State'); $this->params = $this->state->get('params'); if (!empty($this->items)) { // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); } // 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; $this->prepareDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->version = new CrowdfundingFinance\Version(); // Load ITPrism library version if (!class_exists("Prism\\Version")) { $this->itprismVersion = JText::_("COM_CROWDFUNDINGFINANCE_PRISM_LIBRARY_DOWNLOAD"); } else { $itprismVersion = new Prism\Version(); $this->itprismVersion = $itprismVersion->getShortVersion(); } /** @var $cfParams Joomla\Registry\Registry */ $cfParams = JComponentHelper::getParams("com_crowdfunding"); $this->cfParams = $cfParams; // Get latest transactions. $this->latest = new Crowdfunding\Statistics\Transactions\Latest(JFactory::getDbo()); $this->latest->load(5); $basic = new Crowdfunding\Statistics\Basic(JFactory::getDbo()); $this->totalProjects = $basic->getTotalProjects(); $this->totalTransactions = $basic->getTotalTransactions(); $this->totalAmount = $basic->getTotalAmount(); // Get currency. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->cfParams->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->cfParams); $this->amount->setCurrency($currency); // Add submenu CrowdfundingFinanceHelper::addSubmenu($this->getName()); $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
/** * @param int $projectId * @param Joomla\Registry\Registry $params * @param object $paymentSession * * @return stdClass * @throws UnexpectedValueException */ public function prepareItem($projectId, $params, $paymentSession) { $project = new Crowdfunding\Project(JFactory::getDbo()); $project->load($projectId); if (!$project->getId()) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT")); } if ($project->isCompleted()) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_COMPLETED_PROJECT")); } // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Create amount object. $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); $item = new stdClass(); $item->id = $project->getId(); $item->title = $project->getTitle(); $item->slug = $project->getSlug(); $item->catslug = $project->getCatSlug(); $item->rewardId = $paymentSession->rewardId; $item->starting_date = $project->getFundingStart(); $item->ending_date = $project->getFundingEnd(); $item->amount = $paymentSession->amount; $item->currencyCode = $currency->getCode(); $item->amountFormated = $amount->setValue($item->amount)->format(); $item->amountCurrency = $amount->setValue($item->amount)->formatCurrency(); return $item; }
public function display($tpl = null) { $this->app = JFactory::getApplication(); $this->option = $this->app->input->get('option'); $userId = JFactory::getUser()->get('id'); if (!$userId) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), 'notice'); $this->app->redirect(JRoute::_('index.php?option=com_users&view=login', false)); return; } $this->items = $this->get('Items'); $this->state = $this->get('State'); $this->pagination = $this->get('Pagination'); $this->params = $this->state->get('params'); /** @var $params Joomla\Registry\Registry */ if (is_array($this->items) and count($this->items) > 0) { $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); } // 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; $this->userId = JFactory::getUser()->get('id'); $this->redirectUrl = CrowdfundingHelperRoute::getTransactionsRoute(); $this->prepareDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->option = JFactory::getApplication()->input->get('option'); $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); // Get parameters of com_crowdfunding. /** @var $cParams Joomla\Registry\Registry */ $cParams = JComponentHelper::getParams('com_crowdfunding'); $this->cfParams = $cParams; $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->cfParams->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->cfParams); $this->amount->setCurrency($currency); // Get rewards number $projectsIds = array(); foreach ($this->items as $item) { $projectsIds[] = $item->id; } $projects = new Crowdfunding\Projects(JFactory::getDbo()); $this->transactions = $projects->getTransactionsNumber($projectsIds); // Prepare sorting data $this->prepareSorting(); // Prepare actions $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->params = $this->state->get("params"); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->state->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); // Get rewards number $usersIds = array(); foreach ($this->items as $item) { $usersIds[] = $item->id; } // Get number of rewards. $statistics = new Crowdfunding\Statistics\Users(JFactory::getDbo(), $usersIds); $this->projects = $statistics->getProjectsNumber(); $this->amounts = $statistics->getAmounts(); // Add submenu CrowdfundingHelper::addSubmenu($this->getName()); // Prepare sorting data $this->prepareSorting(); // Prepare actions $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->option = JFactory::getApplication()->input->getCmd('option'); $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); // Get params $this->params = $this->state->get('params'); /** @var $this->params Joomla\Registry\Registry */ $this->numberInRow = (int) $this->params->get('featured_items_row', 3); $this->items = CrowdfundingHelper::prepareItems($this->items, $this->numberInRow); // Get the folder with images $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding'); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); $this->displayCreator = (bool) $this->params->get('integration_display_creator', true); // Prepare integration. Load avatars and profiles. if ($this->displayCreator) { $socialProfilesBuilder = new Prism\Integration\Profiles\Builder(array('social_platform' => $this->params->get('integration_social_platform'), 'users_ids' => CrowdfundingHelper::fetchUserIds($this->items))); $socialProfilesBuilder->build(); $this->socialProfiles = $socialProfilesBuilder->getProfiles(); } $this->layoutData = array('items' => $this->items, 'params' => $this->params, 'amount' => $this->amount, 'socialProfiles' => $this->socialProfiles, 'imageFolder' => $this->imageFolder, 'titleLength' => $this->params->get('discover_title_length', 0), 'descriptionLength' => $this->params->get('discover_description_length', 0), 'span' => $this->numberInRow > 0 ? round(12 / $this->numberInRow) : 4); $this->prepareDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->option = JFactory::getApplication()->input->getCmd('option'); $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->params = $this->state->get('params'); $this->numberInRow = (int) $this->params->get('items_row', 3); $this->prepareItems($this->items); // Get the folder with images $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding'); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); $this->displayCreator = (bool) $this->params->get('display_creator', true); // Prepare social integration. if ($this->displayCreator !== false) { $usersIds = CrowdfundingHelper::fetchIds($this->items, 'user_id'); $this->socialProfiles = CrowdfundingHelper::prepareIntegrations($this->params->get('integration_social_platform'), $usersIds); } $this->layoutData = array('items' => $this->items, 'params' => $this->params, 'amount' => $this->amount, 'socialProfiles' => $this->socialProfiles, 'imageFolder' => $this->imageFolder, 'titleLength' => $this->params->get('discover_title_length', 0), 'descriptionLength' => $this->params->get('discover_description_length', 0), 'span' => $this->numberInRow > 0 ? round(12 / $this->numberInRow) : 4); $this->prepareDocument(); parent::display($tpl); }
/** * Display the view */ public function display($tpl = null) { $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->form = $this->get('Form'); $this->layout = $this->getLayout(); if (strcmp($this->layout, "edit") != 0) { $currency = new Crowdfunding\Currency(JFactory::getDbo()); $currency->loadByCode($this->item->txn_currency); $crowdfundingParams = JComponentHelper::getParams("com_crowdfunding"); $this->amount = new Crowdfunding\Amount($crowdfundingParams); $this->amount->setCurrency($currency); } // Prepare actions, behaviors, scripts and document $this->addToolbar(); $this->setDocument(); parent::display($tpl); }
protected function preparePayment(&$paymentSession) { // If missing the flag "step1", redirect to first step. if (!$paymentSession->step1) { $this->returnToStep1($paymentSession, JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT")); } // Check for both user states. The user must have only one state - registered user or anonymous user. $userId = JFactory::getUser()->get("id"); $aUserId = $this->app->getUserState("auser_id"); if (!empty($userId) and !empty($aUserId) or empty($userId) and empty($aUserId)) { // Reset anonymous hash user ID and redirect to first step. $this->app->setUserState("auser_id", ""); $this->returnToStep1($paymentSession); } if (!$this->item->days_left) { $this->returnToStep1($paymentSession, JText::_("COM_CROWDFUNDING_ERROR_PROJECT_COMPLETED")); } // Validate reward $this->reward = null; $keys = array("id" => $paymentSession->rewardId, "project_id" => $this->item->id); $this->reward = new Crowdfunding\Reward(JFactory::getDbo()); $this->reward->load($keys); if ($this->reward->getId()) { if ($this->reward->isLimited() and !$this->reward->getAvailable()) { $this->returnToStep1($paymentSession, JText::_("COM_CROWDFUNDING_ERROR_REWARD_NOT_AVAILABLE")); } } // Set the amount that will be displayed in the view. $this->paymentAmount = $paymentSession->amount; // Validate the amount. if (!$this->paymentAmount) { $this->returnToStep1($paymentSession, JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT")); } // Events $item = new stdClass(); $item->id = $this->item->id; $item->title = $this->item->title; $item->slug = $this->item->slug; $item->catslug = $this->item->catslug; $item->rewardId = $paymentSession->rewardId; $item->amount = $paymentSession->amount; $item->currencyCode = $this->currency->getCode(); $item->amountFormated = $this->amount->setValue($item->amount)->format(); $item->amountCurrency = $this->amount->setValue($item->amount)->formatCurrency(); $this->item->event = new stdClass(); // onBeforePaymentAuthorize JPluginHelper::importPlugin('crowdfundingpayment'); $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onBeforePaymentAuthorize', array('com_crowdfunding.before.payment.authorize', &$item, &$this->amount, &$this->params)); if (!empty($results)) { $this->item->event->onBeforePaymentAuthorize = trim(implode("\n", $results)); } else { // onProjectPayment $results = $dispatcher->trigger('onProjectPayment', array('com_crowdfunding.payment', &$item, &$this->params)); $this->item->event->onProjectPayment = trim(implode("\n", $results)); } }
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); }
/** * Method to get the field input markup. * * @return string The field input markup. * * @since 11.1 */ protected function getInput() { // Initialize some field attributes. $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : ''; $readonly = (string) $this->element['readonly'] == 'true' ? ' readonly="readonly"' : ''; $disabled = (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : ''; $class = !empty($this->element['class']) ? ' class="' . (string) $this->element['class'] . '"' : ""; $required = $this->required ? ' required aria-required="true"' : ''; $cssLayout = $this->element['css_layout'] ? $this->element['css_layout'] : "Bootstrap 2"; // Initialize JavaScript field attributes. $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Prepare amount object. $amount = new Crowdfunding\Amount($params, $this->value); $amount->setCurrency($currency); switch ($cssLayout) { case "Bootstrap 3": $html = array(); $html[] = '<div class="input-group">'; if ($currency->getSymbol()) { // Prepended $html[] = '<div class="input-group-addon">' . $currency->getSymbol() . '</div>'; } $html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . $amount->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>'; // Prepend $html[] = '<div class="input-group-addon">' . $currency->getCode() . '</div>'; $html[] = '</div>'; break; default: // Bootstrap 2 $html = array(); if ($currency->getSymbol()) { // Prepended $html[] = '<div class="input-prepend input-append"><span class="add-on">' . $currency->getSymbol() . '</span>'; } else { // Append $html[] = '<div class="input-append">'; } $html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . $amount->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>'; // Appended $html[] = '<span class="add-on">' . $currency->getCode() . '</span></div>'; break; } return implode("\n", $html); }
public function validate($data) { if (empty($data) or !is_array($data)) { throw new InvalidArgumentException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REWARDS")); } $filter = JFilterInput::getInstance(); $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Create a currency object. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Create the object "amount". $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); foreach ($data as $key => $item) { $item["amount"] = $amount->setValue($item["amount"])->parse(); // Filter data if (!is_numeric($item["amount"])) { $item["amount"] = 0; } $item["title"] = $filter->clean($item["title"], "string"); $item["title"] = Joomla\String\String::trim($item["title"]); $item["title"] = Joomla\String\String::substr($item["title"], 0, 128); $item["description"] = $filter->clean($item["description"], "string"); $item["description"] = Joomla\String\String::trim($item["description"]); $item["description"] = Joomla\String\String::substr($item["description"], 0, 500); $item["number"] = (int) $item["number"]; $item["delivery"] = Joomla\String\String::trim($item["delivery"]); $item["delivery"] = $filter->clean($item["delivery"], "string"); if (!empty($item["delivery"])) { $date = new JDate($item["delivery"]); $unixTime = $date->toUnix(); if ($unixTime < 0) { $item["delivery"] = ""; } } if (!$item["title"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_TITLE")); } if (!$item["description"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION")); } if (!$item["amount"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT")); } $data[$key] = $item; } return $data; }
public function validate($data) { if (!is_array($data) or count($data) === 0) { throw new InvalidArgumentException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARDS')); } $filter = JFilterInput::getInstance(); $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ // Create a currency object. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get('project_currency')); // Create the object 'amount'. $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); foreach ($data as $key => &$item) { $item['amount'] = $amount->setValue($item['amount'])->parse(); // Filter data if (!is_numeric($item['amount'])) { $item['amount'] = 0; } $item['title'] = $filter->clean($item['title'], 'string'); $item['title'] = JString::trim($item['title']); $item['title'] = JString::substr($item['title'], 0, 128); $item['description'] = $filter->clean($item['description'], 'string'); $item['description'] = JString::trim($item['description']); $item['description'] = JString::substr($item['description'], 0, 500); $item['number'] = (int) $item['number']; $item['delivery'] = JString::trim($item['delivery']); $item['delivery'] = $filter->clean($item['delivery'], 'string'); if (!empty($item['delivery'])) { $date = new JDate($item['delivery']); $unixTime = $date->toUnix(); if ($unixTime < 0) { $item['delivery'] = ''; } } if (!$item['title']) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TITLE')); } if (!$item['description']) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION')); } if (!$item['amount']) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_AMOUNT')); } } unset($item); return $data; }
/** * Display the view */ public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ // Get user ID $userId = $app->input->getInt("id"); $model = $this->getModel(); $this->state = $model->getState(); $this->item = $model->getItem($userId); $this->params = JComponentHelper::getParams($this->option); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); // Get number of rewards. $statistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $this->item->id); $this->projects = $statistics->getProjectsNumber(); $amounts = $statistics->getAmounts(); if (!empty($amounts["invested"])) { $this->investedAmount = (double) $amounts["invested"]['amount']; $this->investedTransactions = (int) $amounts["invested"]['number']; } if (!empty($amounts["received"])) { $this->receivedAmount = (double) $amounts["received"]['amount']; $this->receivedTransactions = (int) $amounts["received"]['number']; } // Get social profile $socialPlatform = $this->params->get("integration_social_platform"); if (!empty($socialPlatform)) { $options = array("social_platform" => $socialPlatform, "user_id" => $this->item->id); $profileBuilder = new Prism\Integration\Profile\Builder($options); $profileBuilder->build(); $this->socialProfile = $profileBuilder->getProfile(); $this->profileLink = $this->socialProfile->getLink(); } $this->rewards = new Crowdfunding\User\Rewards(JFactory::getDbo()); $this->rewards->load(array("user_id" => $this->item->id)); $this->returnUrl = base64_encode("index.php?option=com_crowdfunding&view=user&id=" . $this->item->id); // Prepare actions, behaviors, scripts and document $this->addToolbar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->params = $this->state->get('params'); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->state->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); $projectId = $this->state->get('project_id'); $this->projectTitle = CrowdfundingHelper::getProjectTitle($projectId); // Prepare sorting data $this->prepareSorting(); // Prepare actions $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->option = JFactory::getApplication()->input->get('option'); $this->state = $this->get('State'); $this->params = $this->state->get('params'); $this->version = new Crowdfunding\Version(); // Load Prism library version if (!class_exists('Prism\\Version')) { $this->prismVersion = JText::_('COM_CROWDFUNDING_PRISM_LIBRARY_DOWNLOAD'); } else { $prismVersion = new Prism\Version(); $this->prismVersion = $prismVersion->getShortVersion(); if (version_compare($this->prismVersion, $this->version->requiredPrismVersion, '<')) { $this->prismVersionLowerMessage = JText::_('COM_CROWDFUNDING_PRISM_LIBRARY_LOWER_VERSION'); } } // Get popular projects. $this->popular = new Crowdfunding\Statistics\Projects\Popular(JFactory::getDbo()); $this->popular->load(array('limit' => 5)); // Get popular most funded. $this->mostFunded = new Crowdfunding\Statistics\Projects\MostFunded(JFactory::getDbo()); $this->mostFunded->load(array('limit' => 5)); // Get latest started. $options = array('limit' => 10, 'order_by' => 'funding_start', 'order_direction' => 'DESC'); $this->latestStarted = new Crowdfunding\Statistics\Projects\Latest(JFactory::getDbo()); $this->latestStarted->load($options); // Get latest created. $options = array('limit' => 10, 'order_by' => 'created', 'order_direction' => 'DESC'); $this->latestCreated = new Crowdfunding\Statistics\Projects\Latest(JFactory::getDbo()); $this->latestCreated->load($options); // Get currency. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); // Add submenu CrowdfundingHelper::addSubmenu($this->getName()); $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->state = $this->get("State"); $this->params = $this->state->get("params"); $this->version = new Crowdfunding\Version(); // Load ITPrism library version if (!class_exists("Prism\\Version")) { $this->prismVersion = JText::_("COM_CROWDFUNDING_PRISM_LIBRARY_DOWNLOAD"); } else { $prismVersion = new Prism\Version(); $this->prismVersion = $prismVersion->getShortVersion(); if (version_compare($this->prismVersion, $this->version->requiredPrismVersion, "<")) { $this->prismVersionLowerMessage = JText::_("COM_CROWDFUNDING_PRISM_LIBRARY_LOWER_VERSION"); } } // Get popular projects. $this->popular = new Crowdfunding\Statistics\Projects\Popular(JFactory::getDbo()); $this->popular->load(5); // Get popular most funded. $this->mostFunded = new Crowdfunding\Statistics\Projects\MostFunded(JFactory::getDbo()); $this->mostFunded->load(5); // Get latest started. $this->latestStarted = new Crowdfunding\Statistics\Projects\Latest(JFactory::getDbo()); $this->latestStarted->load(5); // Get latest created. $this->latestCreated = new Crowdfunding\Statistics\Projects\Latest(JFactory::getDbo()); $this->latestCreated->loadByCreated(5); // Get currency. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); // Add submenu CrowdfundingHelper::addSubmenu($this->getName()); $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
/** * Display the view */ public function display($tpl = null) { $app = JFactory::getApplication(); $itemId = $app->input->getUint("id"); $model = $this->getModel(); $this->params = JComponentHelper::getParams("com_crowdfundingfinance"); $this->item = $model->getItem($itemId); $this->stats = new Crowdfunding\Statistics\Project(JFactory::getDbo(), $itemId); $this->transactionStatuses = $this->stats->getTransactionsStatusStatistics(); $this->payout = $this->stats->getPayoutStatistics(); /** @var $cParams Joomla\Registry\Registry */ $cParams = JComponentHelper::getParams("com_crowdfunding"); $this->cfParams = $cParams; $imagesFolder = $this->cfParams->get("images_directory", "images/crowdfunding"); $this->imagesUrl = JUri::root() . $imagesFolder; // Get currency. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->cfParams->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->cfParams); $this->amount->setCurrency($currency); // Prepare actions, behaviors, scripts and document $this->addToolbar(); $this->setDocument(); parent::display($tpl); }
/** * This method processes transaction data that comes from PayPal instant notifier. * * @param string $context This string gives information about that where it has been executed the trigger. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|array */ public function onPaymentNotify($context, &$params) { if (strcmp('com_crowdfunding.notify.' . $this->serviceAlias, $context) !== 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentRaw */ // Check document type $docType = $doc->getType(); if (strcmp('raw', $docType) !== 0) { return null; } // Validate request method $requestMethod = $this->app->input->getMethod(); if (strcmp('POST', $requestMethod) !== 0) { $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_REQUEST_METHOD'), $this->debugType, JText::sprintf($this->textPrefix . '_ERROR_INVALID_TRANSACTION_REQUEST_METHOD', $requestMethod)); return null; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_RESPONSE'), $this->debugType, $_POST) : null; // Decode custom data $custom = Joomla\Utilities\ArrayHelper::getValue($_POST, 'custom'); $custom = json_decode(base64_decode($custom), true); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_CUSTOM'), $this->debugType, $custom) : null; // Validate payment services. $gateway = Joomla\Utilities\ArrayHelper::getValue($custom, 'gateway'); if (!$this->isValidPaymentGateway($gateway)) { $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_PAYMENT_GATEWAY'), $this->debugType, array('custom' => $custom, '_POST' => $_POST)); return null; } // Get PayPal URL if ($this->params->get('paypal_sandbox', 1)) { $url = JString::trim($this->params->get('paypal_sandbox_url', 'https://www.sandbox.paypal.com/cgi-bin/webscr')); } else { $url = JString::trim($this->params->get('paypal_url', 'https://www.paypal.com/cgi-bin/webscr')); } $paypalIPN = new Prism\Payment\PayPal\Ipn($url, $_POST); $loadCertificate = (bool) $this->params->get('paypal_load_certificate', 0); $paypalIPN->verify($loadCertificate); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_IPN_OBJECT'), $this->debugType, $paypalIPN) : null; // Prepare the array that will be returned by this method $result = array('project' => null, 'reward' => null, 'transaction' => null, 'payment_session' => null, 'service_provider' => $this->serviceProvider, 'service_alias' => $this->serviceAlias); if ($paypalIPN->isVerified()) { // Get currency $currencyId = $params->get('project_currency'); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $currencyId); // Get payment session data $paymentSessionId = Joomla\Utilities\ArrayHelper::getValue($custom, 'payment_session_id', 0, 'int'); $paymentSession = $this->getPaymentSession(array('id' => $paymentSessionId)); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_PAYMENT_SESSION'), $this->debugType, $paymentSession->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_POST, $currency->getCode(), $paymentSession); if ($validData === null) { return $result; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_VALID_DATA'), $this->debugType, $validData) : null; // Get project. $projectId = Joomla\Utilities\ArrayHelper::getValue($validData, 'project_id'); $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $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, $validData); return $result; } // Set the receiver of funds $validData['receiver_id'] = $project->getUserId(); // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data $transactionData = $this->storeTransaction($validData, $project); if ($transactionData === null) { return $result; } // Update the number of distributed reward. $rewardId = Joomla\Utilities\ArrayHelper::getValue($transactionData, 'reward_id', 0, 'int'); $reward = null; if ($rewardId > 0) { $reward = $this->updateReward($transactionData); // Validate the reward. if (!$reward) { $transactionData['reward_id'] = 0; } } // Prepare the data that will be returned $result['transaction'] = Joomla\Utilities\ArrayHelper::toObject($transactionData); // 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 ($reward !== null and $reward instanceof Crowdfunding\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); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_RESULT_DATA'), $this->debugType, $result) : null; // Remove payment session. $txnStatus = isset($result['transaction']->txn_status) ? $result['transaction']->txn_status : null; $this->closePaymentSession($paymentSession, $txnStatus); } else { // Log error $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_TRANSACTION_DATA'), $this->debugType, array('error message' => $paypalIPN->getError(), 'paypalIPN' => $paypalIPN, '_POST' => $_POST)); } return $result; }
/** * This method processes transaction. * * @param string $context This string gives information about that where it has been executed the trigger. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|array */ public function onPaymentNotify($context, &$params) { if (strcmp('com_crowdfunding.notify.blockchain', $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; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_RESPONSE'), $this->debugType, $_GET) : null; $result = array('project' => null, 'reward' => null, 'transaction' => null, 'payment_session' => null, 'service_provider' => $this->serviceProvider, 'service_alias' => $this->serviceAlias, 'response' => ''); // Get extension parameters $currencyId = $params->get('project_currency'); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $currencyId); // Get payment session data $paymentSessionId = $this->app->input->get->get('payment_session_id'); $paymentSession = $this->getPaymentSession(array('id' => $paymentSessionId)); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_PAYMENT_SESSION'), $this->debugType, $paymentSession->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_GET, $currency->getCode(), $paymentSession); if ($validData === null) { return $result; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_VALID_DATA'), $this->debugType, $validData) : null; // Get project $projectId = Joomla\Utilities\ArrayHelper::getValue($validData, 'project_id'); $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $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, $validData); return $result; } // Set the receiver of funds $validData['receiver_id'] = $project->getUserId(); // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data $transactionData = $this->storeTransaction($validData, $project); if ($transactionData === null) { return $result; } // Update the number of distributed reward. $rewardId = Joomla\Utilities\ArrayHelper::getValue($transactionData, 'reward_id', 0, 'int'); $reward = null; if ($rewardId > 0) { $reward = $this->updateReward($transactionData); // Validate the reward. if (!$reward) { $transactionData['reward_id'] = 0; } } // Prepare the data that will be returned $result['transaction'] = Joomla\Utilities\ArrayHelper::toObject($transactionData); // 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 ($reward !== null and $reward instanceof Crowdfunding\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); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_RESULT_DATA'), $this->debugType, $result) : null; // Remove payment session. $txnStatus = isset($result['transaction']->txn_status) ? $result['transaction']->txn_status : null; $this->closePaymentSession($paymentSession, $txnStatus); if (strcmp('completed', $result['transaction']->txn_status) === 0) { $result['response'] = '*ok*'; } return $result; }
return; } // Get project $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId); if (!$project->getId()) { return; } // Get component params $componentParams = JComponentHelper::getParams('com_crowdfunding'); /** @var $componentParams Joomla\Registry\Registry */ $socialPlatform = $componentParams->get('integration_social_platform'); $imageFolder = $componentParams->get('images_directory', 'images/crowdfunding'); $imageWidth = $componentParams->get('image_width', 200); $imageHeight = $componentParams->get('image_height', 200); // Get currency $currencyId = $componentParams->get('project_currency'); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $componentParams->get('project_currency')); $amount = new Crowdfunding\Amount($componentParams); $amount->setCurrency($currency); // Get social platform and a link to the profile $socialBuilder = new Prism\Integration\Profile\Builder(array('social_platform' => $socialPlatform, 'user_id' => $project->getUserId())); $socialBuilder->build(); $socialProfile = $socialBuilder->getProfile(); $socialProfileLink = !$socialProfile ? null : $socialProfile->getLink(); // Get amounts $fundedAmount = $amount->setValue($project->getGoal())->formatCurrency(); $raised = $amount->setValue($project->getFunded())->formatCurrency(); // Prepare the value that I am going to display $fundedPercents = JHtml::_('crowdfunding.funded', $project->getFundedPercent()); $user = JFactory::getUser($project->getUserId()); require JModuleHelper::getLayoutPath('mod_crowdfundingdetails', $params->get('layout', 'default'));
protected function prepareManager() { $model = JModelLegacy::getInstance('Manager', 'CrowdfundingModel', $config = array('ignore_request' => false)); /** @var $model CrowdfundingModelManager */ // Get state $this->state = $model->getState(); /** @var $state Joomla\Registry\Registry */ $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 = $this->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'); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); $this->item = $model->getItem($itemId, $this->userId); // Check if the item exists. if (!CrowdfundingHelper::isAuthorized($this->userId, $this->item, 'manager')) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_SOMETHING_WRONG'), 'notice'); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute())); return; } $statistics = new Crowdfunding\Statistics\Project(JFactory::getDbo(), $this->item->id); $this->statistics = array('updates' => $statistics->getUpdatesNumber(), 'comments' => $statistics->getCommentsNumber(), 'funders' => $statistics->getTransactionsNumber()); // Get rewards $this->rewards = new Crowdfunding\Rewards(JFactory::getDbo()); $this->rewards->load(array('project_id' => $this->item->id)); $this->pathwayName = JText::_('COM_CROWDFUNDING_STEP_MANAGER'); }
/** * Prepare an amount, parsing it from formatted string to decimal value. * This is most used when a user post a data via form. * * @param float $value * * @return string|float */ public static function parseAmount($value) { $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Parse the goal amount. $amount = new Crowdfunding\Amount($params, $value); $amount->setCurrency($currency); return $amount->parse(); }
/** * This method processes transaction data that comes from PayPal instant notifier. * * @param string $context This string gives information about that where it has been executed the trigger. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|array */ public function onPaymentNotify($context, &$params) { if (strcmp("com_crowdfunding.notify.paypal", $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; } // Validate request method $requestMethod = $this->app->input->getMethod(); if (strcmp("POST", $requestMethod) != 0) { $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_REQUEST_METHOD"), $this->debugType, JText::sprintf($this->textPrefix . "_ERROR_INVALID_TRANSACTION_REQUEST_METHOD", $requestMethod)); return null; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESPONSE"), $this->debugType, $_POST) : null; // Decode custom data $custom = Joomla\Utilities\ArrayHelper::getValue($_POST, "custom"); $custom = json_decode(base64_decode($custom), true); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_CUSTOM"), $this->debugType, $custom) : null; // Verify gateway. Is it PayPal? if (!$this->isPayPalGateway($custom)) { $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PAYMENT_GATEWAY"), $this->debugType, array("custom" => $custom, "_POST" => $_POST)); return null; } // Get PayPal URL if ($this->params->get('paypal_sandbox', 1)) { $url = Joomla\String\String::trim($this->params->get('paypal_sandbox_url', "https://www.sandbox.paypal.com/cgi-bin/webscr")); } else { $url = Joomla\String\String::trim($this->params->get('paypal_url', "https://www.paypal.com/cgi-bin/webscr")); } $paypalIpn = new Prism\Payment\PayPal\Ipn($url, $_POST); $loadCertificate = (bool) $this->params->get("paypal_load_certificate", 0); $paypalIpn->verify($loadCertificate); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_VERIFY_OBJECT"), $this->debugType, $paypalIpn) : null; // Prepare the array that have to be returned by this method. $result = array("project" => null, "reward" => null, "transaction" => null, "payment_session" => null, "payment_service" => $this->paymentService); if ($paypalIpn->isVerified()) { // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Get payment session data $paymentSessionId = Joomla\Utilities\ArrayHelper::getValue($custom, "payment_session_id", 0, "int"); $paymentSession = $this->getPaymentSession(array("id" => $paymentSessionId)); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYMENT_SESSION"), $this->debugType, $paymentSession->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_POST, $currency->getCode(), $paymentSession); if (is_null($validData)) { return $result; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_VALID_DATA"), $this->debugType, $validData) : null; // Get project. $projectId = Joomla\Utilities\ArrayHelper::getValue($validData, "project_id"); $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $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, $validData); return $result; } // Set the receiver of funds. $validData["receiver_id"] = $project->getUserId(); // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data $transactionData = $this->storeTransaction($validData, $project); if (is_null($transactionData)) { return $result; } // Update the number of distributed reward. $rewardId = Joomla\Utilities\ArrayHelper::getValue($transactionData, "reward_id"); $reward = null; if (!empty($rewardId)) { $reward = $this->updateReward($transactionData); // Validate the reward. if (!$reward) { $transactionData["reward_id"] = 0; } } // Generate object of data, based on the transaction properties. $result["transaction"] = Joomla\Utilities\ArrayHelper::toObject($transactionData); // 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); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESULT_DATA"), $this->debugType, $result) : null; // Remove payment session. $txnStatus = isset($result["transaction"]->txn_status) ? $result["transaction"]->txn_status : null; $this->closePaymentSession($paymentSession, $txnStatus); } else { // Log error $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_TRANSACTION_DATA"), $this->debugType, array("error message" => $paypalIpn->getError(), "paypalVerify" => $paypalIpn, "_POST" => $_POST)); } return $result; }
protected function prepareFundersScreen() { $model = JModelLegacy::getInstance('Funders', 'CrowdfundingModel', $config = array('ignore_request' => false)); $this->items = $model->getItems(); // Get users IDs $usersIds = array(); foreach ($this->items as $item) { $usersIds[] = $item->id; } $usersIds = array_filter($usersIds); // Create a currency object if I have to display funders amounts. $this->displayAmounts = $this->params->get('funders_display_amounts', 0); if ($this->displayAmounts) { $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); } // Prepare social integration. $this->socialProfiles = CrowdfundingHelper::prepareIntegrations($this->params->get('integration_social_platform'), $usersIds); }
protected function prepareManager() { $model = JModelLegacy::getInstance("Manager", "CrowdfundingModel", $config = array('ignore_request' => false)); /** @var $model CrowdfundingModelManager */ // Get state $this->state = $model->getState(); /** @var $state Joomla\Registry\Registry */ $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 = $this->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'); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); $this->item = $model->getItem($itemId, $this->userId); // Check if the item exists. if (!$this->isValid()) { return; } $statistics = new Crowdfunding\Statistics\Project(JFactory::getDbo(), $this->item->id); $this->statistics = array("updates" => $statistics->getUpdatesNumber(), "comments" => $statistics->getCommentsNumber(), "funders" => $statistics->getTransactionsNumber()); // Get rewards $this->rewards = new Crowdfunding\Rewards(JFactory::getDbo()); $this->rewards->load(array("project_id" => $this->item->id)); $this->pathwayName = JText::_("COM_CROWDFUNDING_STEP_MANAGER"); }