Пример #1
0
 /**
  * Save transaction.
  *
  * @param array     $data
  *
  * @return boolean
  */
 protected function storeTransaction($data)
 {
     // Get transaction by txn ID
     jimport("virtualcurrency.transaction");
     $keys = array("txn_id" => JArrayHelper::getValue($data, "txn_id"));
     $transaction = new VirtualCurrencyTransaction(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 ($transaction->getId()) {
         // If the current status if completed,
         // stop the process.
         if ($transaction->isCompleted()) {
             return false;
         }
     }
     // Store the new transaction data.
     $transaction->bind($data);
     $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 units.
     if (!$transaction->isCompleted()) {
         return false;
     }
     // If the new transaction is completed,
     // update user account.
     $keys = array("user_id" => $transaction->getReceiverId(), "currency_id" => $transaction->getCurrencyId());
     jimport("virtualcurrency.account");
     $account = new VirtualCurrencyAccount(JFactory::getDbo());
     $account->load($keys);
     $account->increaseAmount($transaction->getUnits());
     $account->updateAmount();
     return true;
 }