Passed
Pull Request — master (#21)
by
unknown
02:53
created

add_pagantis_widget_js()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * Plugin Name: Pagantis
4
 * Plugin URI: http://www.pagantis.com/
5
 * Description: Financiar con Pagantis
6
 * Version: 8.1.2
7
 * Author: Pagantis
8
 */
9
10
//namespace Gateways;
11
12
13
if (!defined('ABSPATH')) {
14
    exit;
15
}
16
17
class WcPagantis
18
{
19
    const GIT_HUB_URL = 'https://github.com/pagantis/woocommerce';
20
    const PAGANTIS_DOC_URL = 'https://developer.pagantis.com';
21
    const SUPPORT_EML = 'mailto:[email protected]?Subject=woocommerce_plugin';
22
23
    /** Concurrency tablename */
24
    const LOGS_TABLE = 'pagantis_logs';
25
26
    /** Config tablename */
27
    const CONFIG_TABLE = 'pagantis_config';
28
29
    /** Concurrency tablename  */
30
    const CONCURRENCY_TABLE = 'pagantis_concurrency';
31
32
    public $defaultConfigs = array('PAGANTIS_TITLE'=>'Instant Financing',
33
                            'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'pgSDK.simulator.types.SIMPLE',
34
                            'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'pgSDK.simulator.skins.BLUE',
35
                            'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons',
36
                            'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3,
37
                            'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12,
38
                            'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default',
39
                            'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'pgSDK.simulator.positions.INNER',
40
                            'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'a:3:{i:0;s:48:"div.summary *:not(del)>.woocommerce-Price-amount";i:1;s:54:"div.entry-summary *:not(del)>.woocommerce-Price-amount";i:2;s:36:"*:not(del)>.woocommerce-Price-amount";}',
41
                            'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'a:2:{i:0;s:22:"div.quantity input.qty";i:1;s:18:"div.quantity>input";}',
42
                            'PAGANTIS_FORM_DISPLAY_TYPE'=>0,
43
                            'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1,
44
                            'PAGANTIS_URL_OK'=>'',
45
                            'PAGANTIS_URL_KO'=>'',
46
                            'PAGANTIS_ALLOWED_COUNTRIES' => 'a:2:{i:0;s:2:"es";i:1;s:2:"it";}'
47
    );
48
49
    /** @var Array $extraConfig */
50
    public $extraConfig;
51
52
    /**
53
     * WC_Pagantis constructor.
54
     */
55
    public function __construct()
56
    {
57
        require_once(plugin_dir_path(__FILE__).'/vendor/autoload.php');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

57
        require_once(/** @scrutinizer ignore-call */ plugin_dir_path(__FILE__).'/vendor/autoload.php');
Loading history...
58
59
        $this->template_path = plugin_dir_path(__FILE__).'/templates/';
0 ignored issues
show
Bug Best Practice introduced by
The property template_path does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
60
61
        $this->pagantisActivation();
62
63
        $this->extraConfig = $this->getExtraConfig();
64
65
        load_plugin_textdomain('pagantis', false, basename(dirname(__FILE__)).'/languages');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

65
        /** @scrutinizer ignore-call */ 
66
        load_plugin_textdomain('pagantis', false, basename(dirname(__FILE__)).'/languages');
Loading history...
66
        add_filter('woocommerce_payment_gateways', array($this, 'addPagantisGateway'));
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

66
        /** @scrutinizer ignore-call */ 
67
        add_filter('woocommerce_payment_gateways', array($this, 'addPagantisGateway'));
Loading history...
67
        add_filter('woocommerce_available_payment_gateways', array($this, 'pagantisFilterGateways'), 9999);
68
        add_filter('plugin_row_meta', array($this, 'pagantisRowMeta'), 10, 2);
69
        add_filter('plugin_action_links_'.plugin_basename(__FILE__), array($this, 'pagantisActionLinks'));
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

69
        add_filter('plugin_action_links_'./** @scrutinizer ignore-call */ plugin_basename(__FILE__), array($this, 'pagantisActionLinks'));
Loading history...
70
        add_action('woocommerce_after_add_to_cart_form', array($this, 'pagantisAddProductSimulator'));
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

70
        /** @scrutinizer ignore-call */ 
71
        add_action('woocommerce_after_add_to_cart_form', array($this, 'pagantisAddProductSimulator'));
Loading history...
71
        add_action('wp_enqueue_scripts', 'add_pagantis_widget_js');
72
        add_action('rest_api_init', array($this, 'pagantisRegisterEndpoint')); //Endpoint
73
        add_filter('load_textdomain_mofile', array($this, 'loadPagantisTranslation'), 10, 2);
74
    }
75
76
    /*
77
     * Replace 'textdomain' with your plugin's textdomain. e.g. 'woocommerce'.
78
     * File to be named, for example, yourtranslationfile-en_GB.mo
79
     * File to be placed, for example, wp-content/lanaguages/textdomain/yourtranslationfile-en_GB.mo
80
     */
81
    public function loadPagantisTranslation($mofile, $domain)
82
    {
83
        if ('pagantis' === $domain) {
84
            $mofile = WP_LANG_DIR . '/../plugins/pagantis/languages/pagantis-' . get_locale() . '.mo';
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

84
            $mofile = WP_LANG_DIR . '/../plugins/pagantis/languages/pagantis-' . /** @scrutinizer ignore-call */ get_locale() . '.mo';
Loading history...
Bug introduced by
The constant WP_LANG_DIR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
85
        }
86
        return $mofile;
87
    }
88
89
    /**
90
     * Sql table
91
     */
92
    public function pagantisActivation()
93
    {
94
        global $wpdb;
95
96
        $tableName = $wpdb->prefix.self::CONCURRENCY_TABLE;
97
        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
98
            $charset_collate = $wpdb->get_charset_collate();
99
            $sql = "CREATE TABLE $tableName ( order_id int NOT NULL,  
100
                    createdAt timestamp DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY id (order_id)) $charset_collate";
101
            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
102
            dbDelta($sql);
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

102
            /** @scrutinizer ignore-call */ 
103
            dbDelta($sql);
Loading history...
103
        }
104
105
        $tableName = $wpdb->prefix.self::CONFIG_TABLE;
106
107
        //Check if table exists
108
        $tableExists = $wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName;
109
        if ($tableExists) {
110
            $charset_collate = $wpdb->get_charset_collate();
111
            $sql = "CREATE TABLE IF NOT EXISTS $tableName (
112
                                id int NOT NULL AUTO_INCREMENT, 
113
                                config varchar(60) NOT NULL, 
114
                                value varchar(1000) NOT NULL, 
115
                                UNIQUE KEY id(id)) $charset_collate";
116
117
            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
118
            dbDelta($sql);
119
        }
