<?php
/*
Plugin Name: Интернет-эквайринг Банк Санкт-Петербург
Plugin URI: https://www.bspb.ru/
Description: плагин для оплаты банковскими картами
Version: 2.0.0
Author: Банк Санкт-Петербург
Author URI: https://www.bspb.ru/
 */

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

spl_autoload_register(function($className) {
	if (strpos($className, 'Bspb\Pay') === 0) {
		$classPath = implode(DIRECTORY_SEPARATOR, explode('\\', substr($className,9)));
		$filePath = __DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.$classPath.'.php';
		if (is_readable($filePath) && file_exists($filePath)) require_once $filePath;
	}

    if (strpos($className, 'BspbSDK') === 0) {
        $classPath = implode(DIRECTORY_SEPARATOR, explode('\\', substr($className, 8)));
        $filePath = __DIR__ . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'BspbSDK' . DIRECTORY_SEPARATOR . $classPath . '.php';
        if (is_readable($filePath) && file_exists($filePath)) require_once $filePath;
    }
});

if(!defined('ABSPATH') || !in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) exit;
add_action( 'before_woocommerce_init', function() {
    if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
    }
} );

(\Bspb\Pay\BspbPlugin::getInstance())->run();

