Example #1
0
 public function process()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Check for request forgeries.
     $requestMethod = $app->input->getMethod();
     if (strcmp("POST", $requestMethod) == 0) {
         JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     } else {
         JSession::checkToken("get") or jexit(JText::_('JINVALID_TOKEN'));
     }
     // Get params
     $params = JComponentHelper::getParams("com_crowdfunding");
     /** @var  $params Joomla\Registry\Registry */
     // Get the data from the form
     $itemId = $this->input->getInt('id', 0);
     $rewardId = $this->input->getInt('rid', 0);
     // Get amount
     $amount = $this->input->get("amount", 0, "float");
     // Get user ID
     $user = JFactory::getUser();
     $userId = (int) $user->get("id");
     // Anonymous user ID
     $aUserId = "";
     $model = $this->getModel();
     /** @var $model CrowdFundingModelBacking */
     // Get the item
     $item = $model->getItem($itemId);
     $returnUrl = CrowdFundingHelperRoute::getBackingRoute($item->slug, $item->catslug);
     // Authorise the user
     if (!$user->authorise("crowdfunding.donate", "com_crowdfunding")) {
         $this->setRedirect(JRoute::_($returnUrl, false), JText::_('COM_CROWDFUNDING_ERROR_NO_PERMISSIONS'), "notice");
         return;
     }
     // Check for valid project
     if (empty($item->id)) {
         $this->setRedirect(JRoute::_(CrowdFundingHelperRoute::getDiscoverRoute()), JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), "notice");
         return;
     }
     // Check for maintenance (debug) state
     if ($params->get("debug_payment_disabled", 0)) {
         $msg = JString::trim($params->get("debug_disabled_functionality_msg"));
         if (!$msg) {
             $msg = JText::_("COM_CROWDFUNDING_DEBUG_MODE_DEFAULT_MSG");
         }
         $this->setRedirect(JRoute::_($returnUrl, false), $msg, "notice");
         return;
     }
     // Check for agreed conditions from the user
     if ($params->get("backing_terms", 0)) {
         $terms = $this->input->get("terms", 0, "int");
         if (!$terms) {
             $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_TERMS_NOT_ACCEPTED"), "notice");
             return;
         }
     }
     // Check for valid amount
     if (!$amount) {
         $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice");
         return;
     }
     // Store payment process data
     // Get the payment process object and
     // store the selected data from the user.
     $paymentSessionContext = CrowdFundingConstants::PAYMENT_SESSION_CONTEXT . $item->id;
     $paymentSession = $app->getUserState($paymentSessionContext);
     $paymentSession->step1 = true;
     $paymentSession->amount = $amount;
     $paymentSession->rewardId = $rewardId;
     $app->setUserState($paymentSessionContext, $paymentSession);
     // Create an intention.
     // Generate hash user ID used for anonymous payment.
     if (!$userId) {
         $aUserId = $app->getUserState("auser_id");
         if (!$aUserId) {
             // Generate a hash ID for anonymous user.
             jimport("itprism.string");
             $anonymousUserId = new ITPrismString();
             $anonymousUserId->generateRandomString(32);
             $aUserId = (string) $anonymousUserId;
             $app->setUserState("auser_id", $aUserId);
         }
         $intentionKeys = array("auser_id" => $aUserId, "project_id" => $item->id);
     } else {
         $intentionKeys = array("user_id" => $userId, "project_id" => $item->id);
     }
     jimport("crowdfunding.intention");
     $intention = new CrowdFundingIntention(JFactory::getDbo());
     $intention->load($intentionKeys);
     $date = new JDate();
     $custom = array("user_id" => $userId, "auser_id" => $aUserId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql(), "session_id" => $paymentSession->session_id);
     $intention->bind($custom);
     $intention->store();
     // Redirect to next page
     $link = CrowdFundingHelperRoute::getBackingRoute($item->slug, $item->catslug, "payment");
     $this->setRedirect(JRoute::_($link, false));
 }
