/** * Method to save the submitted ordering values for records via AJAX. * * @throws Exception * @return void * @since 3.0 */ public function changeRewardsState() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $id = $this->input->post->getUint('id'); $state = $this->input->post->getUint('state'); $response = new Prism\Response\Json(); // Get the model $model = $this->getModel(); try { $model->changeRewardsState($id, $state); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $response->success()->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_REWARD_STATE_CHANGED_SUCCESSFULLY')); echo $response; JFactory::getApplication()->close(); }
/** * This method trigger the event onPaymentsPreparePayment. * The purpose of this method is to load a data and send it to browser. * That data will be used in the process of payment. */ public function preparePaymentAjax() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get component parameters $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ $response = new Prism\Response\Json(); // Check for disabled payment functionality if ($params->get("debug_payment_disabled", 0)) { // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE"))->failure(); echo $response; JFactory::getApplication()->close(); } $output = array(); // Prepare payment service name. $filter = new JFilterInput(); $paymentService = Joomla\String\String::trim(Joomla\String\String::strtolower($this->input->getCmd("payment_service"))); $paymentService = $filter->clean($paymentService, "ALNUM"); // Trigger the event try { $context = 'com_crowdfunding.preparepayment.' . $paymentService; // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onContentPreparePayment event. $results = $dispatcher->trigger("onPaymentsPreparePayment", array($context, &$params)); // Get the result, that comes from the plugin. if (!empty($results)) { foreach ($results as $result) { if (!is_null($result) and is_array($result)) { $output =& $result; break; } } } } catch (Exception $e) { // Store log data in the database JLog::add($e->getMessage()); // Send response to the browser $response->failure()->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); echo $response; JFactory::getApplication()->close(); } // Check the response $success = Joomla\Utilities\ArrayHelper::getValue($output, "success"); if (!$success) { // If there is an error... // Get project id. $projectId = $this->input->getUint("pid"); $paymentProcessContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $projectId; // Initialize the payment process object. $paymentProcess = new JData(); $paymentProcess->step1 = false; $app->setUserState($paymentProcessContext, $paymentProcess); // Send response to the browser $response->failure()->setTitle(Joomla\Utilities\ArrayHelper::getValue($output, "title"))->setText(Joomla\Utilities\ArrayHelper::getValue($output, "text")); } else { // If all is OK... // Send response to the browser $response->success()->setTitle(Joomla\Utilities\ArrayHelper::getValue($output, "title"))->setText(Joomla\Utilities\ArrayHelper::getValue($output, "text"))->setData(Joomla\Utilities\ArrayHelper::getValue($output, "data")); } echo $response; JFactory::getApplication()->close(); }
/** * 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(); }
/** * Catch a request from payment plugin via AJAX and process a transaction. */ public function notifyAjax() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $response = new Prism\Response\Json(); // Check for disabled payment functionality if ($this->params->get("debug_payment_disabled", 0)) { // Log the error. $error = JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED") . "\n"; $error .= JText::sprintf("COM_CROWDFUNDING_TRANSACTION_DATA", var_export($_REQUEST, true)); $this->log->add($error, "CONTROLLER_NOTIFIER_AJAX_ERROR"); // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE"))->failure(); echo $response; $app->close(); } // Get model object. $model = $this->getModel(); $transaction = null; $project = null; $reward = null; $paymentSession = null; $redirectUrl = null; $message = null; // 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 (!empty($results)) { foreach ($results as $result) { if (!empty($result) and isset($result["transaction"])) { $transaction = Joomla\Utilities\ArrayHelper::getValue($result, "transaction"); $project = Joomla\Utilities\ArrayHelper::getValue($result, "project"); $reward = Joomla\Utilities\ArrayHelper::getValue($result, "reward"); $paymentSession = Joomla\Utilities\ArrayHelper::getValue($result, "payment_session"); $redirectUrl = Joomla\Utilities\ArrayHelper::getValue($result, "redirect_url"); $message = Joomla\Utilities\ArrayHelper::getValue($result, "message"); break; } } } // If there is no transaction data, the status might be pending or another one. // So, we have to stop the script execution. if (!$transaction) { // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_TRANSACTION_NOT_PROCESSED_SUCCESSFULLY"))->failure(); echo $response; $app->close(); } // Trigger the event onAfterPayment $dispatcher->trigger('onAfterPayment', array($this->context, &$transaction, &$this->params, &$project, &$reward, &$paymentSession)); // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); } catch (Exception $e) { // Store log data to the database. $error = "AJAX NOTIFIER ERROR: " . $e->getMessage() . "\n"; $errorData = "INPUT:" . var_export($app->input, true) . "\n"; $this->log->add($error, "CONTROLLER_NOTIFIER_AJAX_ERROR", $errorData); // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); // 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; $app->close(); } // Generate redirect URL if (!$redirectUrl) { $uri = JUri::getInstance(); $redirectUrl = $uri->toString(array("scheme", "host")) . JRoute::_(CrowdfundingHelperRoute::getBackingRoute($project->slug, $project->catslug, "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; $app->close(); }
/** * This method trigger the event onPaymentsPreparePayment. * The purpose of this method is to load a data and send it to browser. * That data will be used in the process of payment. * * @throws \InvalidArgumentException */ public function preparePaymentAjax() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get component parameters $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ $response = new Prism\Response\Json(); // Check for disabled payment functionality if ($params->get('debug_payment_disabled', 0)) { // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE'))->failure(); echo $response; $app->close(); } $paymentResult = null; // Prepare payment service alias. $filter = new JFilterInput(); $paymentService = $filter->clean(trim(strtolower($this->input->getCmd('payment_service'))), 'ALNUM'); // Trigger the event try { $context = 'com_crowdfunding.preparepayment.' . $paymentService; // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onContentPreparePayment event. $results = $dispatcher->trigger('onPaymentsPreparePayment', array($context, &$params)); // Get the result, that comes from the plugin. if (is_array($results) and count($results) > 0) { foreach ($results as $result) { if ($result !== null and is_object($result)) { $paymentResult = $result; break; } } } } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); // Send response to the browser $response->failure()->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); echo $response; $app->close(); } // Check the response $success = isset($paymentResult->success) ? $paymentResult->success : null; $title = isset($paymentResult->title) ? $paymentResult->title : null; $text = isset($paymentResult->text) ? $paymentResult->text : null; $data = isset($paymentResult->data) ? $paymentResult->data : null; if (!$success) { // If there is an error... $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $this->input->getUint('pid'); // Initialize the payment process object. $paymentSessionLocal = new JData(); $paymentSessionLocal->step1 = false; $app->setUserState($paymentSessionContext, $paymentSessionLocal); // Send response to the browser $response->failure()->setTitle($title)->setText($text); } else { // If all is OK... $response->success()->setTitle($title)->setText($text)->setData($data); } echo $response; $app->close(); }