Files
AluxPay/aluxpay-payment-gateway/aluxpay-payment-gateway.php

89 lines
2.8 KiB
PHP

<?php
/**
* Plugin Name: AluxPay Payment Gateway
* Plugin URI: https://affordableluxurybags.is
* Description: AluxPay payment gateway that redirects to standalone payment website with PayPal integration
* Version: 1.1.0
* Author: ALUXB
* Author URI: https://affordableluxurybags.is
* Text Domain: aluxpay-payment-gateway
* Domain Path: /languages
* Requires at least: 5.8
* Requires PHP: 7.4
* WC requires at least: 5.0
* WC tested up to: 8.0
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
// Declare HPOS compatibility
add_action('before_woocommerce_init', function() {
if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
}
});
// Define plugin constants
define('CPG_VERSION', '1.1.0');
define('CPG_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('CPG_PLUGIN_URL', plugin_dir_url(__FILE__));
// Check if WooCommerce is active
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
/**
* Initialize the gateway
*/
add_action('plugins_loaded', 'cpg_init_gateway');
function cpg_init_gateway() {
// Make sure WooCommerce payment gateway class exists
if (!class_exists('WC_Payment_Gateway')) {
return;
}
// Include the gateway class
require_once CPG_PLUGIN_DIR . 'includes/class-aluxpay-payment-gateway.php';
// Include the return handler
require_once CPG_PLUGIN_DIR . 'includes/class-payment-return-handler.php';
/**
* Add the gateway to WooCommerce
*/
add_filter('woocommerce_payment_gateways', 'cpg_add_gateway');
function cpg_add_gateway($gateways) {
$gateways[] = 'WC_AluxPay_Payment_Gateway';
return $gateways;
}
}
/**
* Add custom action links
*/
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'cpg_action_links');
function cpg_action_links($links) {
$plugin_links = array(
'<a href="' . admin_url('admin.php?page=wc-settings&tab=checkout&section=aluxpay_payment_gateway') . '">' . __('Settings', 'aluxpay-payment-gateway') . '</a>',
);
return array_merge($plugin_links, $links);
}
} else {
/**
* WooCommerce not active notice
*/
add_action('admin_notices', 'cpg_woocommerce_missing_notice');
function cpg_woocommerce_missing_notice() {
echo '<div class="error"><p><strong>' . sprintf(
esc_html__('AluxPay Payment Gateway requires WooCommerce to be installed and active. You can download %s here.', 'aluxpay-payment-gateway'),
'<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>'
) . '</strong></p></div>';
}
}