/** * Method to get an object. * * @param integer $id The id of the object to get. * * @return null|object Object on success, false on failure. */ public function getItem($id = null) { if (empty($id)) { $id = $this->getState($this->getName() . '.id'); } $storedId = $this->getStoreId($id); if (!isset($this->item[$storedId])) { $this->item[$storedId] = null; // Get a level row instance. $table = $this->getTable(); $table->load($id); // Attempt to load the row. if ($table->get("id")) { $properties = $table->getProperties(); $this->item[$storedId] = Joomla\Utilities\ArrayHelper::toObject($properties); } } return $this->item[$storedId]; }
/** * Method to get an object. * * @param integer $id The id of the object to get. * * @return null|stdClass Object on success, false on failure. */ public function getItem($id = 0) { if ((int) $id === 0) { $id = $this->getState($this->getName() . '.id'); } $storedId = $this->getStoreId($id); if (!array_key_exists($storedId, $this->item)) { $this->item[$storedId] = null; // Get a level row instance. $table = $this->getTable(); $table->load($id); // Attempt to load the row. if ($table->get('id')) { $properties = $table->getProperties(); $this->item[$storedId] = Joomla\Utilities\ArrayHelper::toObject($properties); } } return $this->item[$storedId]; }
/** * Method to get an object. * * @param integer $id The id of the object to get. * * @return mixed Object on success, false on failure. */ public function getItem($id = null) { if ($this->item === null) { if ($id === null) { $id = $this->getState($this->getName() . '.id'); } // Get a level row instance. $table = JTable::getInstance('Item', 'UserIdeasTable'); // Attempt to load the row. if ($table->load($id)) { if (!$table->get('published')) { return $this->item; } // Convert the JTable to a clean JObject. $properties = $table->getProperties(true); $this->item = Joomla\Utilities\ArrayHelper::toObject($properties, 'JObject'); } } return $this->item; }
/** * Method to get an object. * * @param int $id The id of the object to get. * @param int $userId User ID. * * @return mixed Object on success, false on failure. */ public function getItem($id, $userId) { // If missing ID, I have to return null, because there is no item. if (!$id or !$userId) { return null; } $storedId = $this->getStoreId($id); if (!array_key_exists($storedId, $this->item)) { $this->item[$storedId] = null; // Get a level row instance. $table = JTable::getInstance('Notification', 'SocialCommunityTable'); /** @var $table SocialCommunityTableNotification */ $keys = array('id' => $id, 'user_id' => $userId); // Attempt to load the row. if ($table->load($keys)) { $properties = $table->getProperties(); $properties = Joomla\Utilities\ArrayHelper::toObject($properties); $this->item[$storedId] = $properties; } else { $this->item[$storedId] = null; } } return $this->item[$storedId]; }
/** * This method processes transaction data that comes from PayPal instant notifier. * * @param string $context This string gives information about that where it has been executed the trigger. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|array */ public function onPaymentNotify($context, &$params) { if (strcmp('com_crowdfunding.notify.' . $this->serviceAlias, $context) !== 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentRaw */ // Check document type $docType = $doc->getType(); if (strcmp('raw', $docType) !== 0) { return null; } // Validate request method $requestMethod = $this->app->input->getMethod(); if (strcmp('POST', $requestMethod) !== 0) { $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_REQUEST_METHOD'), $this->debugType, JText::sprintf($this->textPrefix . '_ERROR_INVALID_TRANSACTION_REQUEST_METHOD', $requestMethod)); return null; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_RESPONSE'), $this->debugType, $_POST) : null; // Decode custom data $custom = Joomla\Utilities\ArrayHelper::getValue($_POST, 'custom'); $custom = json_decode(base64_decode($custom), true); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_CUSTOM'), $this->debugType, $custom) : null; // Validate payment services. $gateway = Joomla\Utilities\ArrayHelper::getValue($custom, 'gateway'); if (!$this->isValidPaymentGateway($gateway)) { $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_PAYMENT_GATEWAY'), $this->debugType, array('custom' => $custom, '_POST' => $_POST)); return null; } // Get PayPal URL if ($this->params->get('paypal_sandbox', 1)) { $url = JString::trim($this->params->get('paypal_sandbox_url', 'https://www.sandbox.paypal.com/cgi-bin/webscr')); } else { $url = JString::trim($this->params->get('paypal_url', 'https://www.paypal.com/cgi-bin/webscr')); } $paypalIPN = new Prism\Payment\PayPal\Ipn($url, $_POST); $loadCertificate = (bool) $this->params->get('paypal_load_certificate', 0); $paypalIPN->verify($loadCertificate); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_IPN_OBJECT'), $this->debugType, $paypalIPN) : null; // Prepare the array that will be returned by this method $result = array('project' => null, 'reward' => null, 'transaction' => null, 'payment_session' => null, 'service_provider' => $this->serviceProvider, 'service_alias' => $this->serviceAlias); if ($paypalIPN->isVerified()) { // Get currency $currencyId = $params->get('project_currency'); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $currencyId); // Get payment session data $paymentSessionId = Joomla\Utilities\ArrayHelper::getValue($custom, 'payment_session_id', 0, 'int'); $paymentSession = $this->getPaymentSession(array('id' => $paymentSessionId)); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_PAYMENT_SESSION'), $this->debugType, $paymentSession->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_POST, $currency->getCode(), $paymentSession); if ($validData === null) { return $result; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_VALID_DATA'), $this->debugType, $validData) : null; // Get project. $projectId = Joomla\Utilities\ArrayHelper::getValue($validData, 'project_id'); $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_PROJECT_OBJECT'), $this->debugType, $project->getProperties()) : null; // Check for valid project if (!$project->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_PROJECT'), $this->debugType, $validData); return $result; } // Set the receiver of funds $validData['receiver_id'] = $project->getUserId(); // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data $transactionData = $this->storeTransaction($validData, $project); if ($transactionData === null) { return $result; } // Update the number of distributed reward. $rewardId = Joomla\Utilities\ArrayHelper::getValue($transactionData, 'reward_id', 0, 'int'); $reward = null; if ($rewardId > 0) { $reward = $this->updateReward($transactionData); // Validate the reward. if (!$reward) { $transactionData['reward_id'] = 0; } } // Prepare the data that will be returned $result['transaction'] = Joomla\Utilities\ArrayHelper::toObject($transactionData); // Generate object of data based on the project properties $properties = $project->getProperties(); $result['project'] = Joomla\Utilities\ArrayHelper::toObject($properties); // Generate object of data based on the reward properties if ($reward !== null and $reward instanceof Crowdfunding\Reward) { $properties = $reward->getProperties(); $result['reward'] = Joomla\Utilities\ArrayHelper::toObject($properties); } // Generate data object, based on the payment session properties. $properties = $paymentSession->getProperties(); $result['payment_session'] = Joomla\Utilities\ArrayHelper::toObject($properties); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_RESULT_DATA'), $this->debugType, $result) : null; // Remove payment session. $txnStatus = isset($result['transaction']->txn_status) ? $result['transaction']->txn_status : null; $this->closePaymentSession($paymentSession, $txnStatus); } else { // Log error $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_TRANSACTION_DATA'), $this->debugType, array('error message' => $paypalIPN->getError(), 'paypalIPN' => $paypalIPN, '_POST' => $_POST)); } return $result; }
protected function prepareRewards() { $model = JModelLegacy::getInstance("Rewards", "CrowdfundingModel", $config = array('ignore_request' => false)); // Get state $this->state = $model->getState(); // Get params $this->projectId = $this->state->get("rewards.project_id"); // Check if rewards are enabled. if (!$this->rewardsEnabled) { $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_REWARDS_DISABLED"), "notice"); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getFormRoute($this->projectId, "manager"), false)); return; } $this->items = $model->getItems($this->projectId); // Get project and validate it $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $this->projectId); $project = $project->getProperties(); $this->item = Joomla\Utilities\ArrayHelper::toObject($project); // Check if the item exists. if (!$this->isValid()) { return; } // Create a currency object. $this->currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($this->currency); // Get date format $this->dateFormat = CrowdfundingHelper::getDateFormat(); $this->dateFormatCalendar = CrowdfundingHelper::getDateFormat(true); $language = JFactory::getLanguage(); $languageTag = $language->getTag(); $js = ' // Rewards calendar date format. var projectWizard = { dateFormat: "' . $this->dateFormatCalendar . '", locale: "' . substr($languageTag, 0, 2) . '" }; '; $this->document->addScriptDeclaration($js); // Prepare rewards images. $this->rewardsImagesEnabled = $this->params->get("rewards_images", 0); $this->rewardsImagesUri = CrowdfundingHelper::getImagesFolderUri($this->userId); $this->prepareProjectType(); $this->pathwayName = JText::_("COM_CROWDFUNDING_STEP_REWARDS"); }
/** * Method to get a single record. * * @param integer $pk The id of the primary key. * * @return mixed Object on success, false on failure. */ public function getItem($pk = null) { $pk = !empty($pk) ? $pk : (int) $this->getState('plugin.id'); if (!isset($this->_cache[$pk])) { $false = false; // Get a row instance. $table = $this->getTable(); // Attempt to load the row. $return = $table->load($pk); // Check for a table object error. if ($return === false && $table->getError()) { $this->setError($table->getError()); return $false; } // Convert to the JObject before adding other data. $properties = $table->getProperties(1); $this->_cache[$pk] = Joomla\Utilities\ArrayHelper::toObject($properties, 'JObject'); // Convert the params field to an array. $registry = new JRegistry(); $registry->loadString($table->params); $this->_cache[$pk]->params = $registry->toArray(); // Get the plugin XML. $path = KunenaPath::clean(JPATH_PLUGINS . '/' . $table->folder . '/' . $table->element . '/' . $table->element . '.xml'); if (is_file($path)) { $this->_cache[$pk]->xml = simplexml_load_file($path); } else { $this->_cache[$pk]->xml = null; } } return $this->_cache[$pk]; }
/** * This method processes transaction data that comes from PayPal instant notifier. * * @param string $context This string gives information about that where it has been executed the trigger. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|array */ public function onPaymentNotify($context, &$params) { if (strcmp("com_crowdfunding.notify.paypal", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("raw", $docType) != 0) { return null; } // Validate request method $requestMethod = $this->app->input->getMethod(); if (strcmp("POST", $requestMethod) != 0) { $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_REQUEST_METHOD"), $this->debugType, JText::sprintf($this->textPrefix . "_ERROR_INVALID_TRANSACTION_REQUEST_METHOD", $requestMethod)); return null; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESPONSE"), $this->debugType, $_POST) : null; // Decode custom data $custom = Joomla\Utilities\ArrayHelper::getValue($_POST, "custom"); $custom = json_decode(base64_decode($custom), true); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_CUSTOM"), $this->debugType, $custom) : null; // Verify gateway. Is it PayPal? if (!$this->isPayPalGateway($custom)) { $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PAYMENT_GATEWAY"), $this->debugType, array("custom" => $custom, "_POST" => $_POST)); return null; } // Get PayPal URL if ($this->params->get('paypal_sandbox', 1)) { $url = Joomla\String\String::trim($this->params->get('paypal_sandbox_url', "https://www.sandbox.paypal.com/cgi-bin/webscr")); } else { $url = Joomla\String\String::trim($this->params->get('paypal_url', "https://www.paypal.com/cgi-bin/webscr")); } $paypalIpn = new Prism\Payment\PayPal\Ipn($url, $_POST); $loadCertificate = (bool) $this->params->get("paypal_load_certificate", 0); $paypalIpn->verify($loadCertificate); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_VERIFY_OBJECT"), $this->debugType, $paypalIpn) : null; // Prepare the array that have to be returned by this method. $result = array("project" => null, "reward" => null, "transaction" => null, "payment_session" => null, "payment_service" => $this->paymentService); if ($paypalIpn->isVerified()) { // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Get payment session data $paymentSessionId = Joomla\Utilities\ArrayHelper::getValue($custom, "payment_session_id", 0, "int"); $paymentSession = $this->getPaymentSession(array("id" => $paymentSessionId)); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYMENT_SESSION"), $this->debugType, $paymentSession->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_POST, $currency->getCode(), $paymentSession); if (is_null($validData)) { return $result; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_VALID_DATA"), $this->debugType, $validData) : null; // Get project. $projectId = Joomla\Utilities\ArrayHelper::getValue($validData, "project_id"); $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PROJECT_OBJECT"), $this->debugType, $project->getProperties()) : null; // Check for valid project if (!$project->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PROJECT"), $this->debugType, $validData); return $result; } // Set the receiver of funds. $validData["receiver_id"] = $project->getUserId(); // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data $transactionData = $this->storeTransaction($validData, $project); if (is_null($transactionData)) { return $result; } // Update the number of distributed reward. $rewardId = Joomla\Utilities\ArrayHelper::getValue($transactionData, "reward_id"); $reward = null; if (!empty($rewardId)) { $reward = $this->updateReward($transactionData); // Validate the reward. if (!$reward) { $transactionData["reward_id"] = 0; } } // Generate object of data, based on the transaction properties. $result["transaction"] = Joomla\Utilities\ArrayHelper::toObject($transactionData); // Generate object of data based on the project properties. $properties = $project->getProperties(); $result["project"] = Joomla\Utilities\ArrayHelper::toObject($properties); // Generate object of data based on the reward properties. if (!empty($reward)) { $properties = $reward->getProperties(); $result["reward"] = Joomla\Utilities\ArrayHelper::toObject($properties); } // Generate data object, based on the payment session properties. $properties = $paymentSession->getProperties(); $result["payment_session"] = Joomla\Utilities\ArrayHelper::toObject($properties); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESULT_DATA"), $this->debugType, $result) : null; // Remove payment session. $txnStatus = isset($result["transaction"]->txn_status) ? $result["transaction"]->txn_status : null; $this->closePaymentSession($paymentSession, $txnStatus); } else { // Log error $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_TRANSACTION_DATA"), $this->debugType, array("error message" => $paypalIpn->getError(), "paypalVerify" => $paypalIpn, "_POST" => $_POST)); } return $result; }
/** * Method to get a single record. * * @param integer $pk The id of the primary key. * * @return mixed Object on success, false on failure. * * @since 12.2 */ public function getItem($pk = null) { $pk = $pk !== null ? (int) $pk : (int) $this->getState($this->getName() . '.id'); $table = $this->getTable(); if ($pk > 0) { // Attempt to load the row. $return = $table->load($pk); // Check for a table object error. if ($return === false) { throw new RuntimeException(JText::_('COM_USERIDEAS_ERROR_INVALID_ITEM')); } } // Convert to the JObject before adding other data. $properties = $table->getProperties(1); $item = Joomla\Utilities\ArrayHelper::toObject($properties, 'JObject'); if (property_exists($item, 'params')) { $registry = new Joomla\Registry\Registry(); $registry->loadString($item->params); $item->params = $registry->toArray(); } $item->tags = new JHelperTags(); $item->tags->getTagIds($item->id, 'com_userideas.item'); return $item; }
/** * Method to get a single record. * * @param integer $commentId The id of the primary key. * @param integer $userId The user Id * * @return JObject * * @throw Exception * @since 11.1 */ public function getItem($commentId, $userId) { if ($this->item !== null) { return $this->item; } // Initialise variables. $table = $this->getTable(); if ($commentId > 0 and $userId > 0) { $keys = array('id' => $commentId, 'user_id' => $userId); // Attempt to load the row. $table->load($keys); } // Convert to the JObject before adding other data. $properties = $table->getProperties(); $this->item = Joomla\Utilities\ArrayHelper::toObject($properties, 'JObject'); return $this->item; }
public static function createContentType() { $typeCategory = array('type_title' => 'UserIdeas Category', 'type_alias' => 'com_userideas.category', 'table' => '{"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"},"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}', 'rules' => '', 'field_mappings' => '{"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias","core_created_time":"created_time","core_modified_time":"modified_time","core_body":"description", "core_hits":"hits","core_publish_up":"null","core_publish_down":"null","core_access":"access", "core_params":"params", "core_featured":"null", "core_metadata":"metadata", "core_language":"language", "core_images":"null", "core_urls":"null", "core_version":"version", "core_ordering":"null", "core_metakey":"metakey", "core_metadesc":"metadesc", "core_catid":"parent_id", "core_xreference":"null", "asset_id":"asset_id"}, "special": {"parent_id":"parent_id","lft":"lft","rgt":"rgt","level":"level","path":"path","extension":"extension","note":"note"}}', 'router' => 'UserIdeasHelperRoute::getCategoryRoute', 'content_history_options' => '{"formFile":"administrator\\/components\\/com_categories\\/models\\/forms\\/category.xml", "hideFields":["asset_id","checked_out","checked_out_time","version","lft","rgt","level","path","extension"], "ignoreChanges":["modified_user_id", "modified_time", "checked_out", "checked_out_time", "version", "hits", "path"],"convertToInt":["publish_up", "publish_down"], "displayLookup":[{"sourceColumn":"created_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id","displayColumn":"title"},{"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id","displayColumn":"title"}]}'); $typeItem = array('type_title' => 'UserIdeas Item', 'type_alias' => 'com_userideas.item', 'table' => '{"special":{"dbtable":"#__uideas_items","key":"id","type":"Item","prefix":"UserIdeasTable","config":"array()"},"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}', 'rules' => '', 'field_mappings' => '{"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias","core_created_time":"record_date","core_modified_time":"null","core_body":"description","core_hits":"hits","core_publish_up":"null","core_publish_down":"null","core_access":"null","core_params":"null","core_featured":"null","core_metadata":"null","core_language":"null","core_images":"null","core_urls":"null","core_version":"null","core_ordering":"ordering","core_metakey":"null","core_metadesc":"null","core_catid":"catid","core_xreference":"null","asset_id":"null"},"special":{"votes":"votes","status_id":"status_id","user_id":"user_id"}}', 'router' => 'UserIdeasHelperRoute::getDetailsRoute', 'content_history_options' => '{"formFile":"administrator\\/components\\/com_userideas\\/models\\/forms\\/item.xml","hideFields":["votes","hits","record_date"],"ignoreChanges":["votes","hits","record_date",],"convertToInt":["votes","hits","ordering", "published", "status_id", "catid", "user_id"],"displayLookup":[{"sourceColumn":"catid","targetTable":"#__categories","targetColumn":"id","displayColumn":"title"},{"sourceColumn":"user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"status_id","targetTable":"#__uideas_statuses","targetColumn":"id","displayColumn":"name"}]}'); $db = JFactory::getDbo(); // Insert com_userideas.category $query = $db->getQuery(true); $query->select('a.type_id')->from($db->quoteName('#__content_types', 'a'))->where('a.type_alias = ' . $db->quote('com_userideas.category')); $db->setQuery($query, 0, 1); $result = $db->loadResult(); if (!$result) { $typeCategory = Joomla\Utilities\ArrayHelper::toObject($typeCategory); $db->insertObject('#__content_types', $typeCategory); } // Insert com_userideas.item $query = $db->getQuery(true); $query->select('a.type_id')->from($db->quoteName('#__content_types', 'a'))->where('a.type_alias = ' . $db->quote('com_userideas.item')); $db->setQuery($query, 0, 1); $result = $db->loadResult(); if (!$result) { $typeItem = Joomla\Utilities\ArrayHelper::toObject($typeItem); $db->insertObject('#__content_types', $typeItem); } }
/** * This method executes the event onContentAfterSave. * * @param CrowdfundingTableReport $table * * @throws RuntimeException */ protected function triggerEventAfterReport($table) { // Get properties $report = $table->getProperties(); $report = Joomla\Utilities\ArrayHelper::toObject($report); // Generate context $context = $this->option . '.report'; // Include the content plugins for the change of state event. $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('content'); // Trigger the onContentAfterSave event. $results = $dispatcher->trigger('onContentAfterReport', array($context, &$report)); if (in_array(false, $results, true)) { throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_DURING_REPORTING_PROCESS')); } }
/** * Process preapproval notification data from PayPal. * * @param array $result * @param string $url The parameters of the component * @param bool $loadCertificate * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|array */ protected function processPreApproval(&$result, $url, $loadCertificate, &$params) { $paypalIpn = new Prism\Payment\PayPal\Ipn($url, $_POST); $paypalIpn->verify($loadCertificate); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_IPN_OBJECT"), $this->debugType, $paypalIpn) : null; if ($paypalIpn->isVerified()) { // Get currency $currencyId = $params->get("project_currency"); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $currencyId, $params); $preApprovalKey = Joomla\Utilities\ArrayHelper::getValue($_POST, "preapproval_key"); // Get payment session data $keys = array("unique_key" => $preApprovalKey); $paymentSession = $this->getPaymentSession($keys); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYMENT_SESSION"), $this->debugType, $paymentSession->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_POST, $currency->getCode(), $paymentSession); if (is_null($validData)) { return $result; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_VALID_DATA"), $this->debugType, $validData) : null; // Get project. $projectId = Joomla\Utilities\ArrayHelper::getValue($validData, "project_id"); $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PROJECT_OBJECT"), $this->debugType, $project->getProperties()) : null; // Check for valid project if (!$project->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PROJECT"), $this->debugType, $validData); return $result; } // Set the receiver of funds $validData["receiver_id"] = $project->getUserId(); // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data $transactionData = $this->storeTransaction($validData, $project, $preApprovalKey); if (is_null($transactionData)) { return $result; } // Update the number of distributed reward. $rewardId = Joomla\Utilities\ArrayHelper::getValue($transactionData, "reward_id"); $reward = null; if (!empty($rewardId)) { $reward = $this->updateReward($transactionData); // Validate the reward. if (!$reward) { $transactionData["reward_id"] = 0; } } // Prepare the data that will be returned $result["transaction"] = Joomla\Utilities\ArrayHelper::toObject($transactionData); // Generate object of data based on the project properties $properties = $project->getProperties(); $result["project"] = Joomla\Utilities\ArrayHelper::toObject($properties); // Generate object of data based on the reward properties if (!empty($reward)) { $properties = $reward->getProperties(); $result["reward"] = Joomla\Utilities\ArrayHelper::toObject($properties); } // Generate data object, based on the payment session properties. $properties = $paymentSession->getProperties(); $result["payment_session"] = Joomla\Utilities\ArrayHelper::toObject($properties); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESULT_DATA"), $this->debugType, $result) : null; // Remove payment session. $txnStatus = isset($result["transaction"]->txn_status) ? $result["transaction"]->txn_status : null; $this->closePaymentSession($paymentSession, $txnStatus); } else { // Log error $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_TRANSACTION_DATA"), $this->debugType, array("error message" => $paypalIpn->getError(), "paypalIPN" => $paypalIpn, "_POST" => $_POST)); } return $result; }
/** * Method to get a single record. * * @param integer $pk The id of the primary key. * @param integer $userId The user Id * * @throws Exception * @return object * * @since 11.1 */ public function getItem($pk, $userId) { if ($this->item) { return $this->item; } // Initialise variables. $table = $this->getTable(); if ($pk > 0 and $userId > 0) { $keys = array("id" => $pk, "user_id" => $userId); // Attempt to load the row. $return = $table->load($keys); // Check for a table object error. if ($return === false) { throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); } } // Convert to the JObject before adding other data. $properties = $table->getProperties(); $this->item = Joomla\Utilities\ArrayHelper::toObject($properties, 'JObject'); return $this->item; }
/** * This method processes transaction. * * @param string $context This string gives information about that where it has been executed the trigger. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|array */ public function onPaymentNotify($context, &$params) { if (strcmp('com_crowdfunding.notify.blockchain', $context) !== 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('raw', $docType) !== 0) { return null; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_RESPONSE'), $this->debugType, $_GET) : null; $result = array('project' => null, 'reward' => null, 'transaction' => null, 'payment_session' => null, 'service_provider' => $this->serviceProvider, 'service_alias' => $this->serviceAlias, 'response' => ''); // Get extension parameters $currencyId = $params->get('project_currency'); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $currencyId); // Get payment session data $paymentSessionId = $this->app->input->get->get('payment_session_id'); $paymentSession = $this->getPaymentSession(array('id' => $paymentSessionId)); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_PAYMENT_SESSION'), $this->debugType, $paymentSession->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_GET, $currency->getCode(), $paymentSession); if ($validData === null) { return $result; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_VALID_DATA'), $this->debugType, $validData) : null; // Get project $projectId = Joomla\Utilities\ArrayHelper::getValue($validData, 'project_id'); $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_PROJECT_OBJECT'), $this->debugType, $project->getProperties()) : null; // Check for valid project if (!$project->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_PROJECT'), $this->debugType, $validData); return $result; } // Set the receiver of funds $validData['receiver_id'] = $project->getUserId(); // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data $transactionData = $this->storeTransaction($validData, $project); if ($transactionData === null) { return $result; } // Update the number of distributed reward. $rewardId = Joomla\Utilities\ArrayHelper::getValue($transactionData, 'reward_id', 0, 'int'); $reward = null; if ($rewardId > 0) { $reward = $this->updateReward($transactionData); // Validate the reward. if (!$reward) { $transactionData['reward_id'] = 0; } } // Prepare the data that will be returned $result['transaction'] = Joomla\Utilities\ArrayHelper::toObject($transactionData); // Generate object of data based on the project properties $properties = $project->getProperties(); $result['project'] = Joomla\Utilities\ArrayHelper::toObject($properties); // Generate object of data based on the reward properties if ($reward !== null and $reward instanceof Crowdfunding\Reward) { $properties = $reward->getProperties(); $result['reward'] = Joomla\Utilities\ArrayHelper::toObject($properties); } // Generate data object, based on the payment session properties. $properties = $paymentSession->getProperties(); $result['payment_session'] = Joomla\Utilities\ArrayHelper::toObject($properties); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_RESULT_DATA'), $this->debugType, $result) : null; // Remove payment session. $txnStatus = isset($result['transaction']->txn_status) ? $result['transaction']->txn_status : null; $this->closePaymentSession($paymentSession, $txnStatus); if (strcmp('completed', $result['transaction']->txn_status) === 0) { $result['response'] = '*ok*'; } return $result; }
public function doVoid() { // Get component parameters $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ // Check for disabled payment functionality if ($params->get('debug_payment_disabled', 0)) { throw new Exception(JText::_($this->text_prefix . '_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE')); } $cid = $this->input->get('cid', array(), 'array'); $cid = Joomla\Utilities\ArrayHelper::toInteger($cid); $messages = array(); try { if (count($cid) > 0) { $options = array('ids' => $cid, 'txn_status' => 'pending'); $items = new Crowdfunding\Transactions(JFactory::getDbo()); $items->load($options); if (count($items) === 0) { throw new UnexpectedValueException(JText::_($this->text_prefix . '_ERROR_INVALID_TRANSACTIONS')); } // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); foreach ($items as $item) { $item = Joomla\Utilities\ArrayHelper::toObject($item); $context = $this->option . '.payments.void.' . $item->service_alias; // Trigger onContentPreparePayment event. $results = $dispatcher->trigger('onPaymentsVoid', array($context, &$item, &$params)); foreach ($results as $message) { if ($message !== null and is_array($message)) { $messages[] = $message; } } } } } catch (UnexpectedValueException $e) { $this->setMessage($e->getMessage(), 'notice'); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=transactions', false)); return; } catch (Exception $e) { // Store log data in the database $this->log->add(JText::_($this->text_prefix . '_ERROR_SYSTEM'), 'CONTROLLER_PAYMENTS_DOCAPTURE_ERROR', $e->getMessage()); throw new Exception(JText::_($this->text_prefix . '_ERROR_SYSTEM')); } // Set messages. if (count($messages) > 0) { foreach ($messages as $message) { $this->app->enqueueMessage($message['text'], $message['type']); } } $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=transactions', false)); }
protected function prepareRewards() { $model = JModelLegacy::getInstance('Rewards', 'CrowdfundingModel', $config = array('ignore_request' => false)); // Get state $this->state = $model->getState(); // Get params $this->projectId = $this->state->get('rewards.project_id'); // Check if rewards are enabled. if (!$this->rewardsEnabled) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_REWARDS_DISABLED'), 'notice'); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getFormRoute($this->projectId, 'manager'), false)); return; } $this->items = $model->getItems($this->projectId); // Get project and validate it $project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $this->projectId); $project = $project->getProperties(); $this->item = Joomla\Utilities\ArrayHelper::toObject($project); // Check if the item exists. if (!CrowdfundingHelper::isAuthorized($this->userId, $this->item, 'rewards')) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_SOMETHING_WRONG'), 'notice'); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute())); return; } // Create a currency object. $this->currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($this->currency); // Get date format $this->dateFormat = CrowdfundingHelper::getDateFormat(); $this->dateFormatCalendar = CrowdfundingHelper::getDateFormat(true); $language = JFactory::getLanguage(); $languageTag = $language->getTag(); $js = ' // Rewards calendar date format. var projectWizard = { dateFormat: "' . $this->dateFormatCalendar . '", locale: "' . substr($languageTag, 0, 2) . '" }; '; $this->document->addScriptDeclaration($js); // Prepare rewards images. $this->rewardsImagesEnabled = (bool) $this->params->get('rewards_images', 0); $this->rewardsImagesUri = CrowdfundingHelper::getImagesFolderUri($this->userId); $this->options['column_left'] = (!$this->rewardsImagesEnabled or count($this->items) === 0) ? 12 : 8; $this->options['column_right'] = (!$this->rewardsImagesEnabled or count($this->items) === 0) ? 0 : 4; $this->prepareProjectType(); $this->pathwayName = JText::_('COM_CROWDFUNDING_STEP_REWARDS'); }
/** * This method executes the event onContentAfterSave. * * @param CrowdfundingTableProject $table * @param string $step * @param bool $isNew * * @throws Exception */ protected function triggerEventAfterSave($table, $step, $isNew = false) { // Get properties $project = $table->getProperties(); $project = Joomla\Utilities\ArrayHelper::toObject($project); // Generate context $context = $this->option . '.' . $step; // Include the content plugins for the change of state event. $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('content'); // Trigger the onContentAfterSave event. $results = $dispatcher->trigger("onContentAfterSave", array($context, &$project, $isNew)); if (in_array(false, $results, true)) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_DURING_PROJECT_CREATING_PROCESS")); } }
/** * This method performs the transaction. * * @param string $context * @param Joomla\Registry\Registry $params * * @return null|array */ public function onPaymentNotify($context, &$params) { if (strcmp("com_crowdfunding.notify.banktransfer", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("raw", $docType) != 0) { return null; } $projectId = $this->app->input->getInt("pid"); $amount = $this->app->input->getFloat("amount"); // Prepare the array that will be returned by this method $result = array("project" => null, "reward" => null, "transaction" => null, "payment_session" => null, "redirect_url" => null, "message" => null); // Get project $project = new Crowdfunding\Project(JFactory::getDbo()); $project->load($projectId); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PROJECT_OBJECT"), $this->debugType, $project->getProperties()) : null; // Check for valid project if (!$project->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PROJECT"), $this->debugType, array("PROJECT OBJECT" => $project->getProperties(), "REQUEST METHOD" => $this->app->input->getMethod(), "_REQUEST" => $_REQUEST)); return null; } $currencyId = $params->get("project_currency"); $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $currencyId, $params); // Prepare return URL $result["redirect_url"] = Joomla\String\String::trim($this->params->get('return_url')); if (!$result["redirect_url"]) { $filter = JFilterInput::getInstance(); $uri = JUri::getInstance(); $domain = $filter->clean($uri->toString(array("scheme", "host"))); $result["redirect_url"] = $domain . JRoute::_(CrowdfundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatslug(), "share"), false); } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RETURN_URL"), $this->debugType, $result["redirect_url"]) : null; // Payment Session $userId = JFactory::getUser()->get("id"); $aUserId = $this->app->getUserState("auser_id"); // Reset anonymous user hash ID, // because the payment session based in it will be removed when transaction completes. if (!empty($aUserId)) { $this->app->setUserState("auser_id", ""); } $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $project->getId(); $paymentSessionLocal = $this->app->getUserState($paymentSessionContext); $paymentSession = $this->getPaymentSession(array("session_id" => $paymentSessionLocal->session_id)); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYMENT_SESSION_OBJECT"), $this->debugType, $paymentSession->getProperties()) : null; // Validate payment session record. if (!$paymentSession->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PAYMENT_SESSION"), $this->debugType, $paymentSession->getProperties()); // Send response to the browser $response = array("success" => false, "title" => JText::_($this->textPrefix . "_FAIL"), "text" => JText::_($this->textPrefix . "_ERROR_INVALID_PROJECT")); return $response; } // Validate a reward and update the number of distributed ones. // If the user is anonymous, the system will store 0 for reward ID. // The anonymous users can't select rewards. $rewardId = $paymentSession->isAnonymous() ? 0 : (int) $paymentSession->getRewardId(); if (!empty($rewardId)) { $validData = array("reward_id" => $rewardId, "project_id" => $projectId, "txn_amount" => $amount); $reward = $this->updateReward($validData); // Validate the reward. if (!$reward) { $rewardId = 0; } } // Prepare transaction data $transactionId = new Prism\String(); $transactionId->generateRandomString(12, "BT"); $transactionId = Joomla\String\String::strtoupper($transactionId); $transactionData = array("txn_amount" => $amount, "txn_currency" => $currency->getCode(), "txn_status" => "pending", "txn_id" => $transactionId, "project_id" => $projectId, "reward_id" => $rewardId, "investor_id" => (int) $userId, "receiver_id" => (int) $project->getUserId(), "service_provider" => "Bank Transfer"); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_TRANSACTION_DATA"), $this->debugType, $transactionData) : null; // Auto complete transaction if ($this->params->get("auto_complete", 0)) { $transactionData["txn_status"] = "completed"; $project->addFunds($amount); $project->storeFunds(); } // Store transaction data $transaction = new Crowdfunding\Transaction(JFactory::getDbo()); $transaction->bind($transactionData); $transaction->store(); // Generate object of data, based on the transaction properties. $properties = $transaction->getProperties(); $result["transaction"] = Joomla\Utilities\ArrayHelper::toObject($properties); // Generate object of data, based on the project properties. $properties = $project->getProperties(); $result["project"] = Joomla\Utilities\ArrayHelper::toObject($properties); // Generate object of data, based on the reward properties. if (!empty($reward)) { $properties = $reward->getProperties(); $result["reward"] = Joomla\Utilities\ArrayHelper::toObject($properties); } // Generate data object, based on the payment session properties. $properties = $paymentSession->getProperties(); $result["payment_session"] = Joomla\Utilities\ArrayHelper::toObject($properties); // Set message to the user. $result["message"] = JText::sprintf($this->textPrefix . "_TRANSACTION_REGISTERED", $transaction->getTransactionId(), $transaction->getTransactionId()); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESULT_DATA"), $this->debugType, $result) : null; // Close payment session and remove payment session record. $txnStatus = isset($result["transaction"]->txn_status) ? $result["transaction"]->txn_status : null; $this->closePaymentSession($paymentSession, $txnStatus); return $result; }