| @@ -6,10 +6,11 @@ | ||
| 6 | 6 | * Author: PayPlug |
| 7 | 7 | * Author URI: https://www.payplug.com/ |
| 8 | 8 | * Text Domain: payplug |
| 9 | 9 | * Domain Path: /languages |
| 10 | - * Version: 2.18.0 | |
| 10 | + * Version: 3.1.0 | |
| 11 | 11 | * WC tested up to: 10.6.1 |
| 12 | + * Requires PHP: 7.4 | |
| 12 | 13 | * Requires plugins: woocommerce |
| 13 | 14 | * License: GPLv3 or later |
| 14 | 15 | * License URI: https://www.gnu.org/licenses/gpl-3.0.html |
| 15 | 16 | */ |
| @@ -20,9 +21,9 @@ | ||
| 20 | 21 | if (!defined('ABSPATH')) { |
| 21 | 22 | exit; |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | -define('PAYPLUG_GATEWAY_VERSION', '2.18.0'); | |
| 25 | +define('PAYPLUG_GATEWAY_VERSION', '3.1.0'); | |
| 25 | 26 | define('PAYPLUG_MAX_VERSION_FOR_UPGRADE', '2.16.1'); |
| 26 | 27 | define('PAYPLUG_GATEWAY_PLUGIN_DIR', plugin_dir_path(__FILE__)); |
| 27 | 28 | define('PAYPLUG_GATEWAY_PLUGIN_URL', plugin_dir_url(__FILE__)); |
| 28 | 29 | define('PAYPLUG_GATEWAY_PLUGIN_BASENAME', plugin_basename(__FILE__)); |
| @@ -38,9 +39,9 @@ | ||
| 38 | 39 | */ |
| 39 | 40 | global $mo; |
| 40 | 41 | $mo = new \MO(); |
| 41 | 42 | |
| 42 | -function init() | |
| 43 | +function init(): void | |
| 43 | 44 | { |
| 44 | 45 | if (file_exists(plugin_dir_path(__FILE__) . '/vendor/autoload.php')) { |
| 45 | 46 | require_once plugin_dir_path(__FILE__) . '/vendor/autoload.php'; |
| 46 | 47 | } |
| @@ -56,9 +57,9 @@ | ||
| 56 | 57 | $path = WP_PLUGIN_DIR . '/' . plugin_basename(dirname(__FILE__)) . '/languages/payplug-en_US.mo'; |
| 57 | 58 | $GLOBALS['mo']->import_from_file($path); |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | -function create_lock_table() | |
| 61 | +function create_lock_table(): void | |
| 61 | 62 | { |
| 62 | 63 | init(); |
| 63 | 64 | \Payplug\PayplugWoocommerce\Model\Lock::create_lock_table(); |
| 64 | 65 | } |
| @@ -66,9 +67,123 @@ | ||
| 66 | 67 | add_action('upgrader_process_complete', __NAMESPACE__ . '\\create_lock_table', 10, 2); |
| 67 | 68 | add_action('activated_plugin', __NAMESPACE__ . '\\create_lock_table', 10, 2); |
| 68 | 69 | add_action('plugins_loaded', __NAMESPACE__ . '\\init'); |
| 69 | 70 | |
| 70 | -add_action('before_woocommerce_init', function () { | |
| 71 | +/** | |
| 72 | + * ============================================================================ | |
| 73 | + * MCP (Model Context Protocol) Integration for WooCommerce | |
| 74 | + * ============================================================================ | |
| 75 | + */ | |
| 76 | + | |
| 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 | +}); | |
| 87 | + | |
| 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 { | |
| 71 | 186 | if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) { |
| 72 | 187 | \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); |
| 73 | 188 | } |
| 74 | 189 | }); |