/** * Save transaction data. * * @param array $transactionData * * @throws \RuntimeException * @throws \InvalidArgumentException * @throws \UnexpectedValueException * * @return Transaction|null */ protected function storeTransaction($transactionData) { // Get transaction object by transaction ID $keys = array('txn_id' => ArrayHelper::getValue($transactionData, 'txn_id')); $transaction = new 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']); } // IMPORTANT: It must be before ->bind(); $options = array('old_status' => $transaction->getStatus(), 'new_status' => $transactionData['txn_status']); // Create the new transaction record if there is not record. // If there is new record, store new data with new status. // Example: It has been 'pending' and now is 'completed'. // Example2: It has been 'pending' and now is 'failed'. $transaction->bind($transactionData); // Start database transaction. $db = JFactory::getDbo(); $db->transactionStart(); try { $transactionManager = new TransactionManager($db); $transactionManager->setTransaction($transaction); $transactionManager->process('com_crowdfunding.payment', $options); } catch (Exception $e) { $db->transactionRollback(); $this->log->add(JText::_($this->textPrefix . '_ERROR_TRANSACTION_PROCESS'), $this->errorType, $e->getMessage()); return null; } // Commit database transaction. $db->transactionCommit(); return $transaction; }