/** * @param int $projectId * @param Joomla\Registry\Registry $params * @param stdClass $paymentSession * * @throws UnexpectedValueException * @throws InvalidArgumentException * @throws OutOfBoundsException * @throws RuntimeException * * @return stdClass */ public function prepareItem($projectId, $params, $paymentSession) { $container = Prism\Container::getContainer(); $containerHelper = new Crowdfunding\Container\Helper(); $project = $containerHelper->fetchProject($container, $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 $money = $containerHelper->fetchMoneyFormatter($container, $params); $currency = $money->getCurrency(); $item = new stdClass(); $item->id = $project->getId(); $item->title = $project->getTitle(); $item->slug = $project->getSlug(); $item->catslug = $project->getCatSlug(); $item->starting_date = $project->getFundingStart(); $item->ending_date = $project->getFundingEnd(); $item->user_id = $project->getUserId(); $item->rewardId = $paymentSession->rewardId; $item->amount = $paymentSession->amount; $item->currencyCode = $currency->getCode(); $item->amountFormated = $money->setAmount($item->amount)->format(); $item->amountCurrency = $money->setAmount($item->amount)->formatCurrency(); return $item; }
/** * Method to get the field input markup. * * @return string The field input markup. * * @throws \RuntimeException * @throws \InvalidArgumentException * @throws \OutOfBoundsException */ 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 = !empty($this->element['css_layout']) ? (string) $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 */ // Get the currency and money formatter from the container. $container = Prism\Container::getContainer(); $containerHelper = new Crowdfunding\Container\Helper(); $moneyFormatter = $containerHelper->fetchMoneyFormatter($container, $params); $moneyFormatter->setAmount($this->value); $currency = $moneyFormatter->getCurrency(); $html = array(); if ($cssLayout === 'Bootstrap 3') { $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="' . $moneyFormatter->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>'; // Prepend $html[] = '<div class="input-group-addon">' . $currency->getCode() . '</div>'; $html[] = '</div>'; } else { // Bootstrap 2 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="' . $moneyFormatter->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>'; // Appended $html[] = '<span class="add-on">' . $currency->getCode() . '</span></div>'; } return implode("\n", $html); }
/** * 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 * * @throws \InvalidArgumentException * @throws \OutOfBoundsException * @throws \RuntimeException * @throws \UnexpectedValueException * * @return null|stdClass */ 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 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 = 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? $gateway = 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 = trim($this->params->get('paypal_sandbox_url', 'https://www.sandbox.paypal.com/cgi-bin/webscr')); } else { $url = 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. $paymentResult = new stdClass(); $paymentResult->project = null; $paymentResult->reward = null; $paymentResult->transaction = null; $paymentResult->paymentSession = null; $paymentResult->serviceProvider = $this->serviceProvider; $paymentResult->serviceAlias = $this->serviceAlias; if ($paypalIpn->isVerified()) { $containerHelper = new Crowdfunding\Container\Helper(); $currency = $containerHelper->fetchCurrency($this->container, $params); // Get payment session data $paymentSessionId = ArrayHelper::getValue($custom, 'payment_session_id', 0, 'int'); $paymentSessionRemote = $this->getPaymentSession(array('id' => $paymentSessionId)); // Check for valid payment session. if (!$paymentSessionRemote->getId()) { $this->log->add(JText::_($this->textPrefix . '_ERROR_PAYMENT_SESSION'), $this->errorType, $paymentSessionRemote->getProperties()); return null; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_PAYMENT_SESSION'), $this->debugType, $paymentSessionRemote->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_POST, $currency->getCode(), $paymentSessionRemote); if ($validData === null) { return null; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_VALID_DATA'), $this->debugType, $validData) : null; // Set the receiver ID. $project = $containerHelper->fetchProject($this->container, $validData['project_id']); $validData['receiver_id'] = $project->getUserId(); // Get reward object. $reward = null; if ($validData['reward_id']) { $reward = $containerHelper->fetchReward($this->container, $validData['reward_id'], $project->getId()); } // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data $transaction = $this->storeTransaction($validData); if ($transaction === null) { return null; } // Generate object of data, based on the transaction properties. $paymentResult->transaction = $transaction; // Generate object of data based on the project properties. $paymentResult->project = $project; // Generate object of data based on the reward properties. if ($reward !== null and $reward instanceof Crowdfunding\Reward) { $paymentResult->reward = $reward; } // Generate data object, based on the payment session properties. $paymentResult->paymentSession = $paymentSessionRemote; // Removing intention. $this->removeIntention($paymentSessionRemote, $transaction); } 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 $paymentResult; }
$option = $app->input->get('option'); $view = $app->input->get('view'); $allowedViews = array('backing', 'embed', 'report', 'friendmail'); // 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; } $container = Prism\Container::getContainer(); /** @var $container Joomla\DI\Container */ $containerHelper = new Crowdfunding\Container\Helper(); // Get Project object from the container. $project = $containerHelper->fetchProject($container, $projectId); if (!$project->getId()) { return; } // Get component params $componentParams = JComponentHelper::getParams('com_crowdfunding'); /** @var $componentParams Joomla\Registry\Registry */ $money = $containerHelper->fetchMoneyFormatter($container, $componentParams); $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 social platform and a link to the profile $config = new Joomla\Registry\Registry(array('platform' => $socialPlatform, 'user_id' => $project->getUserId()));
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; } $container = Prism\Container::getContainer(); /** @var $container Joomla\DI\Container */ $containerHelper = new Crowdfunding\Container\Helper(); // Get Project object from the container. $project = $containerHelper->fetchProject($container, $projectId); $type = $project->getType(); if ($type === null) { return true; } return (bool) ($type instanceof Crowdfunding\Type and $type->isRewardsEnabled()); }