public function onAfterDispatch()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     if ($app->isAdmin()) {
         return;
     }
     $document = JFactory::getDocument();
     /** @var $document JDocumentHtml */
     $type = $document->getType();
     if (strcmp("html", $type) != 0) {
         return;
     }
     // It works only for GET and POST requests.
     $method = JString::strtolower($app->input->getMethod());
     if (!in_array($method, array("get", "post"))) {
         return;
     }
     // Check component enabled
     if (!JComponentHelper::isEnabled('com_crowdfunding', true)) {
         return;
     }
     $view = $app->input->getCmd("view");
     $option = $app->input->getCmd("option");
     $isCrowdfundingComponent = strcmp($option, "com_crowdfunding") == 0;
     $isDetailsPage = (strcmp($option, "com_crowdfunding") == 0 and strcmp($view, "details") == 0);
     // Allowed views for the module Crowdfunding Details
     $allowedViewsModuleDetails = array("backing", "embed", "report");
     $allowedViewsModuleFilters = array("discover", "category");
     // Hide some modules if it is not details page.
     if (!$isDetailsPage) {
         $this->hideModule("mod_crowdfundinginfo");
         $this->hideModule("mod_crowdfundingprofile");
         $this->hideModule("mod_crowdfundingreporting");
     }
     // Module Crowdfunding Rewards (mod_crowdfundingrewards).
     if (!$isDetailsPage) {
         $this->hideModule("mod_crowdfundingrewards");
     } else {
         // Check project type. If the rewards are disable, hide the module.
         $projectId = $app->input->getInt("id");
         if (!empty($projectId)) {
             $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId);
             $type = $project->getType();
             // Hide the module Crowdfunding Rewards, if rewards are disabled for this type.
             if (!is_null($type) and !$type->isRewardsEnabled()) {
                 $this->hideModule("mod_crowdfundingrewards");
             }
         }
     }
     // Module Crowdfunding Details (mod_crowdfundingdetails) on backing and embed pages.
     if (!$isCrowdfundingComponent or strcmp($option, "com_crowdfunding") == 0 and !in_array($view, $allowedViewsModuleDetails)) {
         $this->hideModule("mod_crowdfundingdetails");
     }
     // Module Crowdfunding Filters (mod_crowdfundingfilters).
     if (!$isCrowdfundingComponent or strcmp($option, "com_crowdfunding") == 0 and !in_array($view, $allowedViewsModuleFilters)) {
         $this->hideModule("mod_crowdfundingfilters");
     }
 }
 public function send()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     // Get the data from the form POST
     $data = $this->input->post->get('cfreport', array(), 'array');
     $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'id');
     if (!$itemId) {
         $redirectOptions = array('force_direction' => CrowdfundingHelperRoute::getReportRoute());
         $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions);
         return;
     }
     // Get project
     $item = Crowdfunding\Project::getInstance(JFactory::getDbo(), $itemId);
     $redirectOptions = array('force_direction' => CrowdfundingHelperRoute::getReportRoute($item->getId()));
     $model = $this->getModel();
     /** @var $model CrowdfundingModelReport */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED'));
     }
     // Test if the data is valid.
     $validData = $model->validate($form, $data);
     // Check for validation errors.
     if ($validData === false) {
         $errors = $form->getErrors();
         $error = array_shift($errors);
         $msg = $error->getMessage();
         $this->displayNotice($msg, $redirectOptions);
         return;
     }
     try {
         $userId = (int) JFactory::getUser()->get('id');
         if ($userId > 0) {
             $validData['user_id'] = $userId;
         }
         $model->save($validData);
     } catch (RuntimeException $e) {
         $this->displayNotice($e->getMessage(), $redirectOptions);
         return;
     } catch (Exception $e) {
         JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding');
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'));
     }
     // Redirect to next page
     $this->displayMessage(JText::_('COM_CROWDFUNDING_REPORT_SENT_SUCCESSFULLY'), $redirectOptions);
 }
 public function save($key = null, $urlVar = null)
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $userId = (int) JFactory::getUser()->get('id');
     if (!$userId) {
         $redirectOptions = array('force_direction' => 'index.php?option=com_users&view=login');
         $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions);
         return;
     }
     // Get the data from the form POST
     $data = $this->input->post->get('jform', array(), 'array');
     $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'project_id', 0, 'int');
     // Get project
     $item = Crowdfunding\Project::getInstance(JFactory::getDbo(), $itemId);
     $redirectOptions = array('force_direction' => CrowdfundingHelperRoute::getDetailsRoute($item->getSlug(), $item->getCatSlug(), 'updates'));
     // Check for valid owner.
     if ($userId !== $item->getUserId()) {
         $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions);
         return;
     }
     $model = $this->getModel();
     /** @var $model CrowdfundingModelUpdate */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED'));
     }
     // Test if the data is valid.
     $validData = $model->validate($form, $data);
     // Check for validation errors.
     if ($validData === false) {
         $errors = $form->getErrors();
         $error = array_shift($errors);
         $msg = $error->getMessage();
         $this->displayNotice($msg, $redirectOptions);
         return;
     }
     try {
         $model->save($validData);
     } catch (Exception $e) {
         JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding');
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'));
     }
     // Redirect to next page
     $this->displayMessage(JText::_('COM_CROWDFUNDING_UPDATE_SUCCESSFULLY_SAVED'), $redirectOptions);
 }
 public function send()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $redirectOptions = array("view" => "discover");
     $params = JComponentHelper::getParams("com_crowdfunding");
     /** @var  $params Joomla\Registry\Registry */
     if (!$params->get("security_display_friend_form", 0)) {
         $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_CANT_SEND_MAIL'), $redirectOptions);
         return;
     }
     // Get the data from the form POST
     $data = $this->input->post->get('jform', array(), 'array');
     $itemId = Joomla\Utilities\ArrayHelper::getValue($data, "id", 0, "uint");
     // Get project
     $item = Crowdfunding\Project::getInstance(JFactory::getDbo(), $itemId);
     // Prepare redirect link
     $link = CrowdfundingHelperRoute::getEmbedRoute($item->getSlug(), $item->getCatSlug(), "email");
     $redirectOptions = array("force_direction" => $link);
     $model = $this->getModel();
     /** @var $model CrowdfundingModelFriendMail */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED"));
     }
     // Test if the data is valid.
     $validData = $model->validate($form, $data);
     // Check for validation errors.
     if ($validData === false) {
         $this->displayNotice($form->getErrors(), $redirectOptions);
         return;
     }
     try {
         $model->send($validData);
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'));
     }
     // Redirect to next page
     $this->displayMessage(JText::_("COM_CROWDFUNDING_FRIEND_MAIL_SUCCESSFULLY_SEND"), $redirectOptions);
 }
