File "woocommerce-vivawallet-gateway.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/viva-wallet-for-woocommerce/woocommerce-vivawallet-gateway.php
File size: 8.47 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

if (!defined('ABSPATH')) {
    exit;
}
define('WC_VIVAWALLET_VERSION', '1.4.3');
add_action('plugins_loaded', 'woocommerce_gateway_vivawallet_init');
function woocommerce_vivawallet_missing_wc_notice()
{
    echo '<div class="error"><p><strong>' . sprintf(esc_html__('The Viva Wallet payment gateway requires WooCommerce to work. You can download %s here.', 'viva-wallet-for-woocommerce'), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>') . '</strong></p></div>';
}
function woocommerce_gateway_vivawallet_init()
{
    load_plugin_textdomain('viva-wallet-for-woocommerce', false, plugin_basename(dirname(__FILE__)) . '/languages');
    if (!class_exists('WooCommerce')) {
        add_action('admin_notices', 'woocommerce_vivawallet_missing_wc_notice');
        return;
    }
    if (!class_exists('PGWC_Vivawallet')) {
        define('WC_VIVAWALLET_MIN_PHP_VER', '5.6.0');
        define('WC_VIVAWALLET_MIN_WC_VER', '3.0.0');
        define('WC_VIVAWALLET_FUTURE_MIN_WC_VER', '4.0');
        define('WC_VIVAWALLET_MAIN_FILE', __FILE__);
        define('WC_VIVAWALLET_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
        define('WC_VIVAWALLET_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
        class PGWC_Vivawallet
        {
            private static $instance;
            public static function get_instance()
            {
                if (null === self::$instance) {
                    self::$instance = new self();
                }
                return self::$instance;
            }
            private function __clone()
            {
            }
            private function __wakeup()
            {
            }
            private function __construct()
            {
                $this->init();
            }
            public function init()
            {
                if (is_admin()) {
                    include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/admin/class-wc-vivawallet-source.php';
                    include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/admin/vivawallet-error-page.php';
                }
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-logger.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-credentials.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/admin/vivawallet-settings.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-helper.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-refund.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-subscriptions.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-apm.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-ideal.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-p24.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-payu.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-multibanco.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-giropay.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-directpay.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-eps.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-wechatpay.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-bitpay.php';
                if (is_admin()) {
                    include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-apple-pay-register.php';
                }
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-applepay.php';
                include_once WC_VIVAWALLET_PLUGIN_PATH . '/includes/class-wc-vivawallet-endpoints.php';
                $viva_settings = get_option('woocommerce_vivawallet_native_settings', array());
                if (empty($viva_settings['version'])) {
                    $this->update_version_in_db($viva_settings, false);
                } elseif (WC_VIVAWALLET_VERSION !== $viva_settings['version']) {
                    $this->update_version_in_db($viva_settings, true);
                }
                add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
                add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
                add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
            }
            private function update_version_in_db($viva_settings, $existing)
            {
                global $wp_version;
                $active_plugins = get_option('active_plugins');
                if ($existing) {
                    $res = "VERSION OF VIVA WALLET PLUGIN WAS UPDATED \nNew version: " . WC_VIVAWALLET_VERSION . "\nOld version: " . $viva_settings['version'];
                } else {
                    $res = "VERSION OF VIVA WALLET PLUGIN WAS UPDATED \nNew version: " . WC_VIVAWALLET_VERSION;
                }
                $res .= "\nEnvironment info: \n       WordPress Version: " . $wp_version;
                if (!function_exists('get_plugins')) {
                    require_once ABSPATH . 'wp-admin/includes/plugin.php';
                }
                $all_plugins = get_plugins();
                $res .= "\nActive Plugins: ";
                foreach ($active_plugins as $plugin) {
                    $author = empty($all_plugins[$plugin]['Author']) ? 'Unknown' : $all_plugins[$plugin]['Author'];
                    $version = empty($all_plugins[$plugin]['Version']) ? 'Unknown version' : $all_plugins[$plugin]['Version'];
                    $res .= "\n       " . $all_plugins[$plugin]['Name'] . ' by ' . $author . ' - ' . $version;
                }
                WC_Vivawallet_Logger::log($res, true);
                WC_Vivawallet_Credentials::get_credentials(true);
                $viva_settings['version'] = WC_VIVAWALLET_VERSION;
                update_option('woocommerce_vivawallet_native_settings', $viva_settings);
            }
            public function add_gateways($gateways)
            {
                if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
                    $gateways[] = 'WC_Vivawallet_Payment_Gateway_Subscriptions';
                } else {
                    $gateways[] = 'WC_Vivawallet_Payment_Gateway';
                }
                $gateways[] = 'WC_Vivawallet_IDeal';
                $gateways[] = 'WC_Vivawallet_P24';
                $gateways[] = 'WC_Vivawallet_PayU';
                $gateways[] = 'WC_Vivawallet_Multibanco';
                $gateways[] = 'WC_Vivawallet_Giropay';
                $gateways[] = 'WC_Vivawallet_DirectPay';
                $gateways[] = 'WC_Vivawallet_Eps';
                $gateways[] = 'WC_Vivawallet_WeChatPay';
                $gateways[] = 'WC_Vivawallet_BitPay';
                return $gateways;
            }
            public function plugin_action_links($links)
            {
                $plugin_links = array('<a href="admin.php?page=wc-settings&tab=checkout&section=vivawallet_native">' . esc_html__('Settings', 'viva-wallet-for-woocommerce') . '</a>');
                return array_merge($plugin_links, $links);
            }
            public function plugin_row_meta($links, $file)
            {
                if (plugin_basename(__FILE__) === $file) {
                    $row_meta = array('docs' => '<a href="' . esc_url('https://docs.woocommerce.com/document/viva-wallet-for-woocommerce') . '" aria-label="' . esc_attr__('View Viva Wallet for WooCommerce plugin documentation', 'viva-wallet-for-woocommerce') . '">' . esc_html__('Documentation', 'viva-wallet-for-woocommerce') . '</a>', 'support' => '<a href="' . esc_url('mailto: [email protected]') . '" aria-label="' . esc_attr__('Get support from Viva Wallet Team', 'viva-wallet-for-woocommerce') . '">' . esc_html__('Get support', 'viva-wallet-for-woocommerce') . '</a>');
                    return array_merge($links, $row_meta);
                }
                return (array) $links;
            }
        }
        PGWC_Vivawallet::get_instance();
    }
}