/** * Catch a request from payment plugin via AJAX and process a transaction. */ public function notifyAjax() { $response = new Prism\Response\Json(); // Check for disabled payment functionality if ($this->params->get('debug_payment_disabled', 0)) { $errorData = JText::sprintf('COM_CROWDFUNDING_TRANSACTION_DATA', var_export($_REQUEST, true)); $this->log->add(JText::_('COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED'), 'ERROR_CONTROLLER_NOTIFIER_AJAX', $errorData); // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE'))->failure(); echo $response; $this->app->close(); } // Get model object. $model = $this->getModel(); $paymentResult = null; $redirectUrl = null; $message = null; $project = null; /** @var Crowdfunding\Project $project */ // Trigger the event try { // Import Crowdfunding Payment Plugins JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onPaymentNotify event. $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onPaymentNotify', array($this->context, &$this->params)); if (is_array($results) and count($results) > 0) { foreach ($results as $result) { if (is_object($result) and isset($result->transaction)) { $paymentResult = $result; $project = isset($result->project) ? $result->project : null; $redirectUrl = isset($result->redirectUrl) ? $result->redirectUrl : null; $message = isset($result->message) ? $result->message : null; break; } } } // If there is no transaction data, the status might be pending or another one. // So, we have to stop the script execution. if (!$paymentResult) { // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_TRANSACTION_NOT_PROCESSED_SUCCESSFULLY'))->failure(); echo $response; $this->app->close(); } // Trigger the event onAfterPaymentNotify $dispatcher->trigger('onAfterPaymentNotify', array($this->context, &$paymentResult, &$this->params)); // Trigger the event onAfterPayment $dispatcher->trigger('onAfterPayment', array($this->context, &$paymentResult, &$this->params)); } catch (Exception $e) { // Store log data to the database. $error = 'AJAX NOTIFIER ERROR: ' . $e->getMessage() . "\n"; $errorData = 'INPUT:' . var_export($this->app->input, true) . "\n"; $this->log->add($error, 'ERROR_CONTROLLER_NOTIFIER_AJAX', $errorData); // Send response to the browser $response->failure()->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); // Send notification about the error to the administrator. $model->sendMailToAdministrator(); echo $response; $this->app->close(); } // Generate redirect URL if (!$redirectUrl and is_object($project)) { $uri = JUri::getInstance(); $redirectUrl = $uri->toString(array('scheme', 'host')) . JRoute::_(CrowdfundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatSlug(), 'share')); } if (!$message) { $message = JText::_('COM_CROWDFUNDING_TRANSACTION_PROCESSED_SUCCESSFULLY'); } // Send response to the browser $response->success()->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText($message)->setRedirectUrl($redirectUrl); echo $response; $this->app->close(); }