1 | <?php |
||||||||
2 | /** |
||||||||
3 | * Plugin Name: Pagantis |
||||||||
4 | * Plugin URI: https://www.pagantis.com/ |
||||||||
5 | * Description: Adds Pagantis as payment method to WooCommerce. |
||||||||
6 | * Version: 8.3.7 |
||||||||
7 | * Author: Pagantis |
||||||||
8 | * Domain Path: /languages |
||||||||
9 | * WC requires at least: 3.0 |
||||||||
10 | */ |
||||||||
11 | |||||||||
12 | //namespace Gateways; |
||||||||
13 | |||||||||
14 | |||||||||
15 | if (! defined('ABSPATH')) { |
||||||||
16 | exit; |
||||||||
17 | } |
||||||||
18 | define('PAGANTIS_VERSION', '8.3.7'); |
||||||||
19 | |||||||||
20 | define('PAGANTIS_WC_MAIN_FILE', __FILE__); |
||||||||
21 | define( |
||||||||
22 | 'PAGANTIS_PLUGIN_URL', |
||||||||
23 | untrailingslashit(plugins_url(basename(plugin_dir_path(PAGANTIS_WC_MAIN_FILE)), basename(PAGANTIS_WC_MAIN_FILE))) |
||||||||
0 ignored issues
–
show
Bug
introduced
by
![]() The function
plugins_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The function
untrailingslashit was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
24 | ); |
||||||||
25 | define('PAGANTIS_PLUGIN_PATH', untrailingslashit(plugin_dir_path(PAGANTIS_WC_MAIN_FILE))); |
||||||||
26 | define('PAGANTIS_ORDERS_TABLE', 'cart_process'); |
||||||||
27 | define('PAGANTIS_WC_ORDERS_TABLE', 'posts'); |
||||||||
28 | define('PAGANTIS_LOGS_TABLE', 'pagantis_logs'); |
||||||||
29 | define('PAGANTIS_NOT_CONFIRMED_MESSAGE', 'No se ha podido confirmar el pago'); |
||||||||
30 | define('PAGANTIS_CONFIG_TABLE', 'pagantis_config'); |
||||||||
31 | define('PAGANTIS_CONCURRENCY_TABLE', 'pagantis_concurrency'); |
||||||||
32 | define('PAGANTIS_GIT_HUB_URL', 'https://github.com/pagantis/woocommerce'); |
||||||||
33 | define('PAGANTIS_DOC_URL', 'https://developer.pagantis.com'); |
||||||||
34 | define('PAGANTIS_SUPPORT_EMAIL', 'mailto:[email protected]?Subject=woocommerce_plugin'); |
||||||||
35 | define('PAGANTIS_PLUGIN_ID', 'pagantis'); |
||||||||
36 | |||||||||
37 | |||||||||
38 | class WC_Pagantis_Plugin |
||||||||
39 | { |
||||||||
40 | |||||||||
41 | |||||||||
42 | /** |
||||||||
43 | * The reference the *Singleton* instance of this class. |
||||||||
44 | * |
||||||||
45 | * @var $instance |
||||||||
0 ignored issues
–
show
|
|||||||||
46 | */ |
||||||||
47 | private static $instance; |
||||||||
48 | |||||||||
49 | |||||||||
50 | /** |
||||||||
51 | * @var array $defaultConfig |
||||||||
52 | */ |
||||||||
53 | private $defaultConfig; |
||||||||
0 ignored issues
–
show
|
|||||||||
54 | |||||||||
55 | /** |
||||||||
56 | * @var array $extraConfig |
||||||||
57 | */ |
||||||||
58 | private $extraConfig; |
||||||||
59 | |||||||||
60 | |||||||||
61 | /** |
||||||||
62 | * WC_Pagantis constructor. |
||||||||
63 | */ |
||||||||
64 | public function __construct() |
||||||||
65 | { |
||||||||
66 | require_once(plugin_dir_path(__FILE__) . 'vendor/autoload.php'); |
||||||||
0 ignored issues
–
show
The function
plugin_dir_path was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
67 | require_once dirname(__FILE__) . '/includes/class-wc-pagantis-config.php'; |
||||||||
68 | require_once dirname(__FILE__) . '/includes/functions.php'; |
||||||||
69 | |||||||||
70 | $this->template_path = plugin_dir_path(__FILE__) . 'templates/'; |
||||||||
0 ignored issues
–
show
|
|||||||||
71 | |||||||||
72 | $this->prepare_wpdb_tables(); |
||||||||
73 | $this->initialConfig = WC_Pagantis_Config::getDefaultConfig(); |
||||||||
0 ignored issues
–
show
|
|||||||||
74 | |||||||||
75 | $this->extraConfig = WC_Pagantis_Config::getExtraConfig(); |
||||||||
76 | add_action('plugins_loaded', array($this, 'bootstrap')); |
||||||||
0 ignored issues
–
show
The function
add_action was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
77 | load_plugin_textdomain('pagantis', false, basename(dirname(__FILE__)) . '/languages'); |
||||||||
0 ignored issues
–
show
The function
load_plugin_textdomain was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
78 | add_filter('woocommerce_payment_gateways', array($this, 'add_pagantis_gateway')); |
||||||||
0 ignored issues
–
show
The function
add_filter was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
79 | add_filter('woocommerce_available_payment_gateways', array($this, 'check_if_pg_is_in_available_gateways'), 9999); |
||||||||
80 | add_filter('plugin_row_meta', array($this, 'get_plugin_row_meta_links'), 10, 2); |
||||||||
81 | add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'get_plugin_action_links')); |
||||||||
0 ignored issues
–
show
The function
plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
82 | |||||||||
83 | add_action('wp_enqueue_scripts', 'add_pagantis_widget_js'); |
||||||||
84 | add_action('rest_api_init', array($this, 'register_pg_rest_routes')); //Endpoint |
||||||||
85 | add_filter('load_textdomain_mofile', array($this, 'loadPagantisTranslation'), 10, 2); |
||||||||
86 | register_activation_hook(__FILE__, array($this, 'prepare_wpdb_tables')); |
||||||||
0 ignored issues
–
show
The function
register_activation_hook was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
87 | add_action('woocommerce_product_options_general_product_data', array($this, 'pagantisPromotedProductTpl')); |
||||||||
88 | add_action('woocommerce_process_product_meta', array($this, 'pagantisPromotedVarSave')); |
||||||||
89 | add_action('woocommerce_product_bulk_edit_start', array($this, 'pagantis_promoted_bulk_template')); |
||||||||
90 | add_action('woocommerce_product_bulk_edit_save', array($this, 'save_pg_promoted_bulk_template')); |
||||||||
91 | add_action('woocommerce_after_add_to_cart_form', array($this, 'pagantisAddProductSimulator')); |
||||||||
92 | //add_action('wp_enqueue_scripts', array($this, 'enqueue_simulator_scripts')); |
||||||||
93 | } |
||||||||
94 | |||||||||
95 | /** |
||||||||
96 | * Returns the *Singleton* instance of this class. |
||||||||
97 | * |
||||||||
98 | * @return self::$instance The *Singleton* instance. |
||||||||
99 | */ |
||||||||
100 | public static function get_instance() |
||||||||
101 | { |
||||||||
102 | if (null === self::$instance) { |
||||||||
103 | self::$instance = new self(); |
||||||||
104 | } |
||||||||
105 | |||||||||
106 | return self::$instance; |
||||||||
107 | } |
||||||||
108 | |||||||||
109 | /** |
||||||||
110 | * Private clone method to prevent cloning of the instance of the |
||||||||
111 | * *Singleton* instance. |
||||||||
112 | * |
||||||||
113 | * @return void |
||||||||
114 | */ |
||||||||
115 | private function __clone() |
||||||||
116 | { |
||||||||
117 | } |
||||||||
118 | |||||||||
119 | /** |
||||||||
120 | * Private unserialize method to prevent unserializing of the *Singleton* |
||||||||
121 | * instance. |
||||||||
122 | * |
||||||||
123 | * @return void |
||||||||
124 | */ |
||||||||
125 | private function __wakeup() |
||||||||
126 | { |
||||||||
127 | } |
||||||||
128 | |||||||||
129 | public function bootstrap() |
||||||||
130 | { |
||||||||
131 | try { |
||||||||
132 | $this->check_dependencies(); |
||||||||
133 | } catch (Exception $e) { |
||||||||
134 | $e->getMessage(); |
||||||||
135 | } |
||||||||
136 | } |
||||||||
137 | |||||||||
138 | /** |
||||||||
139 | * @throws Exception |
||||||||
140 | */ |
||||||||
141 | public function check_dependencies() |
||||||||
142 | { |
||||||||
143 | if (version_compare(WC()->version, '3.0', '<')) { |
||||||||
0 ignored issues
–
show
The function
WC was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
144 | throw new Exception(__('Pagantis requires WooCommerce version 3.0 or greater', 'pagantis')); |
||||||||
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
145 | } |
||||||||
146 | |||||||||
147 | if (! function_exists('curl_init')) { |
||||||||
148 | throw new Exception(__('Pagantis requires cURL to be installed on your server', 'pagantis')); |
||||||||
149 | } |
||||||||
150 | if (! version_compare(phpversion(), '5.3.0', '>=')) { |
||||||||
151 | throw new Exception(__('Pagantis requires PHP 5.3 or greater to be installed on your server', 'pagantis')); |
||||||||
152 | } |
||||||||
153 | } |
||||||||
154 | |||||||||
155 | /** |
||||||||
156 | * Piece of html code to insert into BULK admin edit |
||||||||
157 | */ |
||||||||
158 | public function pagantis_promoted_bulk_template() |
||||||||
159 | { |
||||||||
160 | echo '<div class="inline-edit-group"> |
||||||||
161 | <label class="alignleft"> |
||||||||
162 | <span class="title">Pagantis promoted</span> |
||||||||
163 | <span class="input-text-wrap"> |
||||||||
164 | <input type="checkbox" id="pagantis_promoted" name="pagantis_promoted"/> |
||||||||
165 | </span> |
||||||||
166 | </label> |
||||||||
167 | </div>'; |
||||||||
168 | } |
||||||||
169 | |||||||||
170 | /** |
||||||||
171 | * Php code to save our meta after a bulk admin edit |
||||||||
172 | * |
||||||||
173 | * @param $product |
||||||||
174 | */ |
||||||||
175 | public function save_pg_promoted_bulk_template($product) |
||||||||
176 | { |
||||||||
177 | $post_id = $product->get_id(); |
||||||||
178 | $pagantis_promoted_value = $_REQUEST['pagantis_promoted']; |
||||||||
179 | if ($pagantis_promoted_value === 'on') { |
||||||||
180 | $pagantis_promoted_value = 'yes'; |
||||||||
181 | } else { |
||||||||
182 | $pagantis_promoted_value = 'no'; |
||||||||
183 | } |
||||||||
184 | |||||||||
185 | update_post_meta($post_id, 'custom_product_pagantis_promoted', esc_attr($pagantis_promoted_value)); |
||||||||
0 ignored issues
–
show
The function
esc_attr was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The function
update_post_meta was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
186 | } |
||||||||
187 | |||||||||
188 | /** |
||||||||
189 | * Piece of html code to insert into PRODUCT admin edit |
||||||||
190 | */ |
||||||||
191 | public function pagantisPromotedProductTpl() |
||||||||
192 | { |
||||||||
193 | global $post; |
||||||||
194 | $_product = get_post_meta($post->ID); |
||||||||
0 ignored issues
–
show
The function
get_post_meta was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
195 | woocommerce_wp_checkbox(array( |
||||||||
0 ignored issues
–
show
The function
woocommerce_wp_checkbox was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
196 | 'id' => 'pagantis_promoted', |
||||||||
197 | 'label' => __('Pagantis promoted', 'woocommerce'), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch |
||||||||
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
198 | 'value' => $_product['custom_product_pagantis_promoted']['0'], |
||||||||
199 | 'cbvalue' => 'yes', |
||||||||
200 | 'echo' => true, |
||||||||
201 | )); |
||||||||
202 | } |
||||||||
203 | |||||||||
204 | /** |
||||||||
205 | * Php code to save our meta after a PRODUCT admin edit |
||||||||
206 | * |
||||||||
207 | * @param $post_id |
||||||||
208 | */ |
||||||||
209 | public function pagantisPromotedVarSave($post_id) |
||||||||
210 | { |
||||||||
211 | $pagantis_promoted_value = $_POST['pagantis_promoted']; |
||||||||
212 | if ($pagantis_promoted_value === null) { |
||||||||
213 | $pagantis_promoted_value = 'no'; |
||||||||
214 | } |
||||||||
215 | update_post_meta($post_id, 'custom_product_pagantis_promoted', esc_attr($pagantis_promoted_value)); |
||||||||
0 ignored issues
–
show
The function
esc_attr was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The function
update_post_meta was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
216 | } |
||||||||
217 | |||||||||
218 | /* |
||||||||
219 | * Replace 'textdomain' with your plugin's textdomain. e.g. 'woocommerce'. |
||||||||
220 | * File to be named, for example, yourtranslationfile-en_GB.mo |
||||||||
221 | * File to be placed, for example, wp-content/languages/textdomain/yourtranslationfile-en_GB.mo |
||||||||
222 | */ |
||||||||
223 | public function loadPagantisTranslation($mofile, $domain) |
||||||||
224 | { |
||||||||
225 | if ('pagantis' === $domain) { |
||||||||
226 | $mofile = WP_LANG_DIR . '/../plugins/pagantis/languages/pagantis-' . get_locale() . '.mo'; |
||||||||
0 ignored issues
–
show
The function
get_locale was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
227 | } |
||||||||
228 | |||||||||
229 | return $mofile; |
||||||||
230 | } |
||||||||
231 | |||||||||
232 | /** |
||||||||
233 | * Sql table |
||||||||
234 | */ |
||||||||
235 | public function prepare_wpdb_tables() |
||||||||
236 | { |
||||||||
237 | global $wpdb; |
||||||||
238 | |||||||||
239 | $tableName = $wpdb->prefix . PAGANTIS_CONCURRENCY_TABLE; |
||||||||
240 | if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") !== $tableName) { |
||||||||
241 | $charset_collate = $wpdb->get_charset_collate(); |
||||||||
242 | $sql = "CREATE TABLE $tableName ( order_id int NOT NULL, |
||||||||
243 | createdAt timestamp DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY id (order_id)) $charset_collate"; |
||||||||
244 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
||||||||
0 ignored issues
–
show
|
|||||||||
245 | dbDelta($sql); |
||||||||
0 ignored issues
–
show
The function
dbDelta was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
246 | } |
||||||||
247 | |||||||||
248 | $tableName = $wpdb->prefix . PAGANTIS_CONFIG_TABLE; |
||||||||
249 | |||||||||
250 | //Check if table exists |
||||||||
251 | $tableExists = $wpdb->get_var("SHOW TABLES LIKE '$tableName'") !== $tableName; |
||||||||
252 | if ($tableExists) { |
||||||||
253 | $charset_collate = $wpdb->get_charset_collate(); |
||||||||
254 | $sql = "CREATE TABLE IF NOT EXISTS $tableName ( |
||||||||
255 | id int NOT NULL AUTO_INCREMENT, |
||||||||
256 | config varchar(60) NOT NULL, |
||||||||
257 | value varchar(1000) NOT NULL, |
||||||||
258 | UNIQUE KEY id(id)) $charset_collate"; |
||||||||
259 | |||||||||
260 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
||||||||
261 | dbDelta($sql); |
||||||||
262 | } else { |
||||||||
263 | //Updated value field to adapt to new length < v8.0.1 |
||||||||
264 | $query = "select COLUMN_TYPE FROM information_schema.COLUMNS where TABLE_NAME='$tableName' AND COLUMN_NAME='value'"; |
||||||||
265 | $results = $wpdb->get_results($query, ARRAY_A); |
||||||||
0 ignored issues
–
show
|
|||||||||
266 | if ($results['0']['COLUMN_TYPE'] === 'varchar(100)') { |
||||||||
267 | $sql = "ALTER TABLE $tableName MODIFY value varchar(1000)"; |
||||||||
268 | $wpdb->query($sql); |
||||||||
269 | } |
||||||||
270 | |||||||||
271 | //Adapting selector to array < v8.1.1 |
||||||||
272 | $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR' |
||||||||
273 | or config='PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'"; |
||||||||
274 | $dbCurrentConfig = $wpdb->get_results($query, ARRAY_A); |
||||||||
275 | foreach ($dbCurrentConfig as $item) { |
||||||||
276 | if ($item['config'] === 'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR') { |
||||||||
277 | $css_price_selector = $this->preparePriceSelector($item['value']); |
||||||||
278 | if ($item['value'] !== $css_price_selector) { |
||||||||
279 | $wpdb->update( |
||||||||
280 | $tableName, |
||||||||
281 | array('value' => stripslashes($css_price_selector)), |
||||||||
282 | array('config' => 'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'), |
||||||||
283 | array('%s'), |
||||||||
284 | array('%s') |
||||||||
285 | ); |
||||||||
286 | } |
||||||||
287 | } elseif ($item['config'] === 'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR') { |
||||||||
288 | $css_quantity_selector = $this->prepareQuantitySelector($item['value']); |
||||||||
289 | if ($item['value'] !== $css_quantity_selector) { |
||||||||
290 | $wpdb->update( |
||||||||
291 | $tableName, |
||||||||
292 | array('value' => stripslashes($css_quantity_selector)), |
||||||||
293 | array('config' => 'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'), |
||||||||
294 | array('%s'), |
||||||||
295 | array('%s') |
||||||||
296 | ); |
||||||||
297 | } |
||||||||
298 | } |
||||||||
299 | } |
||||||||
300 | } |
||||||||
301 | |||||||||
302 | //Adapting selector to array < v8.2.2 |
||||||||
303 | $tableName = $wpdb->prefix . PAGANTIS_CONFIG_TABLE; |
||||||||
304 | $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'"; |
||||||||
305 | $results = $wpdb->get_results($query, ARRAY_A); |
||||||||
306 | if (count($results) === 0) { |
||||||||
307 | $wpdb->insert( |
||||||||
308 | $tableName, |
||||||||
309 | array('config' => 'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR', 'value' => '.'), |
||||||||
310 | array('%s', '%s') |
||||||||
311 | ); |
||||||||
312 | $wpdb->insert( |
||||||||
313 | $tableName, |
||||||||
314 | array('config' => 'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR', 'value' => ','), |
||||||||
315 | array('%s', '%s') |
||||||||
316 | ); |
||||||||
317 | } |
||||||||
318 | |||||||||
319 | //Adding new selector < v8.3.0 |
||||||||
320 | $tableName = $wpdb->prefix . PAGANTIS_CONFIG_TABLE; |
||||||||
321 | $query = "select * from $tableName where config='PAGANTIS_DISPLAY_MAX_AMOUNT'"; |
||||||||
322 | $results = $wpdb->get_results($query, ARRAY_A); |
||||||||
323 | if (count($results) === 0) { |
||||||||
324 | $wpdb->insert($tableName, array('config' => 'PAGANTIS_DISPLAY_MAX_AMOUNT', 'value' => '0'), array('%s', '%s')); |
||||||||
325 | } |
||||||||
326 | |||||||||
327 | //Adding new selector < v8.3.2 |
||||||||
328 | $tableName = $wpdb->prefix . PAGANTIS_CONFIG_TABLE; |
||||||||
329 | $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_DISPLAY_SITUATION'"; |
||||||||
330 | $results = $wpdb->get_results($query, ARRAY_A); |
||||||||
331 | if (count($results) === 0) { |
||||||||
332 | $wpdb->insert( |
||||||||
333 | $tableName, |
||||||||
334 | array('config' => 'PAGANTIS_SIMULATOR_DISPLAY_SITUATION', 'value' => 'default'), |
||||||||
335 | array('%s', '%s') |
||||||||
336 | ); |
||||||||
337 | $wpdb->insert( |
||||||||
338 | $tableName, |
||||||||
339 | array('config' => 'PAGANTIS_SIMULATOR_SELECTOR_VARIATION', 'value' => 'default'), |
||||||||
340 | array('%s', '%s') |
||||||||
341 | ); |
||||||||
342 | } |
||||||||
343 | |||||||||
344 | //Adding new selector < v8.3.3 |
||||||||
345 | $tableName = $wpdb->prefix . PAGANTIS_CONFIG_TABLE; |
||||||||
346 | $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_DISPLAY_TYPE_CHECKOUT'"; |
||||||||
347 | $results = $wpdb->get_results($query, ARRAY_A); |
||||||||
348 | if (count($results) === 0) { |
||||||||
349 | $wpdb->insert($tableName, array( |
||||||||
350 | 'config' => 'PAGANTIS_SIMULATOR_DISPLAY_TYPE_CHECKOUT', |
||||||||
351 | 'value' => 'sdk.simulator.types.CHECKOUT_PAGE', |
||||||||
352 | ), array('%s', '%s')); |
||||||||
353 | $wpdb->update( |
||||||||
354 | $tableName, |
||||||||
355 | array('value' => 'sdk.simulator.types.PRODUCT_PAGE'), |
||||||||
356 | array('config' => 'PAGANTIS_SIMULATOR_DISPLAY_TYPE'), |
||||||||
357 | array('%s'), |
||||||||
358 | array('%s') |
||||||||
359 | ); |
||||||||
360 | } |
||||||||
361 | |||||||||
362 | //Adapting to variable selector < v8.3.6 |
||||||||
363 | $variableSelector = 'div.summary div.woocommerce-variation.single_variation > div.woocommerce-variation-price span.price'; |
||||||||
364 | $tableName = $wpdb->prefix . PAGANTIS_CONFIG_TABLE; |
||||||||
365 | $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_SELECTOR_VARIATION' and value='default'"; |
||||||||
366 | $results = $wpdb->get_results($query, ARRAY_A); |
||||||||
367 | if (count($results) === 0) { |
||||||||
368 | $wpdb->update( |
||||||||
369 | $tableName, |
||||||||
370 | array('value' => $variableSelector), |
||||||||
371 | array('config' => 'PAGANTIS_SIMULATOR_SELECTOR_VARIATION'), |
||||||||
372 | array('%s'), |
||||||||
373 | array('%s') |
||||||||
374 | ); |
||||||||
375 | } |
||||||||
376 | |||||||||
377 | $dbConfigs = $wpdb->get_results("select * from $tableName", ARRAY_A); |
||||||||
378 | |||||||||
379 | // Convert a multiple dimension array for SQL insert statements into a simple key/value |
||||||||
380 | $simpleDbConfigs = array(); |
||||||||
381 | foreach ($dbConfigs as $config) { |
||||||||
382 | $simpleDbConfigs[$config['config']] = $config['value']; |
||||||||
383 | } |
||||||||
384 | $newConfigs = array_diff_key(WC_Pagantis_Config::getDefaultConfig(), $simpleDbConfigs); |
||||||||
385 | if (! empty($newConfigs)) { |
||||||||
386 | foreach ($newConfigs as $key => $value) { |
||||||||
387 | $wpdb->insert($tableName, array('config' => $key, 'value' => $value), array('%s', '%s')); |
||||||||
388 | } |
||||||||
389 | } |
||||||||
390 | |||||||||
391 | //Current plugin config: pagantis_public_key => New field --- public_key => Old field |
||||||||
392 | $settings = get_option('woocommerce_pagantis_settings'); |
||||||||
0 ignored issues
–
show
The function
get_option was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
393 | |||||||||
394 | if (! isset($settings['pagantis_public_key']) && $settings['public_key']) { |
||||||||
395 | $settings['pagantis_public_key'] = $settings['public_key']; |
||||||||
396 | unset($settings['public_key']); |
||||||||
397 | } |
||||||||
398 | |||||||||
399 | if (! isset($settings['pagantis_private_key']) && $settings['secret_key']) { |
||||||||
400 | $settings['pagantis_private_key'] = $settings['secret_key']; |
||||||||
401 | unset($settings['secret_key']); |
||||||||
402 | } |
||||||||
403 | |||||||||
404 | update_option('woocommerce_pagantis_settings', $settings); |
||||||||
0 ignored issues
–
show
The function
update_option was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
405 | } |
||||||||
406 | |||||||||
407 | |||||||||
408 | public function enqueue_simulator_scripts() |
||||||||
409 | { |
||||||||
410 | if (! pg_isPluginActive()) { |
||||||||
411 | return; |
||||||||
412 | } |
||||||||
413 | |||||||||
414 | wp_register_script( |
||||||||
0 ignored issues
–
show
The function
wp_register_script was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
415 | 'pagantis-simulator', |
||||||||
416 | plugins_url('assets/js/pagantis-simulator.js', PAGANTIS_PLUGIN_ID), |
||||||||
0 ignored issues
–
show
The function
plugins_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
417 | array('jquery'), |
||||||||
418 | '' |
||||||||
419 | ); |
||||||||
420 | wp_enqueue_script('pagantis-simulator'); |
||||||||
0 ignored issues
–
show
The function
wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
421 | |||||||||
422 | global $product; |
||||||||
423 | |||||||||
424 | pg_canProductSimulatorLoad(); |
||||||||
425 | $locale = pg_GetLocaleString(); |
||||||||
426 | $settings = pg_get_plugin_settings(); |
||||||||
427 | |||||||||
428 | $post_id = $product->get_id(); |
||||||||
429 | $simulator_localized_params = array( |
||||||||
430 | 'total' => is_numeric($product->get_price()) ? $product->get_price() : 0, |
||||||||
431 | 'public_key' => $settings['pagantis_public_key'], |
||||||||
432 | 'simulator_type' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_DISPLAY_TYPE'), |
||||||||
433 | 'positionSelector' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'), |
||||||||
434 | 'quantitySelector' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR', true), |
||||||||
435 | 'priceSelector' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR', true), |
||||||||
436 | 'totalAmount' => is_numeric($product->get_price()) ? $product->get_price() : 0, |
||||||||
437 | 'locale' => $locale, |
||||||||
438 | 'country' => $locale, |
||||||||
439 | 'isProductPromoted' => pg_isProductPromoted($post_id), |
||||||||
440 | 'promotedMessage' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_PROMOTION_EXTRA'), |
||||||||
441 | 'thousandSeparator' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'), |
||||||||
442 | 'decimalSeparator' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'), |
||||||||
443 | 'pagantisQuotesStart' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_START_INSTALLMENTS'), |
||||||||
444 | 'pagantisSimulatorSkin' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_DISPLAY_SKIN'), |
||||||||
445 | 'pagantisSimulatorPosition' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'), |
||||||||
446 | 'finalDestination' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_DISPLAY_SITUATION'), |
||||||||
447 | 'variationSelector' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_SIMULATOR_SELECTOR_VARIATION'), |
||||||||
448 | 'productType' => $product->get_type(), |
||||||||
449 | ); |
||||||||
450 | |||||||||
451 | wp_localize_script('pagantis-simulator', 'pg_sim_params', $simulator_localized_params); |
||||||||
0 ignored issues
–
show
The function
wp_localize_script was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
452 | |||||||||
453 | wp_enqueue_script('pg_sim_params'); |
||||||||
454 | } |
||||||||
455 | |||||||||
456 | |||||||||
457 | /** |
||||||||
458 | * Product simulator |
||||||||
459 | */ |
||||||||
460 | public function addProductSimulatorTemplate() |
||||||||
461 | { |
||||||||
462 | global $product; |
||||||||
463 | |||||||||
464 | pg_canProductSimulatorLoad(); |
||||||||
465 | |||||||||
466 | $post_id = $product->get_id(); |
||||||||
467 | $template_arguments = array( |
||||||||
468 | 'isProductPromoted' => pg_isProductPromoted($post_id), |
||||||||
469 | 'promotedMessage' => WC_Pagantis_Config::getValueOfKey('PAGANTIS_PROMOTION_EXTRA'), |
||||||||
470 | ); |
||||||||
471 | |||||||||
472 | wc_get_template('product_simulator.php', $template_arguments, '', $this->template_path); |
||||||||
0 ignored issues
–
show
The function
wc_get_template was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
473 | } |
||||||||
474 | |||||||||
475 | /** |
||||||||
476 | * Product simulator |
||||||||
477 | * |
||||||||
478 | * @global WC_Product $product Product object. |
||||||||
479 | */ |
||||||||
480 | public function pagantisAddProductSimulator() |
||||||||
481 | { |
||||||||
482 | global $product; |
||||||||
483 | |||||||||
484 | $cfg = get_option('woocommerce_pagantis_settings'); |
||||||||
0 ignored issues
–
show
The function
get_option was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
485 | $locale = strtolower(strstr(get_locale(), '_', true)); |
||||||||
0 ignored issues
–
show
The function
get_locale was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
486 | $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); |
||||||||
487 | $allowedCountry = (in_array(strtolower($locale), $allowedCountries)); |
||||||||
488 | $minAmount = $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT']; |
||||||||
489 | $maxAmount = $this->extraConfig['PAGANTIS_DISPLAY_MAX_AMOUNT']; |
||||||||
490 | $totalPrice = $product->get_price(); |
||||||||
491 | $validAmount = ($totalPrice >= $minAmount && ($totalPrice <= $maxAmount || $maxAmount === '0')); |
||||||||
492 | if ($cfg['enabled'] !== 'yes' || $cfg['pagantis_public_key'] === '' || $cfg['pagantis_private_key'] === '' |
||||||||
493 | || $cfg['simulator'] !== 'yes' |
||||||||
494 | || ! $allowedCountry |
||||||||
495 | || ! $validAmount |
||||||||
496 | ) { |
||||||||
497 | return; |
||||||||
498 | } |
||||||||
499 | |||||||||
500 | $post_id = $product->get_id(); |
||||||||
501 | $template_fields = array( |
||||||||
502 | 'total' => is_numeric($product->get_price()) ? $product->get_price() : 0, |
||||||||
503 | 'public_key' => $cfg['pagantis_public_key'], |
||||||||
504 | 'simulator_type' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'], |
||||||||
505 | 'positionSelector' => $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'], |
||||||||
506 | 'quantitySelector' => unserialize($this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']), |
||||||||
507 | 'priceSelector' => unserialize($this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']), |
||||||||
508 | 'totalAmount' => is_numeric($product->get_price()) ? $product->get_price() : 0, |
||||||||
509 | 'locale' => $locale, |
||||||||
510 | 'country' => $locale, |
||||||||
511 | 'promoted' => pg_isProductPromoted($post_id), |
||||||||
512 | 'promotedMessage' => $this->extraConfig['PAGANTIS_PROMOTION_EXTRA'], |
||||||||
513 | 'thousandSeparator' => $this->extraConfig['PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'], |
||||||||
514 | 'decimalSeparator' => $this->extraConfig['PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'], |
||||||||
515 | 'pagantisQuotesStart' => $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'], |
||||||||
516 | 'pagantisSimulatorSkin' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'], |
||||||||
517 | 'pagantisSimulatorPosition' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'], |
||||||||
518 | 'finalDestination' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SITUATION'], |
||||||||
519 | 'variationSelector' => $this->extraConfig['PAGANTIS_SIMULATOR_SELECTOR_VARIATION'], |
||||||||
520 | 'productType' => $product->get_type(), |
||||||||
521 | ); |
||||||||
522 | WC_Pagantis_Logger::insert_log_entry_in_wpdb($template_fields); |
||||||||
523 | wc_get_template('product_simulator.php', $template_fields, '', $this->template_path); |
||||||||
0 ignored issues
–
show
The function
wc_get_template was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
524 | } |
||||||||
525 | |||||||||
526 | |||||||||
527 | /** |
||||||||
528 | * Add Pagantis to payments list. |
||||||||
529 | * |
||||||||
530 | * @param $methods |
||||||||
531 | * |
||||||||
532 | * @return array |
||||||||
533 | * @hook woocommerce_payment_gateways |
||||||||
534 | */ |
||||||||
535 | public function add_pagantis_gateway($methods) |
||||||||
536 | { |
||||||||
537 | if (! class_exists('WC_Payment_Gateway')) { |
||||||||
538 | return $methods; |
||||||||
539 | } |
||||||||
540 | |||||||||
541 | include_once('controllers/class-wc-pagantis-gateway.php'); |
||||||||
542 | $methods[] = 'WC_Pagantis_Gateway'; |
||||||||
543 | |||||||||
544 | return $methods; |
||||||||
545 | } |
||||||||
546 | |||||||||
547 | /** |
||||||||
548 | * Initialize WC_Pagantis class |
||||||||
549 | * |
||||||||
550 | * @param $methods |
||||||||
551 | * |
||||||||
552 | * @return mixed |
||||||||
553 | */ |
||||||||
554 | public function check_if_pg_is_in_available_gateways($methods) |
||||||||
555 | { |
||||||||
556 | $pagantis = new WC_Pagantis_Gateway(); |
||||||||
557 | if (! $pagantis->is_available()) { |
||||||||
558 | unset($methods['pagantis']); |
||||||||
559 | } |
||||||||
560 | |||||||||
561 | return $methods; |
||||||||
562 | } |
||||||||
563 | |||||||||
564 | /** |
||||||||
565 | * Add links to Plugin description in WP Plugins panel |
||||||||
566 | * |
||||||||
567 | * @param $links |
||||||||
568 | * |
||||||||
569 | * @return mixed |
||||||||
570 | * @hook plugin_action_links_pagantis |
||||||||
571 | */ |
||||||||
572 | public function get_plugin_action_links($links) |
||||||||
573 | { |
||||||||
574 | $setting_link = $this->get_setting_link(); |
||||||||
575 | $plugin_links = array( |
||||||||
576 | '<a href="' . $setting_link . '">' . __('Settings', 'pagantis') . '</a>', |
||||||||
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
577 | ); |
||||||||
578 | |||||||||
579 | return array_merge($plugin_links, $links); |
||||||||
580 | } |
||||||||
581 | |||||||||
582 | |||||||||
583 | public function get_setting_link() |
||||||||
584 | { |
||||||||
585 | $section_slug = 'pagantis'; |
||||||||
586 | |||||||||
587 | return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
||||||||
0 ignored issues
–
show
The function
admin_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
588 | } |
||||||||
589 | |||||||||
590 | /** |
||||||||
591 | * Add links to Plugin options |
||||||||
592 | * |
||||||||
593 | * @param $links |
||||||||
594 | * @param $file |
||||||||
595 | * |
||||||||
596 | * @hook plugin_row_meta |
||||||||
597 | * @return array |
||||||||
598 | */ |
||||||||
599 | public function get_plugin_row_meta_links($links, $file) |
||||||||
600 | { |
||||||||
601 | if ($file === plugin_basename(__FILE__)) { |
||||||||
0 ignored issues
–
show
The function
plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
602 | $links[] = '<a href="' . PAGANTIS_GIT_HUB_URL . '" target="_blank">' . __('Documentation', 'pagantis') . '</a>'; |
||||||||
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
603 | $links[] = '<a href="' . PAGANTIS_DOC_URL . '" target="_blank">' . __('API documentation', 'pagantis') . '</a>'; |
||||||||
604 | $links[] = '<a href="' . PAGANTIS_SUPPORT_EMAIL . '">' . __('Support', 'pagantis') . '</a>'; |
||||||||
605 | |||||||||
606 | return $links; |
||||||||
607 | } |
||||||||
608 | |||||||||
609 | return $links; |
||||||||
610 | } |
||||||||
611 | |||||||||
612 | /** |
||||||||
613 | * Read logs |
||||||||
614 | * |
||||||||
615 | * @param $data |
||||||||
616 | * |
||||||||
617 | * @global wpdb $wpdb WordPress database abstraction object. |
||||||||
618 | */ |
||||||||
619 | public function get_pagantis_logs($data) |
||||||||
620 | { |
||||||||
621 | global $wpdb; |
||||||||
622 | $filters = ($data->get_params()); |
||||||||
623 | $response = array(); |
||||||||
624 | $secretKey = $filters['secret']; |
||||||||
625 | $from = $filters['from']; |
||||||||
626 | $to = $filters['to']; |
||||||||
627 | $cfg = get_option('woocommerce_pagantis_settings'); |
||||||||
0 ignored issues
–
show
The function
get_option was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
628 | $privateKey = isset($cfg['pagantis_private_key']) ? $cfg['pagantis_private_key'] : null; |
||||||||
629 | $tableName = $wpdb->prefix . PAGANTIS_LOGS_TABLE; |
||||||||
630 | $query = "SELECT * FROM $tableName WHERE createdAt>$from AND createdAt<$to ORDER BY createdAt DESC"; |
||||||||
631 | $results = $wpdb->get_results($query); |
||||||||
632 | if (isset($results) && $privateKey === $secretKey) { |
||||||||
633 | foreach ($results as $key => $result) { |
||||||||
634 | $response[$key]['timestamp'] = $result->createdAt; |
||||||||
635 | $response[$key]['log'] = json_decode($result->log); |
||||||||
636 | } |
||||||||
637 | } else { |
||||||||
638 | $response['result'] = 'Error'; |
||||||||
639 | } |
||||||||
640 | $response = json_encode($response); |
||||||||
641 | header('HTTP/1.1 200', true, 200); |
||||||||
642 | header('Content-Type: application/json', true); |
||||||||
643 | header('Content-Length: ' . strlen($response)); |
||||||||
644 | echo($response); |
||||||||
645 | exit(); |
||||||||
0 ignored issues
–
show
|
|||||||||
646 | } |
||||||||
647 | |||||||||
648 | /** |
||||||||
649 | * Update extra config |
||||||||
650 | * |
||||||||
651 | * @param $data |
||||||||
652 | */ |
||||||||
653 | public function updateExtraConfig($data) |
||||||||
654 | { |
||||||||
655 | global $wpdb; |
||||||||
656 | $tableName = $wpdb->prefix . PAGANTIS_CONFIG_TABLE; |
||||||||
657 | $response = array('status' => null); |
||||||||
658 | |||||||||
659 | $filters = ($data->get_params()); |
||||||||
660 | $secretKey = $filters['secret']; |
||||||||
661 | $cfg = get_option('woocommerce_pagantis_settings'); |
||||||||
0 ignored issues
–
show
The function
get_option was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
662 | $privateKey = isset($cfg['pagantis_private_key']) ? $cfg['pagantis_private_key'] : null; |
||||||||
663 | if ($privateKey !== $secretKey) { |
||||||||
664 | $response['status'] = 401; |
||||||||
665 | $response['result'] = 'Unauthorized'; |
||||||||
666 | } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { |
||||||||
667 | if (count($_POST)) { |
||||||||
668 | foreach ($_POST as $config => $value) { |
||||||||
669 | if (isset($this->initialConfig[$config]) && $response['status'] === null) { |
||||||||
670 | $wpdb->update( |
||||||||
671 | $tableName, |
||||||||
672 | array('value' => stripslashes($value)), |
||||||||
673 | array('config' => $config), |
||||||||
674 | array('%s'), |
||||||||
675 | array('%s') |
||||||||
676 | ); |
||||||||
677 | } else { |
||||||||
678 | $response['status'] = 400; |
||||||||
679 | $response['result'] = 'Bad request'; |
||||||||
680 | } |
||||||||
681 | } |
||||||||
682 | } else { |
||||||||
683 | $response['status'] = 422; |
||||||||
684 | $response['result'] = 'Empty data'; |
||||||||
685 | } |
||||||||
686 | } |
||||||||
687 | |||||||||
688 | if ($response['status'] === null) { |
||||||||
689 | $tableName = $wpdb->prefix . PAGANTIS_CONFIG_TABLE; |
||||||||
690 | $dbResult = $wpdb->get_results("select config, value from $tableName", ARRAY_A); |
||||||||
0 ignored issues
–
show
|
|||||||||
691 | foreach ($dbResult as $value) { |
||||||||
692 | $formattedResult[$value['config']] = $value['value']; |
||||||||
693 | } |
||||||||
694 | $response['result'] = $formattedResult; |
||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||||
695 | } |
||||||||
696 | |||||||||
697 | $result = json_encode($response['result']); |
||||||||
698 | header('HTTP/1.1 ' . $response['status'], true, $response['status']); |
||||||||
699 | header('Content-Type: application/json', true); |
||||||||
700 | header('Content-Length: ' . strlen($result)); |
||||||||
701 | echo($result); |
||||||||
702 | exit(); |
||||||||
0 ignored issues
–
show
|
|||||||||
703 | } |
||||||||
704 | |||||||||
705 | /** |
||||||||
706 | * Read logs |
||||||||
707 | * |
||||||||
708 | * @param $data |
||||||||
709 | */ |
||||||||
710 | public function readApi($data) |
||||||||
711 | { |
||||||||
712 | global $wpdb; |
||||||||
713 | $filters = ($data->get_params()); |
||||||||
714 | $response = array('timestamp' => time()); |
||||||||
715 | $secretKey = $filters['secret']; |
||||||||
716 | $from = ($filters['from']) ? date_create($filters['from']) : date('Y-m-d', strtotime('-7 day')); |
||||||||
717 | $to = ($filters['to']) ? date_create($filters['to']) : date('Y-m-d', strtotime('+1 day')); |
||||||||
718 | $method = ($filters['method']) ? ($filters['method']) : 'Pagantis'; |
||||||||
0 ignored issues
–
show
|
|||||||||
719 | $cfg = get_option('woocommerce_pagantis_settings'); |
||||||||
0 ignored issues
–
show
The function
get_option was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
720 | $privateKey = isset($cfg['pagantis_private_key']) ? $cfg['pagantis_private_key'] : null; |
||||||||
721 | $tableName = $wpdb->prefix . PAGANTIS_WC_ORDERS_TABLE; |
||||||||
722 | $tableNameInner = $wpdb->prefix . 'postmeta'; |
||||||||
723 | $query = "SELECT * FROM $tableName tn INNER JOIN $tableNameInner tn2 ON tn2.post_id = tn.id |
||||||||
724 | WHERE tn.post_type='shop_order' AND tn.post_date>'" . $from->format('Y-m-d') . "' |
||||||||
725 | AND tn.post_date<'" . $to->format('Y-m-d') . "' ORDER BY tn.post_date DESC"; |
||||||||
726 | $results = $wpdb->get_results($query); |
||||||||
727 | |||||||||
728 | if (isset($results) && $privateKey === $secretKey) { |
||||||||
729 | foreach ($results as $result) { |
||||||||
730 | $key = $result->ID; |
||||||||
731 | $response['message'][$key]['timestamp'] = $result->post_date; |
||||||||
732 | $response['message'][$key]['order_id'] = $key; |
||||||||
733 | $response['message'][$key][$result->meta_key] = $result->meta_value; |
||||||||
734 | } |
||||||||
735 | } else { |
||||||||
736 | $response['result'] = 'Error'; |
||||||||
737 | } |
||||||||
738 | $response = json_encode($response); |
||||||||
739 | header('HTTP/1.1 200', true, 200); |
||||||||
740 | header('Content-Type: application/json', true); |
||||||||
741 | header('Content-Length: ' . strlen($response)); |
||||||||
742 | echo($response); |
||||||||
743 | exit(); |
||||||||
0 ignored issues
–
show
|
|||||||||
744 | } |
||||||||
745 | |||||||||
746 | /** |
||||||||
747 | * ENDPOINT - Read logs -> Hook: rest_api_init |
||||||||
748 | * |
||||||||
749 | * @hook rest_api_init |
||||||||
750 | * @return mixed |
||||||||
751 | */ |
||||||||
752 | public function register_pg_rest_routes() |
||||||||
753 | { |
||||||||
754 | register_rest_route('pagantis/v1', '/logs/(?P<secret>\w+)/(?P<from>\d+)/(?P<to>\d+)', array( |
||||||||
0 ignored issues
–
show
The function
register_rest_route was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
755 | 'methods' => 'GET', |
||||||||
756 | 'callback' => array( |
||||||||
757 | $this, |
||||||||
758 | 'get_pagantis_logs', |
||||||||
759 | ), |
||||||||
760 | ), true); |
||||||||
761 | |||||||||
762 | register_rest_route('pagantis/v1', '/configController/(?P<secret>\w+)', array( |
||||||||
763 | 'methods' => 'GET, POST', |
||||||||
764 | 'callback' => array( |
||||||||
765 | $this, |
||||||||
766 | 'updateExtraConfig', |
||||||||
767 | ), |
||||||||
768 | ), true); |
||||||||
769 | |||||||||
770 | register_rest_route('pagantis/v1', '/api/(?P<secret>\w+)/(?P<from>\w+)/(?P<to>\w+)', array( |
||||||||
771 | 'methods' => 'GET', |
||||||||
772 | 'callback' => array( |
||||||||
773 | $this, |
||||||||
774 | 'readApi', |
||||||||
775 | ), |
||||||||
776 | ), true); |
||||||||
777 | } |
||||||||
778 | |||||||||
779 | /** |
||||||||
780 | * @param $css_quantity_selector |
||||||||
781 | * |
||||||||
782 | * @return mixed|string |
||||||||
783 | */ |
||||||||
784 | private function prepareQuantitySelector($css_quantity_selector) |
||||||||
785 | { |
||||||||
786 | if ($css_quantity_selector === 'default' || $css_quantity_selector === '') { |
||||||||
787 | $css_quantity_selector = $this->initialConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']; |
||||||||
788 | } elseif (! unserialize($css_quantity_selector)) { //in the case of a custom string selector, we keep it |
||||||||
789 | $css_quantity_selector = serialize(array($css_quantity_selector)); |
||||||||
790 | } |
||||||||
791 | |||||||||
792 | return $css_quantity_selector; |
||||||||
793 | } |
||||||||
794 | |||||||||
795 | /** |
||||||||
796 | * @param $css_price_selector |
||||||||
797 | * |
||||||||
798 | * @return mixed|string |
||||||||
799 | */ |
||||||||
800 | private function preparePriceSelector($css_price_selector) |
||||||||
801 | { |
||||||||
802 | if ($css_price_selector === 'default' || $css_price_selector === '') { |
||||||||
803 | $css_price_selector = $this->initialConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']; |
||||||||
804 | } elseif (! unserialize($css_price_selector)) { //in the case of a custom string selector, we keep it |
||||||||
805 | $css_price_selector = serialize(array($css_price_selector)); |
||||||||
806 | } |
||||||||
807 | |||||||||
808 | return $css_price_selector; |
||||||||
809 | } |
||||||||
810 | } |
||||||||
811 | |||||||||
812 | /** |
||||||||
813 | * Add widget Js |
||||||||
814 | **/ |
||||||||
815 | function add_pagantis_widget_js() |
||||||||
816 | { |
||||||||
817 | wp_enqueue_script('pgSDK', 'https://cdn.pagantis.com/js/pg-v2/sdk.js', '', '', true); |
||||||||
0 ignored issues
–
show
The function
wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
818 | } |
||||||||
819 | |||||||||
820 | WC_Pagantis_Plugin::get_instance(); |
||||||||
821 | |||||||||
822 | /** |
||||||||
823 | * Main instance WC_Pagantis_Plugin. |
||||||||
824 | * |
||||||||
825 | * Returns the main instance of WC_Pagantis_Plugin. |
||||||||
826 | * |
||||||||
827 | * @return WC_Pagantis_Plugin |
||||||||
828 | */ |
||||||||
829 | function PG_WC() // phpcs:ignore |
||||||||
830 | { |
||||||||
831 | return WC_Pagantis_Plugin::get_instance(); |
||||||||
832 | } |
||||||||
833 |