Example #2
0
 protected function preparePayment(&$paymentSession)
 {
     // If missing the flag "step1", redirect to first step.
     if (!$paymentSession->step1) {
         $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice");
         $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false));
     }
     // Check for both user states. The user must have only one state, registered or anonymous.
     $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", "");
         // Reset the flag for step 1
         $paymentSession->step1 = false;
         $this->app->setUserState($this->paymentSessionContext, $paymentSession);
         $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false));
     }
     if (!$this->item->days_left) {
         // Reset the flag for step 1
         $paymentSession->step1 = false;
         $this->app->setUserState($this->paymentSessionContext, $paymentSession);
         $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_PROJECT_COMPLETED"), "notice");
         $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false));
     }
     // Validate reward
     $this->reward = null;
     $keys = array("id" => $paymentSession->rewardId, "project_id" => $this->item->id);
     jimport("crowdfunding.reward");
     $this->reward = new CrowdFundingReward(JFactory::getDbo());
     $this->reward->load($keys);
     if ($this->reward->getId()) {
         if ($this->reward->isLimited() and !$this->reward->getAvailable()) {
             // Reset the flag for step 1
             $paymentSession->step1 = false;
             $this->app->setUserState($this->paymentSessionContext, $paymentSession);
             $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_REWARD_NOT_AVAILABLE"), "notice");
             $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false));
         }
     }
     // Validate amount
     $this->amount = $paymentSession->amount;
     if (!$this->amount) {
         // Reset the flag for step 1
         $paymentSession->step1 = false;
         $this->app->setUserState($this->paymentSessionContext, $paymentSession);
         $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice");
         $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false));
     }
     $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->getAbbr();
     // Events
     JPluginHelper::importPlugin('crowdfundingpayment');
     $dispatcher = JEventDispatcher::getInstance();
     $results = $dispatcher->trigger('onProjectPayment', array('com_crowdfunding.payment', &$item, &$this->params));
     $this->item->event = new stdClass();
     $this->item->event->onProjectPayment = trim(implode("\n", $results));
 }
Example #3
0
    ?>
    <div class="cfrewards<?php 
    echo $moduleclassSfx;
    ?>
">

        <div class="reward_title center"><?php 
    echo JText::_("MOD_CROWDFUNDINGREWARDS_PLEDGE_REWARDS");
    ?>
</div>
        <?php 
    foreach ($rewards as $reward) {
        ?>
            <div class="reward">
                <a href="<?php 
        echo JRoute::_(CrowdFundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatSlug(), "default", $reward->id));
        ?>
">
    			<span class="ramount">
    			<?php 
        $amount = $currency->getAmountString($reward->amount);
        echo JText::sprintf("MOD_CROWDFUNDINGREWARDS_INVEST_MORE", $amount);
        ?>
    			</span>
                    <span class="rtitle"><?php 
        echo htmlspecialchars($reward->title, ENT_QUOTES, "UTF-8");
        ?>
</span>
                    <span class="rdesc"><?php 
        echo htmlspecialchars($reward->description, ENT_QUOTES, "UTF-8");
        ?>
    ?>
</a>
                <?php 
}
?>
            </li>

            <li <?php 
echo $active["share"] ? 'class="active"' : '';
?>
>
                <?php 
if (!empty($displayData->paymentSession->step2)) {
    ?>
                    <a href="<?php 
    echo JRoute::_(CrowdFundingHelperRoute::getBackingRoute($displayData->item->slug, $displayData->item->catslug, "share"));
    ?>
">
                        (4) <?php 
    echo JText::_("COM_CROWDFUNDING_STEP_SHARE");
    ?>
                    </a>
                <?php 
} else {
    ?>
                    <a href="javascript: void(0);"
                       class="disabled">(4) <?php 
    echo JText::_("COM_CROWDFUNDING_STEP_SHARE");
    ?>
</a>
                <?php 
Example #5
0
if (strcmp("three_steps", $this->wizardType) == 0) {
    $layout = new JLayoutFile('payment_wizard', $this->layoutsBasePath);
} else {
    $layout = new JLayoutFile('payment_wizard_four_steps', $this->layoutsBasePath);
}
echo $layout->render($this->layoutData);
?>
	
    	</div>
	</div>
	
	<div class="row-fluid">
		<div class="span12">
			
			<form method="post" action="<?php 
echo JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug));
?>
" class="bs-docs-example cfbf" id="form-pledge" autocomplete="off">
				<fieldset>
    				<legend><?php 
echo JText::_("COM_CROWDFUNDING_ENTER_YOUR_INVESTMENT_AMOUNT");
?>
</legend>
    				<?php 
echo JHtml::_("crowdfunding.inputAmount", $this->rewardAmount, $this->currency, array("name" => "amount", "id" => "js-current-amount"));
?>
    				<?php 
