/** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.0 */ public function register(Container $container) { $container->share('JApplicationAdministrator', function (Container $container) { $app = new \JApplicationAdministrator(null, null, null, $container); // The session service provider needs JFactory::$application, set it if still null if (JFactory::$application === null) { JFactory::$application = $app; } $app->setDispatcher($container->get('Joomla\\Event\\DispatcherInterface')); $app->setLogger(JLog::createDelegatedLogger()); $app->setSession($container->get('Joomla\\Session\\SessionInterface')); return $app; }, true); $container->share('JApplicationSite', function (Container $container) { $app = new \JApplicationSite(null, null, null, $container); // The session service provider needs JFactory::$application, set it if still null if (JFactory::$application === null) { JFactory::$application = $app; } $app->setDispatcher($container->get('Joomla\\Event\\DispatcherInterface')); $app->setLogger(JLog::createDelegatedLogger()); $app->setSession($container->get('Joomla\\Session\\SessionInterface')); return $app; }, true); }
public function onContentAfterDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.details", $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; } $html = ""; $files = new CrowdfundingFiles\Files(JFactory::getDbo()); $files->load(array("project_id" => $item->id)); if (count($files) > 0) { $mediaFolderUri = CrowdfundingFilesHelper::getMediaFolderUri($item->user_id); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('content', 'crowdfundingfiles')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); } return $html; }
/** * This method does some validations before the system to provide payment methods. * * @param string $context This string gives information about that where it has been executed the trigger. * @param stdClass $item A project data. * @param Prism\Money\Money $money An Money object. * @param Joomla\Registry\Registry $params The parameters of the component * * @throws \InvalidArgumentException * * @return null|string */ public function onBeforePaymentAuthorize($context, &$item, &$money, &$params) { if (strcmp('com_crowdfunding.before.payment.authorize', $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; } // Get user ID. $userId = JFactory::getUser()->get('id'); $html = array(); // Display login form if (!$userId) { $html[] = '<p class="bg-warning p-5">'; $html[] = '<span class="fa fa-exclamation-triangle"></span>'; $html[] = JText::_('PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_NOT_REGISTERED'); $html[] = '</p>'; } // Verifications // Get component parameters $componentParams = JComponentHelper::getParams('com_crowdfundingfinance'); /** @var $componentParams Joomla\Registry\Registry */ // Verify maximum allowed amount for contribution. $allowedContributedAmount = $money->setAmount($componentParams->get('protection_max_contributed_amount'))->parse(); // Validate maximum allowed amount. if ($allowedContributedAmount and $allowedContributedAmount < (double) $item->amount) { $html[] = '<p class="bg-warning p-5">'; $html[] = '<span class="fa fa-exclamation-triangle"></span>'; $html[] = JText::sprintf('PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_CONTRIBUTION_AMOUNT_S', $money->setAmount($allowedContributedAmount)->formatCurrency()); $html[] = '</p>'; } // Verify the number of payments per project. $allowedPaymentsPerProject = (int) $componentParams->get('protection_payments_per_project'); if ($allowedPaymentsPerProject > 0) { $userStatistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $userId); $paymentsPerProject = (int) $userStatistics->getNumberOfPayments($item->id); // Validate number of payments per project. if ($paymentsPerProject >= $allowedPaymentsPerProject) { $html[] = '<p class="bg-warning p-5">'; $html[] = '<span class="fa fa-exclamation-triangle"></span>'; $html[] = JText::sprintf('PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_PAYMENT_PER_PROJECT_D', $allowedPaymentsPerProject); $html[] = '</p>'; } } return count($html) > 0 ? implode("\n", $html) : null; }
/** * This method validates project data before a user launch its campaign. * It works only on front-end. * * @param string $context * @param stdClass $item * @param Joomla\Registry\Registry $params * @param int $state * * @return null|array */ public function onContentValidateChangeState($context, &$item, &$params, $state) { if (strcmp('com_crowdfunding.projects.changestate', $context) !== 0) { return null; } // This validation have to be processed when the state is for launching (publishing) campaign. if ((int) $state !== 1) { 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; } $result = array('success' => false, 'message' => ''); // Get user ID. $userId = JFactory::getUser()->get('id'); // Get component parameters $componentParams = JComponentHelper::getParams('com_crowdfundingfinance'); /** @var $componentParams Joomla\Registry\Registry */ // Verify the number of campaigns per user at one time. $allowedActiveCampaigns = (int) $componentParams->get('protection_active_projects'); if ($allowedActiveCampaigns > 0) { // Get the number of active projects for a user. $userStatistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $userId); $activeCampaigns = (int) $userStatistics->getNumberOfActiveCampaigns(); // Validate number of active campaigns per user. if ($activeCampaigns >= $allowedActiveCampaigns) { $result['message'] = JText::sprintf('PLG_CONTENT_CROWDFUNDINGFRAUDPREVENTION_ERROR_ACTIVE_PROJECTS_D', $allowedActiveCampaigns); return $result; } } // Verify the number of campaigns per user per year. $allowedCampaignsPerYear = (int) $componentParams->get('protection_projects_per_year'); if ($allowedCampaignsPerYear > 0) { // Get the number of active projects for a user. $userStatistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $userId); $numberOfCampaigns = (int) $userStatistics->getNumberOfCampaignsInPeriod(); // Validate number of campaigns per year. if ($numberOfCampaigns >= $allowedCampaignsPerYear) { $result['message'] = JText::sprintf('PLG_CONTENT_CROWDFUNDINGFRAUDPREVENTION_ERROR_PROJECTS_YEAR_D', $allowedCampaignsPerYear); return $result; } } // Validation completed successfully. $result = array('success' => true); return $result; }
/** * This method prepares a code that will be included to step "Extras" on project wizard. * * @param string $context This string gives information about that where it has been executed the trigger. * @param object $item A project data. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|string */ public function onExtrasDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.project.extras", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("html", $docType) != 0) { return null; } if (empty($item->user_id)) { return null; } // Create a media folder. $mediaFolder = CrowdfundingFilesHelper::getMediaFolder(); if (!JFolder::exists($mediaFolder)) { CrowdfundingHelper::createFolder($mediaFolder); } // Create a media folder for a user. $mediaFolder = CrowdfundingFilesHelper::getMediaFolder($item->user_id); if (!JFolder::exists($mediaFolder)) { CrowdfundingHelper::createFolder($mediaFolder); } $componentParams = JComponentHelper::getParams("com_crowdfundingfiles"); /** @var $componentParams Joomla\Registry\Registry */ $mediaUri = CrowdfundingFilesHelper::getMediaFolderUri($item->user_id); $options = array("project_id" => $item->id, "user_id" => $item->user_id); $files = new CrowdfundingFiles\Files(JFactory::getDbo()); $files->load($options); // Load jQuery JHtml::_("jquery.framework"); JHtml::_("prism.ui.pnotify"); JHtml::_('prism.ui.fileupload'); JHtml::_('prism.ui.joomlaHelper'); // Include the translation of the confirmation question. JText::script('PLG_CROWDFUNDING_FILES_DELETE_QUESTION'); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('crowdfunding', 'files')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); return $html; }
/** * Init internal vars */ private function __construct() { // get links to global vars $this->doc = JFactory::getDocument(); $this->config = JFactory::getConfig(); $this->url = JUri::getInstance(); $this->app = JFactory::getApplication(); $this->menu = $this->app->getMenu(); $this->params = $this->app->getTemplate(true)->params; $this->user = JFactory::getUser(); $this->baseurl = $this->_getBaseUrl(); // relative paths $this->path = $this->_getTemplatePath(); $this->img = $this->path . '/images'; $this->less = $this->path . '/less'; $this->scss = $this->path . '/scss'; $this->css = $this->path . '/css'; $this->js = $this->path . '/js'; // absolute paths $this->pathFull = $this->_getTemplatePathFull(); $this->imgFull = JPath::clean($this->pathFull . '/images'); $this->cssFull = JPath::clean($this->pathFull . '/css'); $this->lessFull = JPath::clean($this->pathFull . '/less'); $this->scssFull = JPath::clean($this->pathFull . '/scss'); $this->jsFull = JPath::clean($this->pathFull . '/js'); $this->partial = JPath::clean($this->pathFull . '/partial'); // init template vars $this->lang = $this->_getLangCurrent(); $this->langDef = $this->_getLangDefault(); $this->request = $this->_getRequest(); $this->dir = $this->doc->getDirection(); // init mobile detect $this->mobile = $this->_getMobile(); }
/** * Tests the JApplicationSite::setTemplate method. * * @return void * * @since 3.2 */ public function testSetTemplate() { $this->class->setTemplate('beez3'); $template = $this->class->getTemplate(true); $this->assertThat($template->params, $this->isInstanceOf('JRegistry')); $this->assertThat($template->template, $this->equalTo('beez3')); }
/** * This method is executed after complete payment. * It is used to be stored the transaction ID and the investor ID in data record. * * @param object $context * @param object $transaction Transaction data * @param Joomla\Registry\Registry $params Component parameters * @param object $project Project data * @param object $reward Reward data * @param object $paymentSession Payment session object. * * @return void */ public function onAfterPayment($context, &$transaction, &$params, &$project, &$reward, &$paymentSession) { if (0 !== strpos($context, "com_crowdfunding.notify")) { return; } if ($this->app->isAdmin()) { return; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("raw", $docType) != 0) { return; } // Load record data from database. $keys = array("session_id" => $paymentSession->session_id); $record = new CrowdfundingData\Record(JFactory::getDbo()); $record->load($keys); if (!$record->getId()) { return null; } // Set transaction ID. if (!empty($transaction->id)) { $record->setTransactionId($transaction->id); } // Set user ID. if (!empty($transaction->investor_id)) { $record->setUserId($transaction->investor_id); } $record->store(); }
private function preparePageTitle() { // Prepare page title $title = $this->item->title; switch ($this->screen) { case 'updates': $title .= ' | ' . JText::_('COM_CROWDFUNDING_UPDATES'); break; case 'comments': $title .= ' | ' . JText::_('COM_CROWDFUNDING_COMMENTS'); break; case 'funders': $title .= ' | ' . JText::_('COM_CROWDFUNDING_FUNDERS'); break; } // Add title before or after Site Name if (!$title) { $title = $this->app->get('sitename'); } elseif ((int) $this->app->get('sitename_pagetitles', 0) === 1) { $title = JText::sprintf('JPAGETITLE', $this->app->get('sitename'), $title); } elseif ((int) $this->app->get('sitename_pagetitles', 0) === 2) { $title = JText::sprintf('JPAGETITLE', $title, $this->app->get('sitename')); } $this->document->setTitle($title); }
/** * Tests the JApplicationSite::setTemplate method. * * @return void * * @since 3.2 */ public function testSetTemplate() { $this->class->setTemplate('beez3'); $template = $this->class->getTemplate(true); $this->assertInstanceOf('\\Joomla\\Registry\\Registry', $template->params); $this->assertEquals('beez3', $template->template); }
/** * 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; }
protected function returnToStep1(&$paymentSession, $message = "") { // Reset the flag for step 1 $paymentSession->step1 = false; $this->app->setUserState($this->paymentSessionContext, $paymentSession); if (!empty($message)) { $this->app->enqueueMessage($message, "notice"); } $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false)); }
/** * This method prepares a code that will be included to step "Extras" on project wizard. * * @param string $context This string gives information about that where it has been executed the trigger. * @param object $item A project data. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|string */ public function onExtrasDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.project.extras", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("html", $docType) != 0) { return null; } if (empty($item->user_id)) { return null; } // A flag that shows the options are active. if (!$this->params->get("display_paypal", 0) and !$this->params->get("display_banktransfer", 0)) { return ""; } $activeTab = ""; if ($this->params->get("display_paypal", 0)) { $activeTab = "paypal"; } elseif ($this->params->get("display_banktransfer", 0)) { $activeTab = "banktransfer"; } $payout = new CrowdfundingFinance\Payout(JFactory::getDbo()); $payout->load($item->id); // Load jQuery JHtml::_("jquery.framework"); JHtml::_("prism.ui.pnotify"); JHtml::_('prism.ui.joomlaHelper'); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('crowdfunding', 'payoutoptions')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); return $html; }
/** * Generate and display a list of team members on details page. * * @param string $context * @param object $item * @param Joomla\Registry\Registry $params * * @return null|string */ public function onContentAfterDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.details", $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; } $html = ""; $partners = new CrowdfundingPartners\Partners(JFactory::getDbo()); $partners->load($item->id); if (0 < count($partners)) { // Include the project owner to the team. if ($this->params->get("display_owner", 0)) { $user = JFactory::getUser($item->user_id); $owner = array("name" => $user->get("name"), "project_id" => $item->id, "partner_id" => $item->user_id); $partners->add($owner); } // Get a social platform for integration $socialPlatform = $params->get("integration_social_platform"); // Prepare avatars. $this->prepareIntegration($partners, $socialPlatform); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('content', 'crowdfundingpartners')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); } return $html; }
/** * This method prepares a code that will be included to step "Extras" on project wizard. * * @param string $context This string gives information about that where it has been executed the trigger. * @param object $item A project data. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|string */ public function onExtrasDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.project.extras", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("html", $docType) != 0) { return null; } if (empty($item->user_id)) { return null; } $partners = new CrowdfundingPartners\Partners(JFactory::getDbo()); $partners->load($item->id); // Get a social platform for integration $socialPlatform = $params->get("integration_social_platform"); // Prepare avatars. $this->prepareIntegration($partners, $socialPlatform); // Load jQuery JHtml::_("jquery.framework"); JHtml::_("prism.ui.pnotify"); JHtml::_('prism.ui.joomlaHelper'); // Include the translation of the confirmation question. JText::script('PLG_CROWDFUNDING_PARTNERS_DELETE_QUESTION'); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('crowdfunding', 'partners')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); return $html; }
private function preparePageTitle() { // Prepare page title $title = $this->item->title . ' | ' . JText::_('COM_CROWDFUNDING_EMAIL_TO_FRIEND'); // Add title before or after Site Name if (!$title) { $title = $this->app->get('sitename'); } elseif ((int) $this->app->get('sitename_pagetitles', 0) === 1) { $title = JText::sprintf('JPAGETITLE', $this->app->get('sitename'), $title); } elseif ((int) $this->app->get('sitename_pagetitles', 0) === 2) { $title = JText::sprintf('JPAGETITLE', $title, $this->app->get('sitename')); } $this->document->setTitle($title); }
private function preparePageTitle() { // Prepare page title $title = $this->params->get('page_title', ''); // Add title before or after Site Name if (!$title) { $title = $this->app->get('sitename'); } elseif ((int) $this->app->get('sitename_pagetitles', 0) === 1) { $title = JText::sprintf('JPAGETITLE', $this->app->get('sitename'), $title); } elseif ((int) $this->app->get('sitename_pagetitles', 0) === 2) { $title = JText::sprintf('JPAGETITLE', $title, $this->app->get('sitename')); } $this->document->setTitle($title); }
/** * This method is used from the system to authorize step 2, * when you use a payment wizard in four steps. * If this method return true, the system will continue to step 2. * * @param string $context This string gives information about that where it has been executed the trigger. * @param object $item * @param Joomla\Registry\Registry $params * @param JUser $user * * @return bool */ public function onPaymentAuthorize($context, &$item, &$params, &$user) { if (strcmp("com_crowdfunding.payment.authorize", $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; } return true; }
/** * Execute 301 redirect with cycle checking * @param $newUrl * @return null */ protected function _redirect($newUrl) { if (!$newUrl) { return null; } $juri = JUri::getInstance(); $fullCurUrl = urldecode($juri->toString()); $curUrl = urldecode($juri->toString(array('path', 'query', 'fragment'))); // checking for cycle redirect if ($newUrl !== $curUrl && $newUrl !== $fullCurUrl) { if ($this->app->jbversion->joomla(3)) { $this->_joomlaApp->redirect($newUrl, true); } else { $this->_joomlaApp->redirect($newUrl, '', 'message', true); } } }
/** * This method is executed after complete payment. * It is used to be sent mails to user and administrator * * @param string $context Transaction data * @param \stdClass $transaction Transaction data * @param Registry $params Component parameters * @param \stdClass $project Project data * @param \stdClass $reward Reward data * @param \stdClass $paymentSession Payment session data. */ public function onAfterPayment($context, &$transaction, &$params, &$project, &$reward, &$paymentSession) { if (strcmp('com_crowdfunding.notify.' . $this->serviceAlias, $context) !== 0) { return; } if ($this->app->isAdmin()) { return; } $doc = \JFactory::getDocument(); /** @var $doc \JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('raw', $docType) !== 0) { return; } // Send mails $this->sendMails($project, $transaction, $params, $reward); }
/** * This method is executed after complete payment. * It is used to be sent mails to user and administrator * * @param string $context * @param object $transaction Transaction data * @param Joomla\Registry\Registry $params Component parameters * @param object $project Project data * @param object $reward Reward data * @param object $paymentSession Payment session data. * * @return void */ public function onAfterPayment($context, &$transaction, &$params, &$project, &$reward, &$paymentSession) { if (strcmp("com_crowdfunding.notify.paypal", $context) != 0) { return; } if ($this->app->isAdmin()) { return; } $doc = JFactory::getDocument(); /** @var $doc JDocumentRaw */ // Check document type $docType = $doc->getType(); if (strcmp("raw", $docType) != 0) { return; } // Send mails $this->sendMails($project, $transaction, $params); }
private function preparePageTitle() { // Because the application sets a default page title, // we need to get it from the menu item itself. // $menus = $this->app->getMenu(); // $menu = $menus->getActive(); // Prepare page title $title = $this->documentTitle; // Add title before or after Site Name if (!$title) { $title = $this->app->get('sitename'); } elseif ((int) $this->app->get('sitename_pagetitles', 0) === 1) { $title = JText::sprintf('JPAGETITLE', $this->app->get('sitename'), $title); } elseif ((int) $this->app->get('sitename_pagetitles', 0) === 2) { $title = JText::sprintf('JPAGETITLE', $title, $this->app->get('sitename')); } $this->document->setTitle($title); }
/** * This method will be executed after all payment events, especially onAfterPaymentNotify. * It is used to close payment session. * * <code> * $paymentResult->transaction; * $paymentResult->project; * $paymentResult->reward; * $paymentResult->paymentSession; * $paymentResult->serviceProvider; * $paymentResult->serviceAlias; * $paymentResult->response; * $paymentResult->returnUrl; * $paymentResult->message; * $paymentResult->triggerEvents; * </code> * * @param string $context * @param \stdClass $paymentResult Object that contains Transaction, Reward, Project, PaymentSession, etc. * @param Registry $params Component parameters * * @throws \InvalidArgumentException */ public function onAfterPayment($context, $paymentResult, $params) { if (!preg_match('/com_crowdfunding\\.(notify|payments)/', $context)) { return; } if ($this->app->isAdmin()) { return; } // Check document type $docType = \JFactory::getDocument()->getType(); if (!in_array($docType, array('raw', 'html'), true)) { return; } $paymentSession = $paymentResult->paymentSession; /** @var PaymentSessionRemote $paymentSession */ // Remove payment session record from database. if ($paymentSession instanceof PaymentSessionRemote and $paymentSession->getId()) { $paymentSession->delete(); } }
/** * Put some additional code - namespaces, * additional code after body tag or before closing body tag. */ public function onAfterRender() { // Check for restrictions if ($this->isRestricted()) { return; } // Get document buffer $buffer = $this->app->getBody(); switch ($this->params->get('tags_position', 0)) { case 1: $buffer = $this->putAfterHead($buffer); break; case 2: $buffer = $this->putAfterTitle($buffer); break; } // Put open graph namespace in the HTML element $buffer = $this->putNamespaces($buffer, $this->params); // Add code after body tag and before closing body tag $buffer = $this->putAdditionalCode($buffer); $this->app->setBody($buffer); }
protected function preparePageTitle() { // Prepare page title // $title = $this->params->get('page_title', $this->item->title); $title = JText::sprintf("COM_CROWDFUNDING_INVESTING_IN", $this->escape($this->item->title)); switch ($this->getLayout()) { case "payment": $title .= " | " . JText::_("COM_CROWDFUNDING_PAYMENT_METHODS"); break; case "share": $title .= " | " . JText::_("COM_CROWDFUNDING_SHARE"); break; } // Add title before or after Site Name if (!$title) { $title = $this->app->get('sitename'); } elseif ($this->app->get('sitename_pagetitles', 0) == 1) { $title = JText::sprintf('JPAGETITLE', $this->app->get('sitename'), $title); } elseif ($this->app->get('sitename_pagetitles', 0) == 2) { $title = JText::sprintf('JPAGETITLE', $title, $this->app->get('sitename')); } $this->document->setTitle($title); }
/** * 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; }
/** * Catch a request from payment plugin via AJAX and process a transaction. */ public function notifyAjax() { $response = new Prism\Response\Json(); // Check for disabled payment functionality if ($this->params->get('debug_payment_disabled', 0)) { $errorData = JText::sprintf('COM_CROWDFUNDING_TRANSACTION_DATA', var_export($_REQUEST, true)); $this->log->add(JText::_('COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED'), 'ERROR_CONTROLLER_NOTIFIER_AJAX', $errorData); // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE'))->failure(); echo $response; $this->app->close(); } // Get model object. $model = $this->getModel(); $paymentResult = null; $redirectUrl = null; $message = null; $project = null; /** @var Crowdfunding\Project $project */ // Trigger the event try { // Import Crowdfunding Payment Plugins JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onPaymentNotify event. $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onPaymentNotify', array($this->context, &$this->params)); if (is_array($results) and count($results) > 0) { foreach ($results as $result) { if (is_object($result) and isset($result->transaction)) { $paymentResult = $result; $project = isset($result->project) ? $result->project : null; $redirectUrl = isset($result->redirectUrl) ? $result->redirectUrl : null; $message = isset($result->message) ? $result->message : null; break; } } } // If there is no transaction data, the status might be pending or another one. // So, we have to stop the script execution. if (!$paymentResult) { // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_TRANSACTION_NOT_PROCESSED_SUCCESSFULLY'))->failure(); echo $response; $this->app->close(); } // Trigger the event onAfterPaymentNotify $dispatcher->trigger('onAfterPaymentNotify', array($this->context, &$paymentResult, &$this->params)); // Trigger the event onAfterPayment $dispatcher->trigger('onAfterPayment', array($this->context, &$paymentResult, &$this->params)); } catch (Exception $e) { // Store log data to the database. $error = 'AJAX NOTIFIER ERROR: ' . $e->getMessage() . "\n"; $errorData = 'INPUT:' . var_export($this->app->input, true) . "\n"; $this->log->add($error, 'ERROR_CONTROLLER_NOTIFIER_AJAX', $errorData); // Send response to the browser $response->failure()->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); // Send notification about the error to the administrator. $model->sendMailToAdministrator(); echo $response; $this->app->close(); } // Generate redirect URL if (!$redirectUrl and is_object($project)) { $uri = JUri::getInstance(); $redirectUrl = $uri->toString(array('scheme', 'host')) . JRoute::_(CrowdfundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatSlug(), 'share')); } if (!$message) { $message = JText::_('COM_CROWDFUNDING_TRANSACTION_PROCESSED_SUCCESSFULLY'); } // Send response to the browser $response->success()->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText($message)->setRedirectUrl($redirectUrl); echo $response; $this->app->close(); }
/** * @param JApplicationSite $app */ protected function prepareInformation($app) { if ($this->params->get("debug_payment_disabled", 0)) { $app->redirect(JRoute::_('index.php?option=com_virtualcurrency&view=payment', false)); } $paymentSessionData = $app->getUserState("payment.data"); $itemId = $paymentSessionData["item_id"]; $this->amount = $paymentSessionData["amount"]; jimport("virtualcurrency.currency"); $this->item = new VirtualCurrencyCurrency(JFactory::getDbo()); $this->item->load($itemId); // Calculate total amount that should be paid. jimport("itprism.math"); $total = new ITPrismMath(); $total->calculateTotal(array($this->amount, $this->item->getParam("amount"))); $this->total = (string) $total; // Get real currency $realCurrencyId = $this->params->get("payments_currency_id"); jimport("virtualcurrency.realcurrency"); $this->realCurrency = VirtualCurrencyRealCurrency::getInstance(JFactory::getDbo(), $realCurrencyId, $this->params); }
/** * Prepares the document */ protected function prepareDocument() { // Prepare page suffix $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $menus = $this->app->getMenu(); // Because the application sets a default page title, // we need to get it from the menu item itself $menu = $menus->getActive(); if ($menu) { $this->params->def('page_heading', $menu->title); } else { $this->params->def('page_heading', JText::_('COM_CROWDFUNDING_RAISE_DEFAULT_PAGE_TITLE')); } // Prepare page title $title = $menu->title; if (!$title) { $title = $this->app->get('sitename'); // Set site name if it is necessary ( the option 'sitename' = 1 ) } elseif ($this->app->get('sitename_pagetitles', 0)) { $title = JText::sprintf('JPAGETITLE', $this->app->get('sitename'), $title); // Item title to the browser title. } else { if ($this->item !== null) { $title .= ' | ' . $this->escape($this->item->title); } } $this->document->setTitle($title); // Meta Description $this->document->setDescription($this->params->get('menu-meta_description')); // Meta keywords $this->document->setMetaData('keywords', $this->params->get('menu-meta_keywords')); // Add current layout into breadcrumbs. $pathway = $this->app->getPathway(); $pathway->addItem($this->pathwayName); // Scripts if ($this->userId) { JHtml::_('behavior.core'); JHtml::_('behavior.keepalive'); if ($this->params->get('enable_chosen', 1)) { JHtml::_('formbehavior.chosen', '.cf-advanced-select'); } } $version = new Crowdfunding\Version(); switch ($this->layout) { case 'rewards': // Load language string in JavaScript JText::script('COM_CROWDFUNDING_QUESTION_REMOVE_REWARD'); JText::script('COM_CROWDFUNDING_QUESTION_REMOVE_IMAGE'); JText::script('COM_CROWDFUNDING_PICK_IMAGE'); // Scripts if ($this->params->get('rewards_images', 0)) { JHtml::_('Prism.ui.bootstrap3Fileinput'); } JHtml::_('Prism.ui.pnotify'); JHtml::_('Prism.ui.joomlaHelper'); $this->document->addScript('media/' . $this->option . '/js/site/project_rewards.js?v=' . $version->getShortVersion()); break; case 'funding': JHtml::_('Prism.ui.parsley'); JHtml::_('Prism.ui.bootstrap3Datepicker'); $this->document->addScript('media/' . $this->option . '/js/site/project_funding.js?v=' . $version->getShortVersion()); // Load language string in JavaScript JText::script('COM_CROWDFUNDING_THIS_VALUE_IS_REQUIRED'); break; case 'story': // Scripts JHtml::_('Prism.ui.bootstrap3FileInput'); // Include translation of the confirmation question for image removing. JText::script('COM_CROWDFUNDING_QUESTION_REMOVE_IMAGE'); JText::script('COM_CROWDFUNDING_PICK_IMAGE'); JText::script('COM_CROWDFUNDING_REMOVE'); $this->document->addScript('media/' . $this->option . '/js/site/project_story.js?v=' . $version->getShortVersion()); break; case 'manager': $this->document->addScript('media/' . $this->option . '/js/site/project_manager.js?v=' . $version->getShortVersion()); // Load language string in JavaScript JText::script('COM_CROWDFUNDING_QUESTION_LAUNCH_PROJECT'); JText::script('COM_CROWDFUNDING_QUESTION_STOP_PROJECT'); break; case 'extras': JHtml::_('Prism.ui.serializeJson'); break; default: // Basic if ($this->userId) { JHtml::_('Prism.ui.bootstrapMaxLength'); JHtml::_('Prism.ui.bootstrap3Typeahead'); JHtml::_('Prism.ui.parsley'); JHtml::_('Prism.ui.cropper'); JHtml::_('Prism.ui.fileupload'); JHtml::_('Prism.ui.pnotify'); JHtml::_('Prism.ui.joomlaHelper'); $this->document->addScript('media/' . $this->option . '/js/site/project_basic.js?v=' . $version->getShortVersion()); // Load language string in JavaScript JText::script('COM_CROWDFUNDING_QUESTION_REMOVE_IMAGE'); // Provide image size. $js = ' var cfImageWidth = ' . $this->params->get('image_width', 200) . '; var cfImageHeight = ' . $this->params->get('image_height', 200) . '; '; $this->document->addScriptDeclaration($js); } break; } }