<?php
/**
 * @package     CMGiftCard
 * @subpackage  plg_cmgiftcard_offline
 * @copyright   Copyright (C) 2016-2024 CMExension
 * @license     GNU General Public License version 2 or later
 */

defined('_JEXEC') or die;

require_once JPATH_ROOT . '/administrator/components/com_cmgiftcard/helpers/plugin/cmgiftcard.php';

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;

/**
 * Offline payment method for CMGiftCard.
 *
 * @package     CMGiftCard
 * @subpackage  plg_cmgiftcard_offline
 * @since       1.3.0
 */
class PlgCMGiftCardOffline extends CMGiftCardPlugin
{
	/**
	 * Constructor
	 *
	 * @param   object  &$subject  The object to observe
	 * @param   array   $config    An optional associative array of configuration settings.
	 *                             Recognized key values include 'name', 'group', 'params', 'language'
	 *                             (this list is not meant to be comprehensive).
	 *
	 * @since   1.3.0
	 */
	public function __construct(&$subject, $config = array())
	{
		$this->gatewayId = 'offline';
		$this->gatewayName = 'PLG_CMGIFTCARD_OFFLINE_NAME';

		parent::__construct($subject, $config);
	}

	/**
	 * Method to get payment form.
	 *
	 * @param   array  $data  Billing data.
	 *
	 * @return  array
	 *
	 * @since   1.3.0
	 */
	public function onCMGCGetPaymentForm($data)
	{
		$gatewayId = isset($data['billing']['payment_method']) ? $data['billing']['payment_method'] : '';

		if ($gatewayId != $this->gatewayId)
			return false;

		$message = $this->params->get('message');
		$orderNumber = $data['billing']['order_number'];

		$message = str_replace('{order_number}', $orderNumber, $message);

		@ob_start();
		include dirname(__FILE__) . '/form.php';
		$html = @ob_get_clean();

		return $html;
	}

	/**
	 * Extend abstract function.
	 *
	 * @return  boolean
	 *
	 * @since   2.1.0
	 */
	public function onCMGCValidateCallback()
	{
		return true;
	}
}
