示例#1
0
 /**
  * This method is invoked when the administrator changes transaction status from the backend.
  *
  * @param string $context   This string gives information about that where it has been executed the trigger.
  * @param object $item      A transaction data.
  * @param string $oldStatus Old status
  * @param string $newStatus New status
  *
  * @return void
  */
 public function onTransactionChangeState($context, &$item, $oldStatus, $newStatus)
 {
     $allowedContexts = array("com_crowdfunding.transaction", "com_crowdfundingfinance.transaction");
     if (!in_array($context, $allowedContexts)) {
         return;
     }
     $app = \JFactory::getApplication();
     /** @var $app \JApplicationSite */
     if ($app->isSite()) {
         return;
     }
     $doc = \JFactory::getDocument();
     /**  @var $doc \JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("html", $docType) != 0) {
         return;
     }
     // Verify the service provider.
     $paymentService = str_replace(" ", "", String::strtolower(String::trim($item->service_provider)));
     if (strcmp($this->paymentService, $paymentService) != 0) {
         return;
     }
     if (strcmp($oldStatus, "completed") == 0) {
         // Remove funds if someone change the status from completed to other one.
         $project = new Crowdfunding\Project(\JFactory::getDbo());
         $project->load($item->project_id);
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . "_DEBUG_BCSNC"), $this->debugType, $project->getProperties()) : null;
         $project->removeFunds($item->txn_amount);
         $project->storeFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . "_DEBUG_ACSNC"), $this->debugType, $project->getProperties()) : null;
     } elseif (strcmp($newStatus, "completed") == 0) {
         // Add funds if someone change the status to completed.
         $project = new Crowdfunding\Project(\JFactory::getDbo());
         $project->load($item->project_id);
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . "_DEBUG_BCSTC"), $this->debugType, $project->getProperties()) : null;
         $project->addFunds($item->txn_amount);
         $project->storeFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . "_DEBUG_ACSTC"), $this->debugType, $project->getProperties()) : null;
     }
 }
示例#2
0
 /**
  * This method is invoked when the administrator changes transaction status from the backend.
  *
  * @param string $context   This string gives information about that where it has been executed the trigger.
  * @param \stdClass $item    A transaction data.
  * @param string $oldStatus Old status
  * @param string $newStatus New status
  *
  * @return void
  */
 public function onTransactionChangeState($context, &$item, $oldStatus, $newStatus)
 {
     $allowedContexts = array('com_crowdfunding.transaction', 'com_crowdfundingfinance.transaction');
     if (!in_array($context, $allowedContexts, true)) {
         return;
     }
     $app = \JFactory::getApplication();
     /** @var $app \JApplicationSite */
     if ($app->isSite()) {
         return;
     }
     $doc = \JFactory::getDocument();
     /**  @var $doc \JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp('html', $docType) !== 0) {
         return;
     }
     // Verify the service provider.
     if (strcmp($this->serviceAlias, $item->service_alias) !== 0) {
         return;
     }
     if (strcmp($oldStatus, 'completed') === 0) {
         // Remove funds if someone change the status from completed to other one.
         $project = new Crowdfunding\Project(\JFactory::getDbo());
         $project->load($item->project_id);
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . '_DEBUG_BCSNC'), $this->debugType, $project->getProperties()) : null;
         $project->removeFunds($item->txn_amount);
         $project->storeFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . '_DEBUG_ACSNC'), $this->debugType, $project->getProperties()) : null;
     } elseif (strcmp($newStatus, 'completed') === 0) {
         // Add funds if someone change the status to completed.
         $project = new Crowdfunding\Project(\JFactory::getDbo());
         $project->load($item->project_id);
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . '_DEBUG_BCSTC'), $this->debugType, $project->getProperties()) : null;
         $project->addFunds($item->txn_amount);
         $project->storeFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . '_DEBUG_ACSTC'), $this->debugType, $project->getProperties()) : null;
     }
 }