120
121
        $dbConfigs = $wpdb->get_results("select * from $tableName", ARRAY_A);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
122
123
        // Convert a multimple dimension array for SQL insert statements into a simple key/value
124
        $simpleDbConfigs = array();
125
        foreach ($dbConfigs as $config) {
126
            $simpleDbConfigs[$config['config']] = $config['value'];
127
        }
128
        $newConfigs = array_diff_key($this->defaultConfigs, $simpleDbConfigs);
129
        if (!empty($newConfigs)) {
130
            foreach ($newConfigs as $key => $value) {
131
                $wpdb->insert($tableName, array('config' => $key, 'value'  => $value), array('%s', '%s'));
132
            }
133
        }
134
135
        //Current plugin config: pagantis_public_key => New field --- public_key => Old field
136
        $settings = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

136
        $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
137
138
        if (!isset($settings['pagantis_public_key']) && $settings['public_key']) {
139
            $settings['pagantis_public_key'] = $settings['public_key'];
140
            unset($settings['public_key']);
141
        }
142
143
        if (!isset($settings['pagantis_private_key']) && $settings['secret_key']) {
144
            $settings['pagantis_private_key'] = $settings['secret_key'];
145
            unset($settings['secret_key']);
146
        }
147
148
        update_option('woocommerce_pagantis_settings', $settings);
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

148
        /** @scrutinizer ignore-call */ 
149
        update_option('woocommerce_pagantis_settings', $settings);
Loading history...
149
    }
150
151
    /**
152
     * Product simulator
153
     */
154
    public function pagantisAddProductSimulator()
155
    {
156
        global $product;
157
158
        $cfg = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

158
        $cfg = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
159
        $locale = strtolower(strstr(get_locale(), '_', true));
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

159
        $locale = strtolower(strstr(/** @scrutinizer ignore-call */ get_locale(), '_', true));
Loading history...
160
        $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
161
        $allowedCountry = (in_array(strtolower($locale), $allowedCountries));
162
        if ($cfg['enabled'] !== 'yes' || $cfg['pagantis_public_key'] == '' || $cfg['pagantis_private_key'] == '' ||
163
            $cfg['simulator'] !== 'yes' ||  $product->price < $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] ||
164
            !$allowedCountry ) {
165
            return;
166
        }
