/** * Display an input field for amount. * * @param float $value * @param Crowdfunding\Amount $amount * @param array $options * * @return string */ public static function inputAmount($value, Crowdfunding\Amount $amount, $options) { $currency = $amount->getCurrency(); $symbol = $currency->getSymbol(); $currencyCode = $currency->getCode(); $html = '<div class="input-group">'; if ($symbol) { $html .= '<div class="input-group-addon">' . $symbol . '</div>'; } $name = Joomla\Utilities\ArrayHelper::getValue($options, 'name'); $id = ''; if (Joomla\Utilities\ArrayHelper::getValue($options, 'id')) { $id = 'id="' . Joomla\Utilities\ArrayHelper::getValue($options, 'id') . '"'; } $class = 'class="form-control '; if (Joomla\Utilities\ArrayHelper::getValue($options, 'class')) { $class .= Joomla\Utilities\ArrayHelper::getValue($options, 'class'); } $class .= '"'; if (!$value or !is_numeric($value)) { $value = 0; } $html .= '<input type="text" name="' . $name . '" value="' . $amount->setValue($value)->format() . '" ' . $id . ' ' . $class . ' />'; if ($currencyCode) { $html .= '<div class="input-group-addon">' . $currencyCode . '</div>'; } $html .= '</div>'; return $html; }
/** * @param int $projectId * @param Joomla\Registry\Registry $params * @param object $paymentSession * * @return stdClass * @throws UnexpectedValueException */ public function prepareItem($projectId, $params, $paymentSession) { $project = new Crowdfunding\Project(JFactory::getDbo()); $project->load($projectId); if (!$project->getId()) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT")); } if ($project->isCompleted()) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_COMPLETED_PROJECT")); } // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Create amount object. $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); $item = new stdClass(); $item->id = $project->getId(); $item->title = $project->getTitle(); $item->slug = $project->getSlug(); $item->catslug = $project->getCatSlug(); $item->rewardId = $paymentSession->rewardId; $item->starting_date = $project->getFundingStart(); $item->ending_date = $project->getFundingEnd(); $item->amount = $paymentSession->amount; $item->currencyCode = $currency->getCode(); $item->amountFormated = $amount->setValue($item->amount)->format(); $item->amountCurrency = $amount->setValue($item->amount)->formatCurrency(); return $item; }
/** * 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 object $item A project data. * @param Crowdfunding\Amount $amount An amount object. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|string */ public function onBeforePaymentAuthorize($context, &$item, &$amount, &$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="glyphicon glyphicon-warning-sign"></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 = $amount->setValue($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="glyphicon glyphicon-warning-sign"></span>'; $html[] = JText::sprintf("PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_CONTRIBUTION_AMOUNT_S", $amount->setValue($allowedContributedAmount)->formatCurrency()); $html[] = '</p>'; } // Verify the number of payments per project. $allowedPaymentsPerProject = (int) $componentParams->get("protection_payments_per_project"); if (!empty($allowedPaymentsPerProject)) { $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="glyphicon glyphicon-warning-sign"></span>'; $html[] = JText::sprintf("PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_PAYMENT_PER_PROJECT_D", $allowedPaymentsPerProject); $html[] = '</p>'; } } return !empty($html) ? implode("\n", $html) : null; }
/** * Method to get the field input markup. * * @return string The field input markup. * * @since 11.1 */ protected function getInput() { // Initialize some field attributes. $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : ''; $readonly = (string) $this->element['readonly'] == 'true' ? ' readonly="readonly"' : ''; $disabled = (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : ''; $class = !empty($this->element['class']) ? ' class="' . (string) $this->element['class'] . '"' : ""; $required = $this->required ? ' required aria-required="true"' : ''; $cssLayout = $this->element['css_layout'] ? $this->element['css_layout'] : "Bootstrap 2"; // Initialize JavaScript field attributes. $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Prepare amount object. $amount = new Crowdfunding\Amount($params, $this->value); $amount->setCurrency($currency); switch ($cssLayout) { case "Bootstrap 3": $html = array(); $html[] = '<div class="input-group">'; if ($currency->getSymbol()) { // Prepended $html[] = '<div class="input-group-addon">' . $currency->getSymbol() . '</div>'; } $html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . $amount->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>'; // Prepend $html[] = '<div class="input-group-addon">' . $currency->getCode() . '</div>'; $html[] = '</div>'; break; default: // Bootstrap 2 $html = array(); if ($currency->getSymbol()) { // Prepended $html[] = '<div class="input-prepend input-append"><span class="add-on">' . $currency->getSymbol() . '</span>'; } else { // Append $html[] = '<div class="input-append">'; } $html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . $amount->format() . '"' . $class . $size . $disabled . $readonly . $maxLength . $onchange . $required . '/>'; // Appended $html[] = '<span class="add-on">' . $currency->getCode() . '</span></div>'; break; } return implode("\n", $html); }
public function validate($data) { if (empty($data) or !is_array($data)) { throw new InvalidArgumentException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REWARDS")); } $filter = JFilterInput::getInstance(); $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Create a currency object. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Create the object "amount". $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); foreach ($data as $key => $item) { $item["amount"] = $amount->setValue($item["amount"])->parse(); // Filter data if (!is_numeric($item["amount"])) { $item["amount"] = 0; } $item["title"] = $filter->clean($item["title"], "string"); $item["title"] = Joomla\String\String::trim($item["title"]); $item["title"] = Joomla\String\String::substr($item["title"], 0, 128); $item["description"] = $filter->clean($item["description"], "string"); $item["description"] = Joomla\String\String::trim($item["description"]); $item["description"] = Joomla\String\String::substr($item["description"], 0, 500); $item["number"] = (int) $item["number"]; $item["delivery"] = Joomla\String\String::trim($item["delivery"]); $item["delivery"] = $filter->clean($item["delivery"], "string"); if (!empty($item["delivery"])) { $date = new JDate($item["delivery"]); $unixTime = $date->toUnix(); if ($unixTime < 0) { $item["delivery"] = ""; } } if (!$item["title"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_TITLE")); } if (!$item["description"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION")); } if (!$item["amount"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT")); } $data[$key] = $item; } return $data; }
public function validate($data) { if (!is_array($data) or count($data) === 0) { throw new InvalidArgumentException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARDS')); } $filter = JFilterInput::getInstance(); $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ // Create a currency object. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get('project_currency')); // Create the object 'amount'. $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); foreach ($data as $key => &$item) { $item['amount'] = $amount->setValue($item['amount'])->parse(); // Filter data if (!is_numeric($item['amount'])) { $item['amount'] = 0; } $item['title'] = $filter->clean($item['title'], 'string'); $item['title'] = JString::trim($item['title']); $item['title'] = JString::substr($item['title'], 0, 128); $item['description'] = $filter->clean($item['description'], 'string'); $item['description'] = JString::trim($item['description']); $item['description'] = JString::substr($item['description'], 0, 500); $item['number'] = (int) $item['number']; $item['delivery'] = JString::trim($item['delivery']); $item['delivery'] = $filter->clean($item['delivery'], 'string'); if (!empty($item['delivery'])) { $date = new JDate($item['delivery']); $unixTime = $date->toUnix(); if ($unixTime < 0) { $item['delivery'] = ''; } } if (!$item['title']) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TITLE')); } if (!$item['description']) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION')); } if (!$item['amount']) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_AMOUNT')); } } unset($item); return $data; }
protected function preparePayment(&$paymentSession) { // If missing the flag "step1", redirect to first step. if (!$paymentSession->step1) { $this->returnToStep1($paymentSession, JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT")); } // Check for both user states. The user must have only one state - registered user or anonymous user. $userId = JFactory::getUser()->get("id"); $aUserId = $this->app->getUserState("auser_id"); if (!empty($userId) and !empty($aUserId) or empty($userId) and empty($aUserId)) { // Reset anonymous hash user ID and redirect to first step. $this->app->setUserState("auser_id", ""); $this->returnToStep1($paymentSession); } if (!$this->item->days_left) { $this->returnToStep1($paymentSession, JText::_("COM_CROWDFUNDING_ERROR_PROJECT_COMPLETED")); } // Validate reward $this->reward = null; $keys = array("id" => $paymentSession->rewardId, "project_id" => $this->item->id); $this->reward = new Crowdfunding\Reward(JFactory::getDbo()); $this->reward->load($keys); if ($this->reward->getId()) { if ($this->reward->isLimited() and !$this->reward->getAvailable()) { $this->returnToStep1($paymentSession, JText::_("COM_CROWDFUNDING_ERROR_REWARD_NOT_AVAILABLE")); } } // Set the amount that will be displayed in the view. $this->paymentAmount = $paymentSession->amount; // Validate the amount. if (!$this->paymentAmount) { $this->returnToStep1($paymentSession, JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT")); } // Events $item = new stdClass(); $item->id = $this->item->id; $item->title = $this->item->title; $item->slug = $this->item->slug; $item->catslug = $this->item->catslug; $item->rewardId = $paymentSession->rewardId; $item->amount = $paymentSession->amount; $item->currencyCode = $this->currency->getCode(); $item->amountFormated = $this->amount->setValue($item->amount)->format(); $item->amountCurrency = $this->amount->setValue($item->amount)->formatCurrency(); $this->item->event = new stdClass(); // onBeforePaymentAuthorize JPluginHelper::importPlugin('crowdfundingpayment'); $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onBeforePaymentAuthorize', array('com_crowdfunding.before.payment.authorize', &$item, &$this->amount, &$this->params)); if (!empty($results)) { $this->item->event->onBeforePaymentAuthorize = trim(implode("\n", $results)); } else { // onProjectPayment $results = $dispatcher->trigger('onProjectPayment', array('com_crowdfunding.payment', &$item, &$this->params)); $this->item->event->onProjectPayment = trim(implode("\n", $results)); } }
return; } // Get project $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId); if (!$project->getId()) { return; } // Get component params $componentParams = JComponentHelper::getParams('com_crowdfunding'); /** @var $componentParams Joomla\Registry\Registry */ $socialPlatform = $componentParams->get('integration_social_platform'); $imageFolder = $componentParams->get('images_directory', 'images/crowdfunding'); $imageWidth = $componentParams->get('image_width', 200); $imageHeight = $componentParams->get('image_height', 200); // Get currency $currencyId = $componentParams->get('project_currency'); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $componentParams->get('project_currency')); $amount = new Crowdfunding\Amount($componentParams); $amount->setCurrency($currency); // Get social platform and a link to the profile $socialBuilder = new Prism\Integration\Profile\Builder(array('social_platform' => $socialPlatform, 'user_id' => $project->getUserId())); $socialBuilder->build(); $socialProfile = $socialBuilder->getProfile(); $socialProfileLink = !$socialProfile ? null : $socialProfile->getLink(); // Get amounts $fundedAmount = $amount->setValue($project->getGoal())->formatCurrency(); $raised = $amount->setValue($project->getFunded())->formatCurrency(); // Prepare the value that I am going to display $fundedPercents = JHtml::_('crowdfunding.funded', $project->getFundedPercent()); $user = JFactory::getUser($project->getUserId()); require JModuleHelper::getLayoutPath('mod_crowdfundingdetails', $params->get('layout', 'default'));
/** * Calculate the fee that the site owner is going to receive. * * @param array $data * @param Crowdfunding\Amount $amount * @param string $title * * @return string */ public static function ownerMissedAmount($data, $amount, $title) { // Get the data from the aggregated list. $canceled = JArrayHelper::getValue($data, "canceled", array(), "array"); $failed = JArrayHelper::getValue($data, "failed", array(), "array"); $refunded = JArrayHelper::getValue($data, "refunded", array(), "array"); $canceledAmount = JArrayHelper::getValue($canceled, "amount", 0, "float"); $failedAmount = JArrayHelper::getValue($failed, "amount", 0, "float"); $refundedAmount = JArrayHelper::getValue($refunded, "amount", 0, "float"); $html[] = $amount->setValue($canceledAmount + $failedAmount + $refundedAmount)->formatCurrency(); $html[] = '<a class="btn btn-mini hasTooltip" href="javascript:void(0);" title="' . htmlentities($title, ENT_QUOTES, "UTF-8") . '">'; $html[] = '<i class="icon-info"></i>'; $html[] = '</a>'; return implode("\n", $html); }
/** * Generates information about transaction amount. * * @param object $item * @param Crowdfunding\Amount $amount * @param Crowdfunding\Currencies $currencies * * @return string */ public static function transactionAmount($item, $amount, $currencies) { $item->txn_amount = floatval($item->txn_amount); $item->fee = floatval($item->fee); $currency = null; if ($currencies instanceof Crowdfunding\Currencies) { $currency = $currencies->getCurrencyByCode($item->txn_currency); } if ($currency instanceof Crowdfunding\Currency) { $amount->setCurrency($currency); $output = $amount->setValue($item->txn_amount)->formatCurrency(); } else { $output = $item->txn_amount; } if (!empty($item->fee)) { $fee = $currency instanceof Crowdfunding\Currency ? $amount->setValue($item->fee)->formatCurrency() : $item->fee; // Prepare project owner amount. $projectOwnerAmount = round($item->txn_amount - $item->fee, 2); $projectOwnerAmount = !empty($currency) ? $amount->setValue($projectOwnerAmount)->formatCurrency() : $projectOwnerAmount; $title = JText::sprintf("COM_CROWDFUNDING_TRANSACTION_AMOUNT_FEE", $projectOwnerAmount, $fee); $output .= '<a class="btn btn-micro hasTooltip" href="javascript:void(0);" title="' . addslashes($title) . '">'; $output .= '<i class="icon-question"></i>'; $output .= '</a>'; } return $output; }
// If option is not 'com_crowdfunding' and view is not 'details', // do not display anything. if (strcmp($option, 'com_crowdfunding') !== 0 or strcmp($view, 'details') !== 0) { echo JText::_('MOD_CROWDFUNDINGREWARDS_ERROR_INVALID_VIEW'); return; } $projectId = $app->input->getUint('id'); if (!$projectId) { echo JText::_('MOD_CROWDFUNDINGREWARDS_ERROR_INVALID_PROJECT'); return; } $componentParams = JComponentHelper::getParams('com_crowdfunding'); /** @var $componentParams Joomla\Registry\Registry */ // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $componentParams->get('project_currency')); $amount = new Crowdfunding\Amount($componentParams); $amount->setCurrency($currency); $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId); $rewards = $project->getRewards(array('state' => Prism\Constants::PUBLISHED, 'order_by' => 'ordering', 'order_direction' => 'ASC')); // Calculate the number of funders. if ($params->get('display_funders', 0)) { $rewards->countReceivers(); } $additionalInfo = false; if ($params->get('display_funders', 0) or $params->get('display_claimed', 0) or $params->get('display_delivery_date', 0)) { $additionalInfo = true; } $layout = $params->get('layout', 'default'); switch ($layout) { case '_:square': case '_:thumbnail':
/** * Prepare an amount, parsing it from formatted string to decimal value. * This is most used when a user post a data via form. * * @param float $value * * @return string|float */ public static function parseAmount($value) { $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Parse the goal amount. $amount = new Crowdfunding\Amount($params, $value); $amount->setCurrency($currency); return $amount->parse(); }
public function getStatistics($project) { $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); $amount = new Crowdfunding\Amount($params, $project->funded); $amount->setCurrency($currency); $projectData = CrowdfundingHelper::getProjectData($project->id); $html = array(); $html[] = '<div class="panel panel-default">'; $html[] = '<div class="panel-heading"><h5>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_STATISTICS") . '</h5></div>'; $html[] = ' <table class="table table-bordered">'; // Hits $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_HITS") . '</td>'; $html[] = ' <td>' . (int) $project->hits . '</td>'; $html[] = ' </tr>'; // Updates $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_UPDATES") . '</td>'; $html[] = ' <td>' . JArrayHelper::getValue($projectData, "updates", 0, "integer") . '</td>'; $html[] = ' </tr>'; // Comments $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_COMMENTS") . '</td>'; $html[] = ' <td>' . JArrayHelper::getValue($projectData, "comments", 0, "integer") . '</td>'; $html[] = ' </tr>'; // Funders $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_FUNDERS") . '</td>'; $html[] = ' <td>' . JArrayHelper::getValue($projectData, "funders", 0, "integer") . '</td>'; $html[] = ' </tr>'; // Raised $html[] = ' <tr>'; $html[] = ' <td>' . JText::_("PLG_CONTENT_CROWDFUNDINGMANAGER_RAISED") . '</td>'; $html[] = ' <td>' . $amount->formatCurrency() . '</td>'; $html[] = ' </tr>'; $html[] = ' </table>'; $html[] = '</div>'; return implode("\n", $html); }