コード例 #1
0
ファイル: view.html.php プロジェクト: phpsource/CrowdFunding
 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));
 }