167
168
        $template_fields = array(
169
            'total'    => is_numeric($product->price) ? $product->price : 0,
170
            'public_key' => $cfg['pagantis_public_key'],
171
            'simulator_type' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'],
172
            'positionSelector' => $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'],
173
            'quantitySelector' => unserialize($this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']),
174
            'priceSelector' => unserialize($this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']),
175
            'totalAmount' => is_numeric($product->price) ? $product->price : 0,
176
            'locale' => $locale
177
        );
178
        wc_get_template('product_simulator.php', $template_fields, '', $this->template_path);
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

178
        /** @scrutinizer ignore-call */ 
179
        wc_get_template('product_simulator.php', $template_fields, '', $this->template_path);
Loading history...
179
    }
180
181
    /**
182
     * Add Pagantis to payments list.
183
     *
184
     * @param $methods
185
     *
186
     * @return array
187
     */
188
    public function addPagantisGateway($methods)
189
    {
190
        if (! class_exists('WC_Payment_Gateway')) {
191
            return $methods;
192
        }
193
194
        include_once('controllers/paymentController.php');
195
        $methods[] = 'WcPagantisGateway';
196
197
        return $methods;
198
    }
199
200
    /**
201
     * Initialize WC_Pagantis class
202
     *
203
     * @param $methods
204
     *
205
     * @return mixed
206
     */
207
    public function pagantisFilterGateways($methods)
208
    {
209
        $pagantis = new WcPagantisGateway();
210
        if (!$pagantis->is_available()) {
211
            unset($methods['pagantis']);
212
        }
213
214
        return $methods;
215
    }
216
217
    /**
218
     * Add links to Plugin description
219
     *
220
     * @param $links
221
     *
222
     * @return mixed
223
     */
224
    public function pagantisActionLinks($links)
225
    {
226
        $params_array = array('page' => 'wc-settings', 'tab' => 'checkout', 'section' => 'pagantis');
227
        $setting_url  = esc_url(add_query_arg($params_array, admin_url('admin.php?')));
0 ignored issues
show
Bug introduced by
The function add_query_arg 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 ignore-call  annotation

227
        $setting_url  = esc_url(/** @scrutinizer ignore-call */ add_query_arg($params_array, admin_url('admin.php?')));
Loading history...
Bug introduced by
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 ignore-call  annotation

227
        $setting_url  = esc_url(add_query_arg($params_array, /** @scrutinizer ignore-call */ admin_url('admin.php?')));
Loading history...
Bug introduced by
The function esc_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 ignore-call  annotation

227
        $setting_url  = /** @scrutinizer ignore-call */ esc_url(add_query_arg($params_array, admin_url('admin.php?')));
Loading history...
228
        $setting_link = '<a href="'.$setting_url.'">'.__('Settings', 'pagantis').'</a>';
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

228
        $setting_link = '<a href="'.$setting_url.'">'./** @scrutinizer ignore-call */ __('Settings', 'pagantis').'</a>';
Loading history...
229
230
        array_unshift($links, $setting_link);
231
232
        return $links;
233
    }
234
235
    /**
236
     * Add links to Plugin options
237
     *
238
     * @param $links
239
     * @param $file
240
     *
241
     * @return array
242
     */
243
    public function pagantisRowMeta($links, $file)
244
    {
245
        if ($file == plugin_basename(__FILE__)) {
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

245
        if ($file == /** @scrutinizer ignore-call */ plugin_basename(__FILE__)) {
Loading history...
246
            $links[] = '<a href="'.WcPagantis::GIT_HUB_URL.'" target="_blank">'.__('Documentation', 'pagantis').'</a>';
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

246
            $links[] = '<a href="'.WcPagantis::GIT_HUB_URL.'" target="_blank">'./** @scrutinizer ignore-call */ __('Documentation', 'pagantis').'</a>';
Loading history...
247
            $links[] = '<a href="'.WcPagantis::PAGANTIS_DOC_URL.'" target="_blank">'.
248
            __('API documentation', 'pagantis').'</a>';
249
            $links[] = '<a href="'.WcPagantis::SUPPORT_EML.'">'.__('Support', 'pagantis').'</a>';
250
251
            return $links;
252
        }
253
254
        return $links;
255
    }
256
257
    /**
258
     * Read logs
259
     */
260
    public function readLogs($data)
261
    {
262
        global $wpdb;
263
        $filters   = ($data->get_params());
264
        $response  = array();
265
        $secretKey = $filters['secret'];
266
        $from = $filters['from'];
267
        $to   = $filters['to'];
268
        $cfg  = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

268
        $cfg  = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
269
        $privateKey = isset($cfg['secret_key']) ? $cfg['secret_key'] : null;
270
        $tableName = $wpdb->prefix.self::LOGS_TABLE;
271
        $query = "select * from $tableName where createdAt>$from and createdAt<$to order by createdAt desc";
272
        $results = $wpdb->get_results($query);
273
        if (isset($results) && $privateKey == $secretKey) {
274
            foreach ($results as $key => $result) {
275
                $response[$key]['timestamp'] = $result->createdAt;
276
                $response[$key]['log']       = json_decode($result->log);
277
            }
278
        } else {
279
            $response['result'] = 'Error';
280
        }
281
        $response = json_encode($response);
282
        header("HTTP/1.1 200", true, 200);
283
        header('Content-Type: application/json', true);
284
        header('Content-Length: '.strlen($response));
285
        echo($response);
286
        exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
287
    }
288
289
    /**
290
     * Update extra config
291
     */
292
    public function updateExtraConfig($data)
293
    {
294
        global $wpdb;
295
        $tableName = $wpdb->prefix.self::CONFIG_TABLE;
296
        $response = array('status'=>null);
297
298
        $filters   = ($data->get_params());
299
        $secretKey = $filters['secret'];
300
        $cfg  = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

300
        $cfg  = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
301
        $privateKey = isset($cfg['pagantis_private_key']) ? $cfg['pagantis_private_key'] : null;
302
        if ($privateKey != $secretKey) {
303
            $response['status'] = 401;
304
            $response['result'] = 'Unauthorized';
305
        } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
306
            if (count($_POST)) {
307
                foreach ($_POST as $config => $value) {
308
                    if (isset($this->defaultConfigs[$config]) && $response['status']==null) {
309
                        $wpdb->update(
310
                            $tableName,
311
                            array('value' => $value),
312
                            array('config' => $config),
313
                            array('%s'),
314
                            array('%s')
315
                        );
316
                    } else {
317
                        $response['status'] = 400;
318
                        $response['result'] = 'Bad request';
319
                    }
320
                }
321
            } else {
322
                $response['status'] = 422;
323
                $response['result'] = 'Empty data';
324
            }
325
        }
326
327
        if ($response['status']==null) {
328
            $tableName = $wpdb->prefix.self::CONFIG_TABLE;
329
            $dbResult = $wpdb->get_results("select config, value from $tableName", ARRAY_A);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
330
            foreach ($dbResult as $value) {
331
                $formattedResult[$value['config']] = $value['value'];
332
            }
333
            $response['result'] = $formattedResult;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $formattedResult seems to be defined by a foreach iteration on line 330. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
334
        }
335
336
        $result = json_encode($response['result']);
337
        header("HTTP/1.1 ".$response['status'], true, $response['status']);
338
        header('Content-Type: application/json', true);
339
        header('Content-Length: '.strlen($result));
340
        echo($result);
341
        exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
342
    }
343
344
    /**
345
     * ENDPOINT - Read logs -> Hook: rest_api_init
346
     * @return mixed
347
     */
348
    public function pagantisRegisterEndpoint()
349
    {
350
        register_rest_route(
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

350
        /** @scrutinizer ignore-call */ 
351
        register_rest_route(
Loading history...
351
            'pagantis/v1',
352
            '/logs/(?P<secret>\w+)/(?P<from>\d+)/(?P<to>\d+)',
353
            array(
354
            'methods'  => 'GET',
355
            'callback' => array(
356
                $this,
357
                'readLogs')
358
            ),
359
            true
360
        );
361
362
        register_rest_route(
363
            'pagantis/v1',
364
            '/configController/(?P<secret>\w+)',
365
            array(
366
                'methods'  => 'GET, POST',
367
                'callback' => array(
368
                    $this,
369
                    'updateExtraConfig')
370
            ),
371
            true
372
        );
373
    }
374
375
    /**
376
     * @return array
377
     */
378
    private function getExtraConfig()
379
    {
380
        global $wpdb;
381
        $tableName = $wpdb->prefix.self::CONFIG_TABLE;
382
        $response = array();
383
        $dbResult = $wpdb->get_results("select config, value from $tableName", ARRAY_A);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
384
        foreach ($dbResult as $value) {
385
            $response[$value['config']] = $value['value'];
386
        }
387
388
        return $response;
389
    }
390
}
391
392
/**
393
 * Add widget Js
394
 **/
395
function add_pagantis_widget_js()
396
{
397
    wp_enqueue_script('pgSDK', 'https://cdn.pagantis.com/js/pg-v2/sdk.js', '', '', true);
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

397
    /** @scrutinizer ignore-call */ 
398
    wp_enqueue_script('pgSDK', 'https://cdn.pagantis.com/js/pg-v2/sdk.js', '', '', true);
Loading history...
398
    wp_enqueue_script('pmtSDK', 'https://cdn.pagamastarde.com/js/pmt-v2/sdk.js', '', '', true);
399
}
400
401
$WcPagantis = new WcPagantis();
402