<?php
/**
 * Plugin Name: YITH PayPal Payouts for WooCommerce Premium
 * Plugin URI: https://yithemes.com/themes/plugins/yith-paypal-payouts-for-woocommerce/
 * Description: <code><strong>YITH PayPal Payouts for WooCommerce</strong></code> allows you to automatically share the profits of your store with others thanks to PayPal Payouts. <a href="https://yithemes.com">Get more plugins for your e-commerce shop on <strong>YITH</strong></a>.
 * Version: 2.16.0
 * Author: YITH
 * Author URI: https://yithemes.com/
 * Text Domain: yith-paypal-payouts-for-woocommerce
 * Domain Path: /languages/
 * WC requires at least: 8.5
 * WC tested up to: 8.7
 *
 * @package YITH\PayPalPayouts
 * @version 1.6.0
 */

/*
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-3.0.txt
 */


if ( ! defined( 'ABSPATH' ) ) {
	exit;
} // Exit if accessed directly

if ( ! function_exists( 'is_plugin_active' ) ) {
	require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

/**
 * Show a notice is WooCommerce isn't enabled
 *
 * @author YITH <plugins@yithemes.com>
 * @since 1.0.
 */
function yith_payouts_install_woocommerce_admin_notice() {
	?>
	<div class="error">
		<p><?php esc_html_e( 'YITH PayPal Payouts for WooCommerce is enabled but not active. It requires WooCommerce in order to work.', 'yith-paypal-payouts-for-woocommerce' ); ?></p>
	</div>
	<?php
}

if ( ! function_exists( 'yith_plugin_onboarding_registration_hook' ) ) {
	include_once 'plugin-upgrade/functions-yith-licence.php';
}
register_activation_hook( __FILE__, 'yith_plugin_onboarding_registration_hook' );

if ( ! defined( 'YITH_PAYOUTS_VERSION' ) ) {
	define( 'YITH_PAYOUTS_VERSION', '2.16.0' );
}

if ( ! defined( 'YITH_PAYOUTS_PREMIUM' ) ) {
	define( 'YITH_PAYOUTS_PREMIUM', '1' );
}

if ( ! defined( 'YITH_PAYOUTS_DB_VERSION' ) ) {
	define( 'YITH_PAYOUTS_DB_VERSION', '1.1.0' );
}

if ( ! defined( 'YITH_PAYOUTS_INIT' ) ) {
	define( 'YITH_PAYOUTS_INIT', plugin_basename( __FILE__ ) );
}

if ( ! defined( 'YITH_PAYOUTS_FILE' ) ) {
	define( 'YITH_PAYOUTS_FILE', __FILE__ );
}

if ( ! defined( 'YITH_PAYOUTS_DIR' ) ) {
	define( 'YITH_PAYOUTS_DIR', plugin_dir_path( __FILE__ ) );
}

if ( ! defined( 'YITH_PAYOUTS_URL' ) ) {
	define( 'YITH_PAYOUTS_URL', plugins_url( '/', __FILE__ ) );
}

if ( ! defined( 'YITH_PAYOUTS_ASSETS_URL' ) ) {
	define( 'YITH_PAYOUTS_ASSETS_URL', YITH_PAYOUTS_URL . 'assets/' );
}

if ( ! defined( 'YITH_PAYOUTS_ASSETS_PATH' ) ) {
	define( 'YITH_PAYOUTS_ASSETS_PATH', YITH_PAYOUTS_DIR . 'assets/' );
}

if ( ! defined( 'YITH_PAYOUTS_TEMPLATE_PATH' ) ) {
	define( 'YITH_PAYOUTS_TEMPLATE_PATH', YITH_PAYOUTS_DIR . 'templates/' );
}

if ( ! defined( 'YITH_PAYOUTS_INC' ) ) {
	define( 'YITH_PAYOUTS_INC', YITH_PAYOUTS_DIR . 'includes/' );
}

if ( ! defined( 'YITH_PAYOUTS_SLUG' ) ) {
	define( 'YITH_PAYOUTS_SLUG', 'yith-paypal-payouts-for-woocommerce' );
}

if ( ! defined( 'YITH_PAYOUTS_SECRET_KEY' ) ) {
	define( 'YITH_PAYOUTS_SECRET_KEY', 'v93AiIDM1EvWaccSRS2G' );
}

if ( ! function_exists( 'yith_plugin_registration_hook' ) ) {
	require_once 'plugin-fw/yit-plugin-registration-hook.php';
}

register_activation_hook( __FILE__, 'yith_plugin_registration_hook' );

/* Plugin Framework Version Check */
if ( ! function_exists( 'yit_maybe_plugin_fw_loader' ) && file_exists( YITH_PAYOUTS_DIR . 'plugin-fw/init.php' ) ) {
	require_once YITH_PAYOUTS_DIR . 'plugin-fw/init.php';
}
yit_maybe_plugin_fw_loader( YITH_PAYOUTS_DIR );

if ( ! function_exists( 'YITH_PayOuts_Premium_Init' ) ) {

	/* Load  text domain */
	load_plugin_textdomain( 'yith-paypal-payouts-for-woocommerce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

	/**
	 * Unique access to instance of YITH_PayPal_Payouts class
	 *
	 * @since 1.0.0
	 */
	function YITH_PayOuts_Premium_Init() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName

		require_once 'class.yith-paypal-payouts.php';
		require_once YITH_PAYOUTS_INC . 'functions-yith-payouts-update.php';
		require_once YITH_PAYOUTS_INC . 'functions-yith-paypal-payouts.php';
		require_once YITH_PAYOUTS_INC . 'class.yith-payouts-admin.php';
		require_once YITH_PAYOUTS_INC . 'class.yith-payout.php';
		require_once YITH_PAYOUTS_INC . 'class.yith-payout-endpoint.php';
		require_once YITH_PAYOUTS_INC . 'class.yith-payouts-shortcodes.php';

		/**
		 * Load PayPal library
		 */
		require_once 'vendor/autoload.php';

		YITH_PayPal_Payouts();
	}
}

add_action( 'yith_wc_payouts_premium_init', 'YITH_PayOuts_Premium_Init' );

if ( ! function_exists( 'yith_payouts_premium_install' ) ) {
	/**
	 * Install payouts plugin
	 *
	 * @since 1.0.0
	 */
	function yith_payouts_premium_install() {

		if ( ! function_exists( 'WC' ) ) {
			add_action( 'admin_notices', 'yith_payouts_install_woocommerce_admin_notice' );
		} else {
			add_action( 'before_woocommerce_init', 'yith_wc_payouts_add_support_hpos_system' );

			do_action( 'yith_wc_payouts_premium_init' );
		}
	}
}

if ( ! function_exists( 'yith_wc_payouts_add_support_hpos_system' ) ) {
	function yith_wc_payouts_add_support_hpos_system() {
		if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {

			\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', YITH_PAYOUTS_INIT );
			\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', YITH_PAYOUTS_INIT );
		}
	}
}

add_action( 'plugins_loaded', 'yith_payouts_premium_install', 11 );

if ( ! class_exists( 'YITH_Payouts' ) ) {
	require_once YITH_PAYOUTS_INC . 'class.yith-payouts.php';
}

if ( ! class_exists( 'YITH_Payout_Items' ) ) {
	require_once YITH_PAYOUTS_INC . 'class.yith-payout-items.php';
}
register_activation_hook( YITH_PAYOUTS_FILE, 'YITH_Payout_Items::create_payouts_table' );
register_activation_hook( YITH_PAYOUTS_FILE, 'YITH_Payouts::create_payouts_table' );
