| @@ -6,29 +6,28 @@ | ||
| 6 | 6 | * Author: PayPlug |
| 7 | 7 | * Author URI: https://www.payplug.com/ |
| 8 | 8 | * Text Domain: payplug |
| 9 | 9 | * Domain Path: /languages |
| 10 | - * Version: 3.0.0 | |
| 11 | - * WC tested up to: 10.6.1 | |
| 12 | - * Requires PHP: 7.4 | |
| 13 | - * Requires plugins: woocommerce | |
| 10 | + * Version: 2.9.0 | |
| 11 | + * WC tested up to: 9.3.3 | |
| 14 | 12 | * License: GPLv3 or later |
| 15 | 13 | * License URI: https://www.gnu.org/licenses/gpl-3.0.html |
| 16 | 14 | */ |
| 17 | 15 | |
| 16 | + | |
| 18 | 17 | namespace Payplug\PayplugWoocommerce; |
| 19 | 18 | |
| 20 | 19 | // Exit if accessed directly |
| 21 | -if (!defined('ABSPATH')) { | |
| 22 | - exit; | |
| 20 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 21 | + exit; | |
| 23 | 22 | } |
| 24 | 23 | |
| 25 | -define('PAYPLUG_GATEWAY_VERSION', '3.0.0'); | |
| 26 | -define('PAYPLUG_MAX_VERSION_FOR_UPGRADE', '2.16.1'); | |
| 27 | -define('PAYPLUG_GATEWAY_PLUGIN_DIR', plugin_dir_path(__FILE__)); | |
| 28 | -define('PAYPLUG_GATEWAY_PLUGIN_URL', plugin_dir_url(__FILE__)); | |
| 29 | -define('PAYPLUG_GATEWAY_PLUGIN_BASENAME', plugin_basename(__FILE__)); | |
| 30 | 24 | |
| 25 | +define( 'PAYPLUG_GATEWAY_VERSION', '2.9.0' ); | |
| 26 | +define( 'PAYPLUG_GATEWAY_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); | |
| 27 | +define( 'PAYPLUG_GATEWAY_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); | |
| 28 | +define( 'PAYPLUG_GATEWAY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); | |
| 29 | + | |
| 31 | 30 | /** |
| 32 | 31 | * Plugin bootstrap function. |
| 33 | 32 | */ |
| 34 | 33 | |
| @@ -39,158 +38,37 @@ | ||
| 39 | 38 | */ |
| 40 | 39 | global $mo; |
| 41 | 40 | $mo = new \MO(); |
| 42 | 41 | |
| 43 | -function init(): void | |
| 44 | -{ | |
| 45 | - if (file_exists(plugin_dir_path(__FILE__) . '/vendor/autoload.php')) { | |
| 46 | - require_once plugin_dir_path(__FILE__) . '/vendor/autoload.php'; | |
| 47 | - } | |
| 42 | +function init() { | |
| 43 | + if ( file_exists( plugin_dir_path( __FILE__ ) . '/vendor/autoload.php' ) ) { | |
| 44 | + require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload.php'; | |
| 45 | + } | |
| 46 | + PayplugWoocommerceHelper::load_plugin_textdomain( plugin_basename( dirname( __FILE__ ) ) . '/languages' ); | |
| 47 | + PayplugWoocommerce::get_instance(); | |
| 48 | 48 | |
| 49 | - if (file_exists(plugin_dir_path(__FILE__) . DIRECTORY_SEPARATOR . 'payplug-config.php')) { | |
| 50 | - require_once plugin_dir_path(__FILE__) . DIRECTORY_SEPARATOR . 'payplug-config.php'; | |
| 51 | - } | |
| 52 | - | |
| 53 | - PayplugWoocommerceHelper::load_plugin_textdomain(plugin_basename(dirname(__FILE__)) . '/languages'); | |
| 54 | - PayplugWoocommerce::get_instance(); | |
| 55 | - | |
| 56 | - // parse the English translation file | |
| 57 | - $path = WP_PLUGIN_DIR . '/' . plugin_basename(dirname(__FILE__)) . '/languages/payplug-en_US.mo'; | |
| 58 | - $GLOBALS['mo']->import_from_file($path); | |
| 49 | + // parse the English translation file | |
| 50 | + $path = WP_PLUGIN_DIR . '/' . plugin_basename( dirname( __FILE__ ) ) . '/languages/payplug-en_US.mo'; | |
| 51 | + $GLOBALS["mo"]->import_from_file($path); | |
| 59 | 52 | } |
| 60 | 53 | |
| 61 | -function create_lock_table(): void | |
| 62 | -{ | |
| 63 | - init(); | |
| 64 | - \Payplug\PayplugWoocommerce\Model\Lock::create_lock_table(); | |
| 54 | +function create_lock_table(){ | |
| 55 | + init(); | |
| 56 | + \Payplug\PayplugWoocommerce\Model\Lock::create_lock_table(); | |
| 65 | 57 | } |
| 66 | 58 | |
| 67 | -add_action('upgrader_process_complete', __NAMESPACE__ . '\\create_lock_table', 10, 2); | |
| 68 | -add_action('activated_plugin', __NAMESPACE__ . '\\create_lock_table', 10, 2); | |
| 69 | -add_action('plugins_loaded', __NAMESPACE__ . '\\init'); | |
| 59 | +add_action( 'upgrader_process_complete', __NAMESPACE__ . '\\create_lock_table', 10, 2 ); | |
| 60 | +add_action( 'activated_plugin', __NAMESPACE__ . '\\create_lock_table', 10, 2 ); | |
| 61 | +add_action( 'plugins_loaded', __NAMESPACE__ . '\\init' ); | |
| 70 | 62 | |
| 71 | -/** | |
| 72 | - * ============================================================================ | |
| 73 | - * MCP (Model Context Protocol) Integration for WooCommerce | |
| 74 | - * ============================================================================ | |
| 75 | - */ | |
| 63 | +add_action( 'before_woocommerce_init', function() { | |
| 64 | + if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { | |
| 65 | + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); | |
| 66 | + } | |
| 67 | +} ); | |
| 76 | 68 | |
| 77 | -// Register PayPlug ability category | |
| 78 | -add_action('wp_abilities_api_categories_init', function (): void { | |
| 79 | - wp_register_ability_category( | |
| 80 | - 'payplug', | |
| 81 | - [ | |
| 82 | - 'label' => __('PayPlug Payments', 'payplug'), | |
| 83 | - 'description' => __('Abilities for PayPlug payment processing in WooCommerce.', 'payplug'), | |
| 84 | - ] | |
| 85 | - ); | |
| 86 | -}); | |
| 69 | +register_deactivation_hook( __FILE__, __NAMESPACE__ .'\\PayplugWoocommerceHelper::plugin_deactivation' ); | |
| 87 | 70 | |
| 88 | -// Register PayPlug abilities | |
| 89 | -add_action('wp_abilities_api_init', function (): void { | |
| 90 | - wp_register_ability( | |
| 91 | - 'payplug/create-payment-link', | |
| 92 | - [ | |
| 93 | - 'label' => __('Create Payment Link', 'payplug'), | |
| 94 | - 'description' => __('Creates a payment link to send to a customer for online payment in WooCommerce.', 'payplug'), | |
| 95 | - 'category' => 'payplug', | |
| 96 | - 'input_schema' => [ | |
| 97 | - 'type' => 'object', | |
| 98 | - 'properties' => [ | |
| 99 | - 'customer' => [ | |
| 100 | - 'type' => 'object', | |
| 101 | - 'description' => __('Customer information object.', 'payplug'), | |
| 102 | - 'properties' => [ | |
| 103 | - 'customer_id' => ['type' => 'integer', 'description' => __('WooCommerce customer ID.', 'payplug')], | |
| 104 | - 'customer_address_title' => ['type' => 'string', 'description' => __('Customer civility: "mr" or "mrs".', 'payplug')], | |
| 105 | - 'customer_address_first_name' => ['type' => 'string', 'description' => __('Customer first name.', 'payplug')], | |
| 106 | - 'customer_address_last_name' => ['type' => 'string', 'description' => __('Customer last name.', 'payplug')], | |
| 107 | - 'customer_address_mobile_phone_number' => ['type' => 'string', 'description' => __('Phone number in E.164 format.', 'payplug')], | |
| 108 | - 'customer_address_email' => ['type' => 'string', 'description' => __('Customer email address.', 'payplug')], | |
| 109 | - 'customer_address_address1' => ['type' => 'string', 'description' => __('Primary street address.', 'payplug')], | |
| 110 | - 'customer_address_address2' => ['type' => 'string', 'description' => __('Secondary address line.', 'payplug')], | |
| 111 | - 'customer_address_postcode' => ['type' => 'string', 'description' => __('Postal/ZIP code.', 'payplug')], | |
| 112 | - 'customer_address_city' => ['type' => 'string', 'description' => __('City name.', 'payplug')], | |
| 113 | - 'customer_address_country' => ['type' => 'string', 'description' => __('Country ISO code (e.g., FR).', 'payplug')], | |
| 114 | - 'customer_address_language' => ['type' => 'string', 'description' => __('Language ISO code (e.g., fr).', 'payplug')], | |
| 115 | - ], | |
| 116 | - 'required' => ['customer_id', 'customer_address_email', 'customer_address_first_name', 'customer_address_last_name', 'customer_address_address1', 'customer_address_postcode', 'customer_address_city', 'customer_address_country', 'customer_address_language'], | |
| 117 | - ], | |
| 118 | - 'cart' => [ | |
| 119 | - 'type' => 'object', | |
| 120 | - 'description' => __('Shopping cart with products.', 'payplug'), | |
| 121 | - 'properties' => [ | |
| 122 | - 'products' => [ | |
| 123 | - 'type' => 'array', | |
| 124 | - 'description' => __('Array of products to add to cart.', 'payplug'), | |
| 125 | - 'items' => [ | |
| 126 | - 'type' => 'object', | |
| 127 | - 'properties' => [ | |
| 128 | - 'product_id' => ['type' => 'integer', 'description' => __('WooCommerce product ID.', 'payplug')], | |
| 129 | - 'qty' => ['type' => 'integer', 'description' => __('Quantity.', 'payplug')], | |
| 130 | - 'variation_id' => ['type' => 'integer', 'description' => __('Variation ID for variable products.', 'payplug')], | |
| 131 | - ], | |
| 132 | - 'required' => ['product_id', 'qty'], | |
| 133 | - ], | |
| 134 | - ], | |
| 135 | - ], | |
| 136 | - 'required' => ['products'], | |
| 137 | - ], | |
| 138 | - ], | |
| 139 | - 'required' => ['customer', 'cart'], | |
| 140 | - ], | |
| 141 | - 'output_schema' => [ | |
| 142 | - 'type' => 'object', | |
| 143 | - 'properties' => [ | |
| 144 | - 'result' => ['type' => 'boolean'], | |
| 145 | - 'code' => ['type' => ['integer', 'null']], | |
| 146 | - 'message' => ['type' => ['string', 'null']], | |
| 147 | - 'order_id' => ['type' => ['integer', 'null']], | |
| 148 | - 'resource_id' => ['type' => ['string', 'null']], | |
| 149 | - 'payment_url' => ['type' => ['string', 'null']], | |
| 150 | - ], | |
| 151 | - 'required' => ['result'], | |
| 152 | - ], | |
| 153 | - 'execute_callback' => function ($input) { | |
| 154 | - $mcp = new \Payplug\PayplugWoocommerce\Service\Mcp(); | |
| 155 | - | |
| 156 | - return $mcp->createByLink($input['customer'], $input['cart']); | |
| 157 | - }, | |
| 158 | - 'permission_callback' => fn () => current_user_can('manage_woocommerce'), | |
| 159 | - ] | |
| 160 | - ); | |
| 161 | -}); | |
| 162 | - | |
| 163 | -// Enable MCP integration for WooCommerce | |
| 164 | -add_filter('woocommerce_features', function ($features) { | |
| 165 | - $features['mcp_integration'] = true; | |
| 166 | - | |
| 167 | - return $features; | |
| 168 | -}); | |
| 169 | - | |
| 170 | -// Include PayPlug abilities in WooCommerce MCP Server | |
| 171 | -add_filter('woocommerce_mcp_include_ability', function ($include, $ability_id) { | |
| 172 | - if (strpos($ability_id, 'payplug/') === 0) { | |
| 173 | - return true; | |
| 174 | - } | |
| 175 | - | |
| 176 | - return $include; | |
| 177 | -}, 10, 2); | |
| 178 | - | |
| 179 | -add_filter('woocommerce_mcp_ability_permissions', function ($permissions) { | |
| 180 | - // Autorise les utilisateurs ayant la capacité de gérer WooCommerce | |
| 181 | - $permissions['payplug/create-payment-link'] = 'manage_woocommerce'; | |
| 182 | - | |
| 183 | - return $permissions; | |
| 184 | -}); | |
| 185 | -add_action('before_woocommerce_init', function (): void { | |
| 186 | - if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) { | |
| 187 | - \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); | |
| 188 | - } | |
| 189 | -}); | |
| 190 | - | |
| 191 | -register_deactivation_hook(__FILE__, __NAMESPACE__ . '\\PayplugWoocommerceHelper::plugin_deactivation'); | |
| 192 | - | |
| 193 | 71 | /** |
| 194 | 72 | * A fail-safe in case a transltion does not exist shows the default translation (English) |
| 195 | 73 | * |
| 196 | 74 | * @param $msgstr string Translated text (Usually starts with "payplug_") |
| @@ -200,15 +78,17 @@ | ||
| 200 | 78 | * @return string |
| 201 | 79 | */ |
| 202 | 80 | function wpdocs_translate_text($msgstr, $msgid, $domain) |
| 203 | 81 | { |
| 204 | - $pattern = '/^payplug_.+/'; | |
| 82 | + $pattern = '/^payplug_.+/'; | |
| 205 | 83 | |
| 206 | - if (preg_match($pattern, $msgstr) === 1) { | |
| 207 | - if (isset($GLOBALS['mo']->entries[$msgstr])) { | |
| 208 | - return $GLOBALS['mo']->entries[$msgstr]->translations[0]; | |
| 209 | - } | |
| 210 | - } | |
| 84 | + if (preg_match($pattern, $msgstr) === 1) { | |
| 85 | + if(isset($GLOBALS["mo"]->entries[$msgstr])) | |
| 86 | + return $GLOBALS["mo"]->entries[$msgstr]->translations[0]; | |
| 87 | + } | |
| 211 | 88 | |
| 212 | - return $msgstr; | |
| 89 | + return $msgstr; | |
| 213 | 90 | } |
| 214 | 91 | add_filter('gettext_payplug', __NAMESPACE__ . '\\wpdocs_translate_text', 10, 3); |
| 92 | + | |
| 93 | + | |
| 94 | + | |