PluginProbe
PayPlug for WooCommerce (Official) / trunk
PayPlug for WooCommerce (Official) vtrunk
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
payplug / payplug.php

payplug.php in PayPlug for WooCommerce (Official) trunk, at payplug.php

215 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: PayPlug pour WooCommerce (Officiel)
4 * Plugin URI: https://www.payplug.com/modules/woocommerce
5 * Description: The online payment solution combining simplicity and first-rate support to boost your sales.
6 * Author: PayPlug
7 * Author URI: https://www.payplug.com/
8 * Text Domain: payplug
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
14 * License: GPLv3 or later
15 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
16 */
17
18 namespace Payplug\PayplugWoocommerce;
19
20 // Exit if accessed directly
21 if (!defined('ABSPATH')) {
22 exit;
23 }
24
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
31 /**
32 * Plugin bootstrap function.
33 */
34
35 /**
36 * $mo is the Mo object used to parse the English translations
37 *
38 * @var \MO
39 */
40 global $mo;
41 $mo = new \MO();
42
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 }
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);
59 }
60
61 function create_lock_table(): void
62 {
63 init();
64 \Payplug\PayplugWoocommerce\Model\Lock::create_lock_table();
65 }
66
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');
70
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 {
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 /**
194 * A fail-safe in case a transltion does not exist shows the default translation (English)
195 *
196 * @param $msgstr string Translated text (Usually starts with "payplug_")
197 * @param $msgid string Text to translate (irrelevant because it is equal to $msgstr in this case)
198 * @param $domain string the domain is always = "payplug" (filter "gettext_payplug" is only for payplug translation domain)
199 *
200 * @return string
201 */
202 function wpdocs_translate_text($msgstr, $msgid, $domain)
203 {
204 $pattern = '/^payplug_.+/';
205
206 if (preg_match($pattern, $msgstr) === 1) {
207 if (isset($GLOBALS['mo']->entries[$msgstr])) {
208 return $GLOBALS['mo']->entries[$msgstr]->translations[0];
209 }
210 }
211
212 return $msgstr;
213 }
214 add_filter('gettext_payplug', __NAMESPACE__ . '\\wpdocs_translate_text', 10, 3);
215