<?php
/**
 * Base gateway implementation.
 *
 * @package Lucrativeit_Subscription_Recurring_Billing
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Shared gateway behaviour.
 */
abstract class LUCRSURE_Abstract_Gateway implements LUCRSURE_Gateway_Interface {

	/**
	 * Gateway id.
	 *
	 * @var string
	 */
	protected $id = '';

	/**
	 * Gateway title.
	 *
	 * @var string
	 */
	protected $title = '';

	/**
	 * Whether the gateway supports automatic recurring billing.
	 *
	 * @var bool
	 */
	protected $automatic_recurring = false;

	/**
	 * {@inheritDoc}
	 */
	public function get_id() {
		return $this->id;
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_title() {
		return $this->title;
	}

	/**
	 * {@inheritDoc}
	 */
	public function supports_automatic_recurring() {
		return $this->automatic_recurring;
	}

	/**
	 * Read this gateway's config from settings.
	 *
	 * @return array
	 */
	protected function config() {
		$settings = get_option( 'lucrsure_settings', array() );
		$gateways = isset( $settings['gateways'] ) ? $settings['gateways'] : array();
		return isset( $gateways[ $this->id ] ) ? $gateways[ $this->id ] : array();
	}

	/**
	 * {@inheritDoc}
	 */
	public function is_enabled() {
		$config = $this->config();
		return ! empty( $config['enabled'] );
	}
}