if ($this->params->get("backing_terms", 0)) {
    $termsUrl = $this->params->get("backing_terms_url", "");
    ?>
    				<label class="checkbox">
Example #6
0
 /**
  * Catch a request from payment plugin via AJAX and process a transaction.
  */
 public function notifyAjax()
 {
     jimport('itprism.response.json');
     $response = new ITPrismResponseJson();
     // Check for disabled payment functionality
     if ($this->params->get("debug_payment_disabled", 0)) {
         // Log the error.
         $error = JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED") . "\n";
         $error .= JText::sprintf("COM_CROWDFUNDING_TRANSACTION_DATA", var_export($_REQUEST, true));
         $this->log->add($error, "CONTROLLER_NOTIFIER_AJAX_ERROR");
         // Send response to the browser
         $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE"))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Get model object.
     $model = $this->getModel();
     $transaction = null;
     $project = null;
     $reward = null;
     $paymentSession = null;
     $redirectUrl = null;
     $message = null;
     // Trigger the event
     try {
         // Import CrowdFunding Payment Plugins
         JPluginHelper::importPlugin('crowdfundingpayment');
         // Trigger onPaymenNotify event.
         $dispatcher = JEventDispatcher::getInstance();
         $results = $dispatcher->trigger("onPaymenNotify", array($this->context, &$this->params));
         if (!empty($results)) {
             foreach ($results as $result) {
                 if (!empty($result) and isset($result["transaction"])) {
                     $transaction = JArrayHelper::getValue($result, "transaction");
                     $project = JArrayHelper::getValue($result, "project");
                     $reward = JArrayHelper::getValue($result, "reward");
                     $paymentSession = JArrayHelper::getValue($result, "payment_session");
                     $redirectUrl = JArrayHelper::getValue($result, "redirect_url");
                     $message = JArrayHelper::getValue($result, "message");
                     break;
                 }
             }
         }
         // If there is no transaction data, the status might be pending or another one.
         // So, we have to stop the script execution.
         if (!$transaction) {
             // Remove the record of the payment session from database.
             $model->closePaymentSession($paymentSession);
             // Send response to the browser
             $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_TRANSACTION_NOT_PROCESSED_SUCCESSFULLY"))->failure();
             echo $response;
             JFactory::getApplication()->close();
         }
         // Trigger the event onAfterPayment
         $dispatcher->trigger('onAfterPayment', array($this->context, &$transaction, &$this->params, &$project, &$reward, &$paymentSession));
         // Remove the record of the payment session from database.
         $model->closePaymentSession($paymentSession);
     } catch (Exception $e) {
         // Store log data to the database.
         $this->log->add(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM"), "CONTROLLER_NOTIFIER_AJAX_ERROR", $e->getMessage());
         // Remove the record of the payment session from database.
         $model->closePaymentSession($paymentSession);
         // Send response to the browser
         $response->failure()->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM"));
         // Send notification about the error to the administrator.
         $model->sendMailToAdministrator();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Generate redirect URL
     if (!$redirectUrl) {
         $uri = JUri::getInstance();
         $redirectUrl = $uri->toString(array("scheme", "host")) . JRoute::_(CrowdFundingHelperRoute::getBackingRoute($project->slug, $project->catslug, "share"));
     }
     if (!$message) {
         $message = JText::_("COM_CROWDFUNDING_TRANSACTION_PROCESSED_SUCCESSFULLY");
     }
     // Send response to the browser
     $response->success()->setTitle(JText::_("COM_CROWDFUNDING_SUCCESS"))->setText($message)->setRedirectUrl($redirectUrl);
     echo $response;
     JFactory::getApplication()->close();
 }
Example #7
0
	<div class="well">
		<div class="cf-fund-result-state pull-center"><?php 
    echo JHtml::_("crowdfunding.resultState", $project->getFundedPercent(), $project->getFundingType());
    ?>
</div>
		<div class="cf-frss pull-center"><?php 
    echo JHtml::_("crowdfunding.resultStateText", $project->getFundedPercent(), $project->getFundingType());
    ?>
</div>
	</div>
	<?php 
} else {
    ?>
	<div class="cfinfo-funding-action">
		<a class="btn btn-large btn-block" href="<?php 
    echo JRoute::_(CrowdFundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatSlug()));
    ?>
">
            <?php 
    echo JText::_("MOD_CROWDFUNDINGINFO_INVEST_NOW");
    ?>
        </a>
	</div>
	<?php 
}
?>
    
    <div class="cfinfo-funding-type-info">
    	<?php 
$endDate = JHtml::_('crowdfunding.date', $project->getFundingEnd(), JText::_('DATE_FORMAT_LC3'));
if ("FIXED" == $project->getFundingType()) {
Example #8
0
 protected function getCancelUrl($slug, $catslug)
 {
     $page = JString::trim($this->params->get('paypal_cancel_url'));
     if (!$page) {
         $uri = JURI::getInstance();
         $page = $uri->toString(array("scheme", "host")) . JRoute::_(CrowdFundingHelperRoute::getBackingRoute($slug, $catslug, "default"), false);
     }
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_CANCEL_URL"), $this->debugType, $page) : null;
     return $page;
 }