/** * Save transaction data. * * @param array $transactionData * @param Crowdfunding\Project $project * * @return null|array */ protected function storeTransaction($transactionData, $project) { // Get transaction by txn ID $keys = array('txn_id' => Joomla\Utilities\ArrayHelper::getValue($transactionData, 'txn_id')); $transaction = new Crowdfunding\Transaction(JFactory::getDbo()); $transaction->load($keys); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_TRANSACTION_OBJECT'), $this->debugType, $transaction->getProperties()) : null; // Check for existed transaction // If the current status if completed, stop the payment process. if ($transaction->getId() and $transaction->isCompleted()) { return null; } // Add extra data. if (array_key_exists('extra_data', $transactionData)) { if (!empty($transactionData['extra_data'])) { $transaction->addExtraData($transactionData['extra_data']); } unset($transactionData['extra_data']); } // Store the new transaction data. $transaction->bind($transactionData); $transaction->store(); // If it is not completed (it might be pending or other status), // stop the process. Only completed transaction will continue // and will process the project, rewards,... if (!$transaction->isCompleted()) { return null; } // Set transaction ID. $transactionData['id'] = $transaction->getId(); // If the new transaction is completed, // update project funded amount. $amount = Joomla\Utilities\ArrayHelper::getValue($transactionData, 'txn_amount'); $project->addFunds($amount); $project->storeFunds(); return $transactionData; }
/** * Method to change state of reward. * * @throws Exception * @return void */ public function changeState() { // Check for request forgeries. JSession::checkToken('get') or jexit(JText::_('JINVALID_TOKEN')); $userId = JFactory::getUser()->get('id'); if (!$userId) { $redirectOptions = array('force_direction' => JRoute::_('index.php?option=com_users&view=login', false)); $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions); return; } $redirect = base64_decode($this->input->get('redirect')); $redirectOptions = array('force_direction' => JRoute::_($redirect, false)); $txnId = $this->input->get->getInt('txn_id'); $state = $this->input->get->getInt('state'); $state = !$state ? 0 : 1; if (!$txnId) { $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TRANSACTION'), $redirectOptions); return; } $keys = array('id' => $txnId, 'receiver_id' => $userId); /** @var $transaction Crowdfunding\Transaction */ $transaction = new Crowdfunding\Transaction(JFactory::getDbo()); $transaction->load($keys); if (!$transaction->getId()) { $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TRANSACTION'), $redirectOptions); return; } try { $transaction->updateRewardState($state); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } if (!$state) { $msg = JText::_('COM_CROWDFUNDING_REWARD_HAS_BEEN_SET_AS_NOT_SENT'); } else { $msg = JText::_('COM_CROWDFUNDING_REWARD_HAS_BEEN_SET_AS_SENT'); } $this->displayMessage($msg, $redirectOptions); }
/** * Save transaction data. * * @param array $transactionData * @param Crowdfunding\Project $project * @param string $preApprovalKey * * @return null|array */ protected function storeTransaction($transactionData, $project, $preApprovalKey) { // Get transaction by ID $transaction = new Crowdfunding\Transaction(JFactory::getDbo()); $transaction->load(array("txn_id" => $preApprovalKey)); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_TRANSACTION_OBJECT"), $this->debugType, $transaction->getProperties()) : null; // Check for existed transaction record. if ($transaction->getId()) { // Update existed transaction record. // If the current status is completed, // stop the process to prevent overwriting data. if ($transaction->isCompleted()) { return null; } $txnStatus = Joomla\Utilities\ArrayHelper::getValue($transactionData, "txn_status"); switch ($txnStatus) { case "completed": $this->processCompleted($transaction, $project, $transactionData); break; case "canceled": $this->processVoided($transaction, $project, $transactionData); break; } return null; } else { // Create the new transaction data. // Store the transaction data. $transaction->bind($transactionData); $transaction->store(); // Add funds to the project. if ($transaction->isCompleted() or $transaction->isPending()) { $amount = Joomla\Utilities\ArrayHelper::getValue($transactionData, "txn_amount"); $project->addFunds($amount); $project->storeFunds(); } // Set transaction ID. $transactionData["id"] = $transaction->getId(); return $transactionData; } }