/** * 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; }
/** * @param Crowdfunding\Transaction $transaction * @param Crowdfunding\Project $project * @param array $data * * @return bool */ protected function processVoided(&$transaction, &$project, &$data) { // It is possible only to void a transaction with status "pending". if (!$transaction->isPending()) { return false; } // Set transaction data to canceled. $data['txn_status'] = 'canceled'; // Update the transaction data. // If the current status is pending and the new status is completed, // only store the transaction data, updating the status to completed. $transaction->bind($data, array('extra_data')); $transaction->addExtraData($data['extra_data']); $transaction->store(); $amount = Joomla\Utilities\ArrayHelper::getValue($data, 'txn_amount'); $project->removeFunds($amount); $project->storeFunds(); return true; }
/** * @param Crowdfunding\Transaction $transaction * @param Crowdfunding\Project $project * @param array $data * * @return bool */ protected function processVoided(&$transaction, &$project, &$data) { // It is possible only to void a transaction with status "pending". if (!$transaction->isPending()) { return; } // Merge existed extra data with the new one. if (!empty($data["extra_data"])) { $transaction->addExtraData($data["extra_data"]); unset($data["extra_data"]); } // Remove the status reason. $data["status_reason"] = ""; // Update the transaction data. // If the current status is pending and the new status is completed, // only store the transaction data, updating the status to completed. $transaction->bind($data); $transaction->store(); $amount = Joomla\Utilities\ArrayHelper::getValue($data, "txn_amount"); $project->removeFunds($amount); $project->storeFunds(); }