/** * 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 processCompleted(&$transaction, &$project, &$data) { // Set a flag that shows the project is NOT funded. // If the status had not been completed or pending ( it might be failed, voided, created,...), // the project funds has not been increased. So, I will set this flag to how this below. $projectFunded = true; if (!$transaction->isCompleted() and !$transaction->isPending()) { $projectFunded = false; } // 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(); if (!$projectFunded and ($transaction->isCompleted() or $transaction->isPending())) { $amount = Joomla\Utilities\ArrayHelper::getValue($data, 'txn_amount'); $project->addFunds($amount); $project->storeFunds(); } return true; }
/** * @param Crowdfunding\Transaction $transaction * @param Crowdfunding\Project $project * @param array $data * * @return bool */ protected function processCompleted(&$transaction, &$project, &$data) { // Set a flag that shows the project is NOT funded. // If the status had not been completed or pending ( it might be failed, voided, created,...), // the project funds had not been increased. So, I will set this flag to false. $projectFunded = true; if (!$transaction->isCompleted() and !$transaction->isPending()) { $projectFunded = false; } // 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. if ($transaction->isCompleted()) { $data["pending_reason"] = ""; } // Update the transaction data. $transaction->bind($data); $transaction->store(); // If the transaction status has been changed to pending or completed, // I have to add funds to the project. if (!$projectFunded and ($transaction->isCompleted() or $transaction->isPending())) { $amount = Joomla\Utilities\ArrayHelper::getValue($data, "txn_amount"); $project->addFunds($amount); $project->storeFunds(); } return true; }