コード例 #1
0
ファイル: notifier.php プロジェクト: phpsource/CrowdFunding
 /**
  * Remove a record of payment session from the database.
  *
  * @param object $session
  */
 public function closePaymentSession($session)
 {
     if (!empty($session->id)) {
         jimport("crowdfunding.intention");
         $intention = new CrowdFundingIntention(JFactory::getDbo());
         $intention->setId($session->id);
         $intention->delete();
     }
 }
コード例 #2
0
ファイル: backing.php プロジェクト: phpsource/CrowdFunding
 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));
 }
コード例 #3
0
ファイル: plugin.php プロジェクト: phpsource/CrowdFunding
 /**
  * This method returns intention
  * based on user ID or anonymous hash user ID.
  *
  * @param array  $options   The keys used to load data of the intention from database.
  *
  * @throws UnexpectedValueException
  *
  * @return CrowdFundingIntention
  */
 public function getIntention(array $options)
 {
     $userId = JArrayHelper::getValue($options, "user_id");
     $aUserId = JArrayHelper::getValue($options, "auser_id");
     $projectId = JArrayHelper::getValue($options, "project_id");
     $token = JArrayHelper::getValue($options, "token");
     $txnId = JArrayHelper::getValue($options, "txn_id");
     // Prepare keys for anonymous user.
     if (!empty($aUserId)) {
         $intentionKeys = array("auser_id" => $aUserId, "project_id" => $projectId);
     } elseif (!empty($userId)) {
         // Prepare keys for registered user.
         $intentionKeys = array("user_id" => $userId, "project_id" => $projectId);
     } elseif (!empty($token)) {
         // Prepare keys for token.
         $intentionKeys = array("token" => $token);
     } elseif (!empty($txnId)) {
         // Prepare keys for transaction ID.
         $intentionKeys = array("txn_id" => $txnId);
     } else {
         throw new UnexpectedValueException(JText::_("LIB_CROWDFUNDING_INVALID_INTENTION_KEYS"));
     }
     jimport("crowdfunding.intention");
     $intention = new CrowdFundingIntention(JFactory::getDbo());
     $intention->load($intentionKeys);
     return $intention;
 }
コード例 #4
0
ファイル: paypal.php プロジェクト: phpsource/CrowdFunding
 /**
  * Remove an intention record or create a payment session record.
  *
  * @param CrowdFundingIntention|CrowdFundingPaymentSession $intention
  * @param string                                           $txnStatus
  */
 protected function removeIntention($intention, $txnStatus)
 {
     // If status is NOT completed create a payment session.
     if (strcmp("completed", $txnStatus) != 0) {
         // If intention object is instance of CrowdFundingIntention,
         // create a payment session record and remove intention record.
         // If it is NOT instance of CrowdFundingIntention, do NOT remove the recrod,
         // because it will be used again when PayPal sends a response with status "completed".
         if ($intention instanceof CrowdFundingIntention) {
             jimport("crowdfunding.payment.session");
             $paymentSession = new CrowdFundingPaymentSession(JFactory::getDbo());
             $paymentSession->setUserId($intention->getUserId())->setAnonymousUserId($intention->getAnonymousUserId())->setProjectId($intention->getProjectId())->setRewardId($intention->getRewardId())->setRecordDate($intention->getRecordDate())->setTransactionId($intention->getTransactionId())->setGateway($intention->getGateway())->setIntentionId($intention->getId())->setToken($intention->getToken());
             $paymentSession->store();
             // DEBUG DATA
             JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYMENT_SESSION"), $this->debugType, $paymentSession->getProperties()) : null;
             // Remove intention object.
             $intention->delete();
         }
         // If transaction status is completed, remove intention record.
     } elseif (strcmp("completed", $txnStatus) == 0) {
         $intention->delete();
     }
 }