<?php
/**
 * @version     1.3.3
 * @package     sellacious
 *
 * @copyright   Copyright (C) 2012-2017 Bhartiy Web Technologies. All rights reserved.
 * @license     SPL Sellacious Private License; see http://www.sellacious.com/spl.html
 * @author      Izhar Aazmi <info@bhartiy.com> - http://www.bhartiy.com
 */
// no direct access.
defined('_JEXEC') or die;

/**
 * Currencies list controller class.
 */
class SellaciousControllerPaymentMethods extends SellaciousControllerAdmin
{
	/**
	 * @var		string	The prefix to use with controller messages.
	 * @since	1.6
	 */
	protected $text_prefix = 'COM_SELLACIOUS_PAYMENTMETHODS';

	/**
	 * Proxy for getModel.
	 *
	 * @param  string  $name
	 * @param  string  $prefix
	 * @param  array   $config
	 *
	 * @return object
	 */
	public function getModel($name = 'PaymentMethod', $prefix = 'SellaciousModel', $config = null)
	{
		return parent::getModel($name, $prefix, array('ignore_request' => true));
	}

	/**
	 * Reload the list of installed extensions and sync the payment methods that are linked to a plugin handler
	 *
	 * @return  bool
	 */
	public function discover()
	{
		// Check for request forgeries
		JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

		try
		{
			$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false));

			// Silently ignore if the user has no access for this.
			if ($this->helper->access->check('paymentmethod.create'))
			{
				$this->helper->paymentMethod->discover();
			}
		}
		catch (Exception $e)
		{
			JLog::add($e->getMessage(), JLog::WARNING);

			return false;
		}

		return true;
	}
}
