예제 #1
0
 /**
  * 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 */
     jimport('itprism.response.json');
     $response = new ITPrismResponseJson();
     // 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 = JString::trim(JString::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 = JArrayHelper::getValue($output, "success");
     if (!$success) {
         // If there is an error...
         // Get project id.
         $projectId = $this->input->getUint("pid");
         $paymentProcessContext = CrowdFundingConstants::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(JArrayHelper::getValue($output, "title"))->setText(JArrayHelper::getValue($output, "text"));
     } else {
         // If all is OK...
         // Send response to the browser
         $response->success()->setTitle(JArrayHelper::getValue($output, "title"))->setText(JArrayHelper::getValue($output, "text"))->setData(JArrayHelper::getValue($output, "data"));
     }
     echo $response;
     JFactory::getApplication()->close();
 }
예제 #2
0
 /**
  * Catch a request from payment plugin via AJAX and process a transaction.
  */
 public function notifyAjax()
 {
     jimport('itprism.response.json');
     $response = new ITPrismResponseJson();
     // 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;
         JFactory::getApplication()->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 onPaymenNotify event.
         $dispatcher = JEventDispatcher::getInstance();
         $results = $dispatcher->trigger("onPaymenNotify", array($this->context, &$this->params));
         if (!empty($results)) {
             foreach ($results as $result) {
                 if (!empty($result) and isset($result["transaction"])) {
                     $transaction = JArrayHelper::getValue($result, "transaction");
                     $project = JArrayHelper::getValue($result, "project");
                     $reward = JArrayHelper::getValue($result, "reward");
                     $paymentSession = JArrayHelper::getValue($result, "payment_session");
                     $redirectUrl = JArrayHelper::getValue($result, "redirect_url");
                     $message = JArrayHelper::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;
             JFactory::getApplication()->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.
         $this->log->add(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM"), "CONTROLLER_NOTIFIER_AJAX_ERROR", $e->getMessage());
         // 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;
         JFactory::getApplication()->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;
     JFactory::getApplication()->close();
 }