$moduleclassSfx = htmlspecialchars($params->get('moduleclass_sfx'));
$option = $app->input->get('option');
$view = $app->input->get('view');
$allowedViews = array('backing', 'embed', 'report');
// If option is not 'com_crowdfunding' and view is not one of allowed,
// do not display anything.
if (strcmp($option, 'com_crowdfunding') !== 0 or !in_array($view, $allowedViews, true)) {
    echo JText::_('MOD_CROWDFUNDINGDETAILS_ERROR_INVALID_VIEW');
    return;
}
$projectId = $app->input->getInt('id');
if (!$projectId) {
    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);
Exemple #6
0
 /**
  * Store the temporary images to project record.
  * Remove the old images and move the new ones from temporary folder to the images folder.
  *
  * @param int $projectId
  * @param array $images The names of the pictures.
  * @param string $source Path to the temporary folder.
  */
 public function updateImages($projectId, $images, $source)
 {
     $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId);
     if (!$project->getId()) {
         throw new InvalidArgumentException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT"));
     }
     // Prepare the path to the pictures.
     $fileImage = $source . DIRECTORY_SEPARATOR . $images["image"];
     $fileSmall = $source . DIRECTORY_SEPARATOR . $images["image_small"];
     $fileSquare = $source . DIRECTORY_SEPARATOR . $images["image_square"];
     if (is_file($fileImage) and is_file($fileSmall) and is_file($fileSquare)) {
         // Get the folder where the pictures are stored.
         $imagesFolder = CrowdfundingHelper::getImagesFolder();
         // Remove an image from the filesystem
         $oldFileImage = $imagesFolder . DIRECTORY_SEPARATOR . $project->getImage();
         $oldFileSmall = $imagesFolder . DIRECTORY_SEPARATOR . $project->getSmallImage();
         $oldFileSquare = $imagesFolder . DIRECTORY_SEPARATOR . $project->getSquareImage();
         if (is_file($oldFileImage)) {
             JFile::delete($oldFileImage);
         }
         if (is_file($oldFileSmall)) {
             JFile::delete($oldFileSmall);
         }
         if (is_file($oldFileSquare)) {
             JFile::delete($oldFileSquare);
         }
         // Move the new files to the images folder.
         $newFileImage = $imagesFolder . DIRECTORY_SEPARATOR . $images["image"];
         $newFileSmall = $imagesFolder . DIRECTORY_SEPARATOR . $images["image_small"];
         $newFileSquare = $imagesFolder . DIRECTORY_SEPARATOR . $images["image_square"];
         JFile::move($fileImage, $newFileImage);
         JFile::move($fileSmall, $newFileSmall);
         JFile::move($fileSquare, $newFileSquare);
         // Store the newest pictures.
         $project->bind($images);
         $project->store();
     }
 }
 public static function isRewardsEnabled($projectId)
 {
     // Check for enabled rewards by component options.
     $componentParams = JComponentHelper::getParams('com_crowdfunding');
     if (!$componentParams->get('rewards_enabled', 1)) {
         return false;
     }
     // Check for enabled rewards by project type.
     $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId);
     $type = $project->getType();
     if ($type === null) {
         return true;
     }
     return (bool) ($type instanceof Crowdfunding\Type and $type->isRewardsEnabled());
 }
 protected function sendReportMail($report, $emailId)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Send mail to the administrator
     if (!$emailId) {
         return false;
     }
     // Get website
     $uri = JUri::getInstance();
     $website = $uri->toString(array('scheme', 'host'));
     $emailMode = $this->params->get('email_mode', 'plain');
     // Get project
     $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $report->project_id);
     // Prepare data for parsing
     $data = array('site_name' => $app->get('sitename'), 'site_url' => JUri::root(), 'item_title' => $project->getTitle(), 'item_url' => $website . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($project->getSlug(), $project->getCatSlug())), 'report_subject' => $report->subject, 'report_description' => $report->description);
     $email = new Emailtemplates\Email();
     $email->setDb(JFactory::getDbo());
     $email->load($emailId);
     if (!$email->getSenderName()) {
         $email->setSenderName($app->get('fromname'));
     }
     if (!$email->getSenderEmail()) {
         $email->setSenderEmail($app->get('mailfrom'));
     }
     // Prepare recipient data.
     $componentParams = JComponentHelper::getParams('com_crowdfunding');
     /** @var  $componentParams Joomla\Registry\Registry */
     $recipientId = (int) $componentParams->get('administrator_id');
     if ($recipientId > 0) {
         $recipient = JFactory::getUser($recipientId);
         $recipientName = $recipient->get('name');
         $recipientMail = $recipient->get('email');
     } else {
         $recipientName = $app->get('fromname');
         $recipientMail = $app->get('mailfrom');
     }
     // Prepare data for parsing
     $data['sender_name'] = $email->getSenderName();
     $data['sender_email'] = $email->getSenderEmail();
     $data['recipient_name'] = $recipientName;
     $data['recipient_email'] = $recipientMail;
     $email->parse($data);
     $subject = $email->getSubject();
     $body = $email->getBody($emailMode);
     $mailer = JFactory::getMailer();
     if (strcmp('html', $emailMode) === 0) {
         // Send as HTML message
         $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
     } else {
         // Send as plain text.
         $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
     }
     // Log the error.
     if ($result !== true) {
         $this->log->add(JText::sprintf('PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_SEND_MAIL', $this->name), 'PLG_CONTENT_ADMIN_EMAIL_ERROR', JText::sprintf('PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_SEND_MAIL_NOTE', $mailer->ErrorInfo));
         return false;
     }
     return true;
 }
 /**
  * Store the temporary images to project record.
  * Remove the old images and move the new ones from temporary folder to the images folder.
  *
  * @param int    $projectId
  * @param array  $images The names of the pictures.
  * @param string $source Path to the temporary folder.
  *
  * @throws InvalidArgumentException
  */
 public function updateImages($projectId, $images, $source)
 {
     $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId);
     if (!$project->getId()) {
         throw new InvalidArgumentException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'));
     }
     // Prepare the path to the pictures.
     $fileImage = $source . DIRECTORY_SEPARATOR . $images['image'];
     $fileSmall = $source . DIRECTORY_SEPARATOR . $images['image_small'];
     $fileSquare = $source . DIRECTORY_SEPARATOR . $images['image_square'];
     if (is_file($fileImage) and is_file($fileSmall) and is_file($fileSquare)) {
         // Get the folder where the pictures are stored.
         $params = JComponentHelper::getParams('com_crowdfunding');
         /** @var $params Joomla\Registry\Registry */
         $imagesFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $params->get('images_directory', 'images/crowdfunding'));
         // Remove an image from the filesystem
         $oldFileImage = $imagesFolder . DIRECTORY_SEPARATOR . $project->getImage();
         $oldFileSmall = $imagesFolder . DIRECTORY_SEPARATOR . $project->getSmallImage();
         $oldFileSquare = $imagesFolder . DIRECTORY_SEPARATOR . $project->getSquareImage();
         if (JFile::exists($oldFileImage)) {
             JFile::delete($oldFileImage);
         }
         if (JFile::exists($oldFileSmall)) {
             JFile::delete($oldFileSmall);
         }
         if (JFile::exists($oldFileSquare)) {
             JFile::delete($oldFileSquare);
         }
         // Move the new files to the images folder.
         $newFileImage = $imagesFolder . DIRECTORY_SEPARATOR . $images['image'];
         $newFileSmall = $imagesFolder . DIRECTORY_SEPARATOR . $images['image_small'];
         $newFileSquare = $imagesFolder . DIRECTORY_SEPARATOR . $images['image_square'];
         JFile::move($fileImage, $newFileImage);
         JFile::move($fileSmall, $newFileSmall);
         JFile::move($fileSquare, $newFileSquare);
         // Store the newest pictures.
         $project->bind($images);
         $project->store();
     }
 }
 /**
  * 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;
 }
Exemple #11
0
 protected function prepareRewards()
 {
     $model = JModelLegacy::getInstance("Rewards", "CrowdfundingModel", $config = array('ignore_request' => false));
     // Get state
     $this->state = $model->getState();
     // Get params
     $this->projectId = $this->state->get("rewards.project_id");
     // Check if rewards are enabled.
     if (!$this->rewardsEnabled) {
         $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_REWARDS_DISABLED"), "notice");
         $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getFormRoute($this->projectId, "manager"), false));
         return;
     }
     $this->items = $model->getItems($this->projectId);
     // Get project and validate it
     $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $this->projectId);
     $project = $project->getProperties();
     $this->item = Joomla\Utilities\ArrayHelper::toObject($project);
     // Check if the item exists.
     if (!$this->isValid()) {
         return;
     }
     // Create a currency object.
     $this->currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency"));
     $this->amount = new Crowdfunding\Amount($this->params);
     $this->amount->setCurrency($this->currency);
     // Get date format
     $this->dateFormat = CrowdfundingHelper::getDateFormat();
     $this->dateFormatCalendar = CrowdfundingHelper::getDateFormat(true);
     $language = JFactory::getLanguage();
     $languageTag = $language->getTag();
     $js = '
         // Rewards calendar date format.
         var projectWizard = {
             dateFormat: "' . $this->dateFormatCalendar . '",
             locale: "' . substr($languageTag, 0, 2) . '"
         };
     ';
     $this->document->addScriptDeclaration($js);
     // Prepare rewards images.
     $this->rewardsImagesEnabled = $this->params->get("rewards_images", 0);
     $this->rewardsImagesUri = CrowdfundingHelper::getImagesFolderUri($this->userId);
     $this->prepareProjectType();
     $this->pathwayName = JText::_("COM_CROWDFUNDING_STEP_REWARDS");
 }
Exemple #12
0
 /**
  * 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;
 }
Exemple #13
0
 protected function prepareRewards()
 {
     $model = JModelLegacy::getInstance('Rewards', 'CrowdfundingModel', $config = array('ignore_request' => false));
     // Get state
     $this->state = $model->getState();
     // Get params
     $this->projectId = $this->state->get('rewards.project_id');
     // Check if rewards are enabled.
     if (!$this->rewardsEnabled) {
         $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_REWARDS_DISABLED'), 'notice');
         $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getFormRoute($this->projectId, 'manager'), false));
         return;
     }
     $this->items = $model->getItems($this->projectId);
     // Get project and validate it
     $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $this->projectId);
     $project = $project->getProperties();
     $this->item = Joomla\Utilities\ArrayHelper::toObject($project);
     // Check if the item exists.
     if (!CrowdfundingHelper::isAuthorized($this->userId, $this->item, 'rewards')) {
         $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_SOMETHING_WRONG'), 'notice');
         $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()));
         return;
     }
     // Create a currency object.
     $this->currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency'));
     $this->amount = new Crowdfunding\Amount($this->params);
     $this->amount->setCurrency($this->currency);
     // Get date format
     $this->dateFormat = CrowdfundingHelper::getDateFormat();
     $this->dateFormatCalendar = CrowdfundingHelper::getDateFormat(true);
     $language = JFactory::getLanguage();
     $languageTag = $language->getTag();
     $js = '
         // Rewards calendar date format.
         var projectWizard = {
             dateFormat: "' . $this->dateFormatCalendar . '",
             locale: "' . substr($languageTag, 0, 2) . '"
         };
     ';
     $this->document->addScriptDeclaration($js);
     // Prepare rewards images.
     $this->rewardsImagesEnabled = (bool) $this->params->get('rewards_images', 0);
     $this->rewardsImagesUri = CrowdfundingHelper::getImagesFolderUri($this->userId);
     $this->options['column_left'] = (!$this->rewardsImagesEnabled or count($this->items) === 0) ? 12 : 8;
     $this->options['column_right'] = (!$this->rewardsImagesEnabled or count($this->items) === 0) ? 0 : 4;
     $this->prepareProjectType();
     $this->pathwayName = JText::_('COM_CROWDFUNDING_STEP_REWARDS');
 }
 /**
  * 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;
 }
Exemple #15
0
 /**
  * Process preapproval notification data from PayPal.
  *
  * @param array $result
  * @param string $url  The parameters of the component
  * @param bool $loadCertificate
  * @param Joomla\Registry\Registry $params  The parameters of the component
  *
  * @return null|array
  */
 protected function processPreApproval(&$result, $url, $loadCertificate, &$params)
 {
     $paypalIpn = new Prism\Payment\PayPal\Ipn($url, $_POST);
     $paypalIpn->verify($loadCertificate);
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_IPN_OBJECT"), $this->debugType, $paypalIpn) : null;
     if ($paypalIpn->isVerified()) {
         // Get currency
         $currencyId = $params->get("project_currency");
         $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $currencyId, $params);
         $preApprovalKey = Joomla\Utilities\ArrayHelper::getValue($_POST, "preapproval_key");
         // Get payment session data
         $keys = array("unique_key" => $preApprovalKey);
         $paymentSession = $this->getPaymentSession($keys);
         // 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, $preApprovalKey);
         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;
             }
         }
         //  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 (!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(), "paypalIPN" => $paypalIpn, "_POST" => $_POST));
     }
     return $result;
 }