Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 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));
     }
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }
    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);
 }
Ejemplo n.º 9
0
 /**
  * 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;
 }