pagantis::process_button()   F
last analyzed

Complexity

Conditions 12
Paths 2420

Size

Total Lines 194
Code Lines 158

Duplication

Lines 0
Ratio 0 %

Importance

Changes 19
Bugs 1 Features 1
Metric Value
cc 12
eloc 158
c 19
b 1
f 1
nc 2420
nop 0
dl 0
loc 194
rs 2.2399

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use Pagantis\ModuleUtils\Exception\OrderNotFoundException;
4
use Pagantis\OrdersApiClient\Model\Order\User\Address;
5
use Pagantis\ModuleUtils\Exception\UnknownException;
6
use Pagantis\ModuleUtils\Model\Log\LogEntry;
7
8
define('TABLE_PAGANTIS_LOG', 'pagantis_log');
9
define('TABLE_PAGANTIS_CONFIG', 'pagantis_config');
10
define('TABLE_PAGANTIS_ORDERS', 'pagantis_order');
11
define('TABLE_PAGANTIS_CONCURRENCY', 'pagantis_concurrency');
12
define('MODULE_PAYMENT_PAGANTIS_TEXT_ADMIN_TITLE', 'Pagantis');
13
define('__ROOT__', dirname(dirname(__FILE__)));
14
15
class pagantis
16
{
17
    /** @var  String $is_guest */
18
    public $is_guest;
19
20
    /** @var Array $extraConfig */
21
    public $extraConfig;
22
23
    /** @var String $form_action_url */
24
    public $form_action_url;
25
26
    /** @var String $base_url */
27
    public $base_url;
28
29
    /** @var String $os_order_reference */
30
    public $os_order_reference;
31
32
    /** @var notifyController $pgNotify */
33
    public $pgNotify;
34
35
    /** @var string $langCode */
36
    public $langCode = null;
37
38
    /** @var string $errorMessage */
39
    public $errorMessage;
40
41
    /** @var string $errorLinkMessage */
42
    public $errorLinkMessage;
43
44
    public $defaultConfigs = array(
45
        'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'sdk.simulator.types.PRODUCT_PAGE',
46
        'PAGANTIS_SIMULATOR_DISPLAY_TYPE_CHECKOUT'=>'sdk.simulator.types.CHECKOUT_PAGE',
47
        'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'sdk.simulator.skins.BLUE',
48
        'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons',
49
        'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3,
50
        'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12,
51
        'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default',
52
        'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'sdk.simulator.positions.INNER',
53
        'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'default',
54
        'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'default',
55
        'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR_CHECKOUT'=>'default',
56
        'PAGANTIS_FORM_DISPLAY_TYPE'=>0,
57
        'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1,
58
        'PAGANTIS_SIMULATOR_DISPLAY_MAX_AMOUNT'=>'0',
59
        'PAGANTIS_URL_OK'=>'',
60
        'PAGANTIS_URL_KO'=>'',
61
        'PAGANTIS_TITLE_EXTRA' => 'Paga hasta en 12 cómodas cuotas con Pagantis. Solicitud totalmente online y sin papeleos,¡y la respuesta es inmediata!',
62
        'PAGANTIS_PROMOTION' => '',
63
        'PAGANTIS_PROMOTED_PRODUCT_CODE' => 'Finance this product <span class="pmt-no-interest">without interest!</span>',
64
        'PAGANTIS_ALLOWED_COUNTRIES' => 'a:3:{i:0;s:2:"es";i:1;s:2:"it";i:2;s:2:"fr";}',
65
        'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR' => '.',
66
        'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR' => ','
67
68
    );
69
70
    /**
71
     * Constructor
72
     */
73
    public function __construct()
74
    {
75
        $this->version = '8.2.0';
0 ignored issues
show
Bug Best Practice introduced by
The property version does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
76
        $this->code = 'pagantis';
0 ignored issues
show
Bug Best Practice introduced by
The property code does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
77
        $this->sort_order = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property sort_order does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
78
        $this->description = $this->getDescription();
0 ignored issues
show
Bug Best Practice introduced by
The property description does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
79
        $this->extraConfig = $this->getExtraConfig();
80
81
        if (strpos($_SERVER[REQUEST_URI], "checkout_payment.php") <= 0) {
0 ignored issues
show
Bug introduced by
The constant REQUEST_URI was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
82
            $this->title = MODULE_PAYMENT_PAGANTIS_TEXT_ADMIN_TITLE; // Payment module title in Admin
0 ignored issues
show
Bug Best Practice introduced by
The property title does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
83
        } else {
84
            $this->title = MODULE_PAYMENT_PAGANTIS_TEXT_CHECKOUT .'<br/><br/><div class="buttonSet" style="display:none"></div><br/>'; // Payment module title in Catalog
85
        }
86
87
        if (defined('MODULE_PAYMENT_PAGANTIS_LANG_CODE')) {
88
            $this->langCode = strtoupper(MODULE_PAYMENT_PAGANTIS_LANG_CODE);
89
        }
90
91
        $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
92
93
        $this->enabled = ((MODULE_PAYMENT_PAGANTIS_STATUS == 'True' && in_array(strtolower($this->langCode), $allowedCountries)) ? true : false);
0 ignored issues
show
Bug Best Practice introduced by
The property enabled does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
The constant MODULE_PAYMENT_PAGANTIS_STATUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
94
95
        $this->base_url = dirname(
96
            sprintf(
97
                "%s://%s%s%s",
98
                isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
99
                $_SERVER['SERVER_NAME'],
100
                isset($_SERVER['SERVER_PORT']) ? ":" . $_SERVER['SERVER_PORT'] : '',
101
                $_SERVER['REQUEST_URI']
102
            )
103
        );
104
105
        $this->form_action_url = $this->base_url . '/ext/modules/payment/pagantis/bypass.php';
106
107
        if (defined('MODULE_PAYMENT_PAGANTIS_ERROR_MESSAGE')) {
108
            $this->errorMessage = strtoupper(MODULE_PAYMENT_PAGANTIS_ERROR_MESSAGE);
109
        }
110
111
        if (defined('MODULE_PAYMENT_PAGANTIS_ERROR_MESSAGE')) {
112
            $this->errorLinkMessage = strtoupper(MODULE_PAYMENT_PAGANTIS_ERROR_LINK_MESSAGE);
113
        }
114
    }
115
116
    /***************
117
     *
118
     * CLASS METHODS
119
     *
120
     **************/
121
    /**
122
     * Here you can implement using payment zones (refer to standard PayPal module as reference)
123
     */
124
    public function update_status()
125
    {
126
127
    }
128
129
    /*
130
    * Here you may define client side javascript that will verify any input fields you use in the payment method
131
    * selection page. Refer to standard cc module as reference (cc.php).
132
    */
133
    public function javascript_validation()
134
    {
135
        return false;
136
    }
137
138
    /*
139
    * Llamada cuando el usuario esta en la pantalla de eleccion de tipo de pago
140
     * This function outputs the payment method title/text and if required, the input fields.
141
    *
142
    * Si hay un pedido generado previamente y no confirmado, se borra
143
    * Caso de uso:
144
    * - el usuario llega a la pantalla de confirmacion
145
    * - se genera el pedido (pero no se genera entrada en orders_status_history)
146
    * - el usuario decide realizar algun cambio en su compra antes de pasar a pagantis
147
    * - entra de nuevo en la pantalla de seleccion de tipo de pago (puede elegir otra forma de pago)
148
    * - se comprueba que no exista el pedido generado anteriormente
149
    * - se borra el pedido que se habia generado inicialmente. Ya no es valido
150
    *
151
    */
152
    public function selection()
153
    {
154
        return array('id' => $this->code, 'module' => $this->title);
155
    }
156
157
    /*
158
    * Use this function implement any checks of any conditions after payment method has been selected. You most probably
159
    *  don't need to implement anything here.
160
    */
161
    public function pre_confirmation_check()
162
    {
163
        return false;
164
    }
165
166
    /*
167
     * Implement any checks or processing on the order information before proceeding to payment confirmation. You most
168
    probably don't need to implement anything here.
169
    * Llamada cuando el usuario entra en la pantalla de confirmacion
170
    *
171
    * Se genera el pedido:
172
    * - con el estado predefinido para el modulo pagantis
173
    * - sin notificacion a cliente ni administrador
174
    * - no se borra el carrito asociado al pedido
175
    *
176
    */
177
    public function confirmation()
178
    {
179
        return false;
180
    }
181
182
    /**
183
     * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
184
     * This sends the data to the payment gateway for processing.
185
     * (These are hidden fields on the checkout confirmation page)
186
     */
187
    public function process_button()
188
    {
189
        try {
190
            include_once('./ext/modules/payment/pagantis/vendor/autoload.php');
191
            global $order, $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping,
192
                   $payment, $comments, $customer_default_address_id, $cartID;
193
            $global_vars = array();
194
            $global_vars['customer_id'] = serialize($customer_id);
195
            $global_vars['sendTo'] = serialize($sendto);
196
            $global_vars['billTo'] = serialize($billto);
197
            $global_vars['cart'] = serialize($cart);
198
            $global_vars['languages_id'] = serialize($languages_id);
199
            $global_vars['currency'] = serialize($currency);
200
            $global_vars['currencies'] = serialize($currencies);
201
            $global_vars['shipping'] = serialize($shipping);
202
            $global_vars['payment'] = serialize($payment);
203
            $global_vars['comments'] = serialize($comments);
204
            $global_vars['$customer_default_address_id'] = serialize($customer_default_address_id);
205
            $global_vars['cartID'] = serialize($cartID);
206
            $global_vars['sessiontoken'] = serialize($_SESSION['sessiontoken']);
207
208
            if (!isset($order)) {
209
                throw new UnknownException("Order not found");
210
            }
211
212
            $id_hash = time().serialize($order->products).''.serialize($order->customer).''.serialize($order->delivery);
213
            $this->os_order_reference = md5($id_hash);
214
            $_SESSION['order_id'] = $this->os_order_reference;
215
216
            $national_id = $this->getNationalId();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $national_id is correct as $this->getNationalId() targeting pagantis::getNationalId() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
217
            $tax_id = $this->getTaxId();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $tax_id is correct as $this->getTaxId() targeting pagantis::getTaxId() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
218
219
            $fullName = $order->billing['firstname'] . ' ' . $order->billing['lastname'];
220
            if ($fullName == ' ') {
221
                $fullName = $order->customer['firstname'] . ' ' . $order->customer['lastname'];
222
            }
223
            if ($fullName == ' ') {
224
                $fullName = $order->delivery['firstname'] . ' ' . $order->delivery['lastname'];
225
            }
226
            $fullName = utf8_encode($fullName);
227
            $userAddress = new Address();
228
            $userAddress
229
                ->setZipCode($order->billing['postcode'])
230
                ->setFullName($fullName)
231
                ->setCountryCode($order->billing['country']['iso_code'])
232
                ->setCity($order->billing['city'])
233
                ->setAddress($order->billing['street_address'])
234
                ->setFixPhone($order->customer['telephone'])
235
                ->setMobilePhone($order->customer['telephone'])
236
                ->setNationalId($national_id)
237
                ->setDni($national_id)
238
                ->setTaxId($tax_id);
239
240
            $orderBillingAddress = $userAddress;
241
            $orderShippingAddress = new Address();
242
            $orderShippingAddress
243
                ->setZipCode($order->delivery['postcode'])
244
                ->setFullName($fullName)
245
                ->setCountryCode($order->delivery['country']['iso_code'])
246
                ->setCity($order->delivery['city'])
247
                ->setAddress($order->delivery['street_address'])
248
                ->setFixPhone($order->customer['telephone'])
249
                ->setMobilePhone($order->customer['telephone']);
250
251
            $orderUser = new \Pagantis\OrdersApiClient\Model\Order\User();
252
            $orderUser
253
                ->setAddress($userAddress)
254
                ->setFullName($fullName)
255
                ->setBillingAddress($orderBillingAddress)
256
                ->setEmail($order->customer['email_address'])
257
                ->setFixPhone($order->customer['telephone'])
258
                ->setMobilePhone($order->customer['telephone'])
259
                ->setShippingAddress($orderShippingAddress)
260
                ->setNationalId($national_id)
261
                ->setDni($national_id)
262
                ->setTaxId($tax_id);
263
264
            $previousOrders = $this->getOrders();
265
            foreach ((array)$previousOrders as $k => $previousOrder) {
266
                $orderHistory = new \Pagantis\OrdersApiClient\Model\Order\User\OrderHistory();
267
                $orderHistory
268
                    ->setAmount(intval(100 * $previousOrder['value']))
269
                    ->setDate(new \DateTime($previousOrder['date_purchased']));
0 ignored issues
show
Bug introduced by
new DateTime($previousOrder['date_purchased']) of type DateTime is incompatible with the type string expected by parameter $date of Pagantis\OrdersApiClient...OrderHistory::setDate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

269
                    ->setDate(/** @scrutinizer ignore-type */ new \DateTime($previousOrder['date_purchased']));
Loading history...
270
                $orderUser->addOrderHistory($orderHistory);
271
            }
272
273
            $details = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details();
274
            $shippingCost = number_format($order->info['shipping_cost'], 2, '.', '');
275
            $details->setShippingCost(intval(strval(100 * $shippingCost)));
276
277
            $metadataOrder = new \Pagantis\OrdersApiClient\Model\Order\Metadata();
278
            $metadata = array(
279
                'member_since' => $this->getMemberSince(),
280
                'pg_module' => 'oscommerce',
281
                'pg_version' => $this->version,
282
                'ec_module' => 'oscommerce',
283
                'ec_version' => PROJECT_VERSION
0 ignored issues
show
Bug introduced by
The constant PROJECT_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
284
            );
285
            foreach ($metadata as $key => $metadatum) {
286
                $metadataOrder->addMetadata($key, $metadatum);
287
            }
288
289
            $promotedAmount = 0;
290
            foreach ($order->products as $item) {
291
                $promotedProduct = $this->isPromoted($item);
292
                $product = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details\Product();
293
                $product
294
                    ->setAmount(intval(100 * number_format(($item['final_price'] * $item['qty']), 2)))
295
                    ->setQuantity(intval($item['qty']))
296
                    ->setDescription($item['name']);
297
                if ($promotedProduct) {
298
                    $promotedAmount+=$product->getAmount();
299
                    $promotedMessage = $product->getDescription()."-Price:".$item['final_price']."-Qty:".$product->getQuantity();
300
                    $metadataOrder->addMetadata('promotedProduct', $promotedMessage);
301
                }
302
                $details->addProduct($product);
303
            }
304
305
            $orderShoppingCart = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart();
306
            $orderShoppingCart
307
                ->setDetails($details)
308
                ->setOrderReference($this->os_order_reference)
309
                ->setTotalAmount(intval($order->info['total'] * 100))
310
                ->setPromotedAmount($promotedAmount);
311
312
            $callback_url = $this->base_url.'/ext/modules/payment/pagantis/callback.php?order_id='.$this->os_order_reference;
313
            $checkoutProcessUrl = htmlspecialchars_decode(
314
                tep_href_link(FILENAME_CHECKOUT_PROCESS, "order_id=$this->os_order_reference&from=order", 'SSL', true)
0 ignored issues
show
Bug introduced by
The constant FILENAME_CHECKOUT_PROCESS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function tep_href_link 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

314
                /** @scrutinizer ignore-call */ 
315
                tep_href_link(FILENAME_CHECKOUT_PROCESS, "order_id=$this->os_order_reference&from=order", 'SSL', true)
Loading history...
315
            );
316
317
            $cancelUrl = trim(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL', false));
0 ignored issues
show
Bug introduced by
The constant FILENAME_CHECKOUT_SHIPPING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
318
            if ($this->extraConfig['PAGANTIS_URL_KO']!='') {
319
                $koUrl = $this->extraConfig['PAGANTIS_URL_KO'];
320
            } else {
321
                $koUrl = $cancelUrl;
322
            }
323
324
            $orderConfigurationUrls = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Urls();
325
            $orderConfigurationUrls
326
                ->setCancel($cancelUrl)
327
                ->setKo($koUrl)
328
                ->setAuthorizedNotificationCallback($callback_url)
329
                ->setRejectedNotificationCallback($callback_url)
330
                ->setOk($checkoutProcessUrl);
331
332
333
            $orderChannel = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Channel();
334
            $orderChannel
335
                ->setAssistedSale(false)
336
                ->setType(\Pagantis\OrdersApiClient\Model\Order\Configuration\Channel::ONLINE);
337
            $orderConfiguration = new \Pagantis\OrdersApiClient\Model\Order\Configuration();
338
            $orderConfiguration
339
                ->setChannel($orderChannel)
340
                ->setUrls($orderConfigurationUrls)
341
                ->setPurchaseCountry($this->langCode)
342
            ;
343
344
            $orderApiClient = new \Pagantis\OrdersApiClient\Model\Order();
345
            $orderApiClient
346
                ->setConfiguration($orderConfiguration)
347
                ->setMetadata($metadataOrder)
348
                ->setShoppingCart($orderShoppingCart)
349
                ->setUser($orderUser);
350
351
            $publicKey = trim(MODULE_PAYMENT_PAGANTIS_PK);
0 ignored issues
show
Bug introduced by
The constant MODULE_PAYMENT_PAGANTIS_PK was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
352
            $secretKey = trim(MODULE_PAYMENT_PAGANTIS_SK);
0 ignored issues
show
Bug introduced by
The constant MODULE_PAYMENT_PAGANTIS_SK was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
353
            $orderClient = new \Pagantis\OrdersApiClient\Client($publicKey, $secretKey);
354
            $pagantisOrder = $orderClient->createOrder($orderApiClient);
355
            if ($pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) {
0 ignored issues
show
introduced by
$pagantisOrder is always a sub-type of Pagantis\OrdersApiClient\Model\Order.
Loading history...
356
                $url = $pagantisOrder->getActionUrls()->getForm();
357
                $this->insertRow($this->os_order_reference, $pagantisOrder->getId(), serialize($global_vars));
358
            } else {
359
                throw new OrderNotFoundException();
360
            }
361
362
            if ($url == "") {
363
                throw new UnknownException(_("No ha sido posible obtener una respuesta de Pagantis"));
364
            } else {
365
                $output = "\n";
366
                $output .= tep_draw_hidden_field("formUrl", $url) . "\n";
0 ignored issues
show
Bug introduced by
The function tep_draw_hidden_field 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

366
                $output .= /** @scrutinizer ignore-call */ tep_draw_hidden_field("formUrl", $url) . "\n";
Loading history...
367
                $output .= tep_draw_hidden_field("cancelUrl", $cancelUrl) . "\n";
368
                return $output;
369
370
            } //TODO IFRAME
371
        } catch (\Exception $exception) {
372
            $this->insertLog($exception);
373
            $output = "\n";
374
            $output .= tep_draw_hidden_field("cancelUrl", $cancelUrl) . "\n";
375
            $output .= tep_draw_hidden_field("errorMessage", $exception->getMessage()) . "\n";
376
            $output .= tep_draw_hidden_field("errorCode", $exception->getCode()) . "\n";
377
            $output .= "<p>".$this->errorMessage.", <a href='$cancelUrl' style='text-decoration:underline'><b>";
378
            $output .= $this->errorLinkMessage." </b></a></p>";
379
380
            return $output;
381
        }
382
    }
383
384
    /**
385
     * @throws Exception
386
     */
387
    public function before_process()
388
    {
389
        include_once('./ext/modules/payment/pagantis/notifyController.php');
390
        $this->pgNotify = new notifyController();
391
        $this->pgNotify->setOscommerceOrderId($_GET['order_id']);
392
        $this->pgNotify->setOrigin(isset($_GET['from']) ? ($_GET['from']) : 'order');
393
        $this->pgNotify->processInformation();
394
    }
395
396
    /**
397
     * Post-processing activities
398
     *
399
     * @return boolean
400
     */
401
    public function after_process()
402
    {
403
        $this->pgNotify->confirmInformation();
404
    }
405
406
    /**
407
     * @return bool
408
     */
409
    public function output_error()
410
    {
411
        return false;
412
    }
413
414
    /**
415
     * @return mixed
416
     */
417
    public function check()
418
    {
419
        if (!isset($this->_check)) {
420
            $query = "select * from ".TABLE_CONFIGURATION." where configuration_key = 'MODULE_PAYMENT_PAGANTIS_STATUS'";
0 ignored issues
show
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
421
            $check_query = tep_db_query($query);
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

421
            $check_query = /** @scrutinizer ignore-call */ tep_db_query($query);
Loading history...
422
            $this->_check = tep_db_num_rows($check_query);
0 ignored issues
show
Bug Best Practice introduced by
The property _check does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
The function tep_db_num_rows 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

422
            $this->_check = /** @scrutinizer ignore-call */ tep_db_num_rows($check_query);
Loading history...
423
        }
424
        $this->installPagantisTables();
425
        return $this->_check;
426
    }
427
428
    /**
429
     * This is where you define module's configurations (displayed in admin).
430
     */
431
    public function install()
432
    {
433
        global $messageStack;
434
435
        if (defined('MODULE_PAYMENT_PAGANTIS_STATUS')) {
436
            tep_redirect(tep_href_link(FILENAME_MODULES, 'set=payment&module=pagantis', 'NONSSL'));
0 ignored issues
show
Bug introduced by
The function tep_href_link 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

436
            tep_redirect(/** @scrutinizer ignore-call */ tep_href_link(FILENAME_MODULES, 'set=payment&module=pagantis', 'NONSSL'));
Loading history...
Bug introduced by
The function tep_redirect 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

436
            /** @scrutinizer ignore-call */ 
437
            tep_redirect(tep_href_link(FILENAME_MODULES, 'set=payment&module=pagantis', 'NONSSL'));
Loading history...
Bug introduced by
The constant FILENAME_MODULES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
437
            return 'failed';
438
        }
439
440
        tep_db_query("insert into " . TABLE_CONFIGURATION . "
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

440
        /** @scrutinizer ignore-call */ 
441
        tep_db_query("insert into " . TABLE_CONFIGURATION . "
Loading history...
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
441
        (
442
            configuration_title,
443
            configuration_key,
444
            configuration_value,
445
            configuration_description,
446
            configuration_group_id,
447
            sort_order,
448
            set_function,
449
            date_added) 
450
        values 
451
        (
452
            'Enable module',
453
            'MODULE_PAYMENT_PAGANTIS_STATUS',
454
            'True',
455
            '',
456
            '6',
457
            '0',
458
            'tep_cfg_select_option(array(\'True\',
459
            \'False\'),
460
            ',
461
            now()
462
        )");
463
        tep_db_query("insert into " . TABLE_CONFIGURATION . "
464
        (
465
            configuration_title,
466
            configuration_key,
467
            configuration_value,
468
            configuration_description,
469
            configuration_group_id,
470
            sort_order,
471
            date_added
472
        ) 
473
        values 
474
        (
475
            'Public Key',
476
            'MODULE_PAYMENT_PAGANTIS_PK',
477
            '',
478
            'MANDATORY. You can get in your pagantis profile',
479
            '6',
480
            '0',
481
            now()
482
        )");
483
        tep_db_query("insert into " . TABLE_CONFIGURATION . "
484
        (
485
            configuration_title,
486
            configuration_key,
487
            configuration_value,
488
            configuration_description,
489
            configuration_group_id,
490
            sort_order,
491
            date_added
492
        ) 
493
        values 
494
        (
495
            'Secret Key',
496
            'MODULE_PAYMENT_PAGANTIS_SK',
497
            '',
498
            'MANDATORY. You can get in your pagantis profile',
499
            '6',
500
            '0',
501
            now()
502
        )");
503
        tep_db_query("insert into " . TABLE_CONFIGURATION . "
504
        (
505
            configuration_title,
506
            configuration_key,
507
            configuration_value,
508
            configuration_description,
509
            configuration_group_id,
510
            sort_order,
511
            set_function,
512
            date_added
513
        ) 
514
        values 
515
        (
516
            'Include simulator',
517
            'MODULE_PAYMENT_PAGANTIS_SIMULATOR',
518
            'True',
519
            'Do you want to include Pagantis simulator',
520
            '6',
521
            '3',
522
            'tep_cfg_select_option(array(\'True\',\'False\'), ',
523
            now())"
524
        );
525
        $this->installPagantisTables();
526
527
        $this->installSimulator();
528
    }
529
530
    /**
531
     * Create the neccesary tables for the module
532
     */
533
    private function installPagantisTables()
534
    {
535
        $sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_LOG . " ( 
536
                          id int NOT NULL AUTO_INCREMENT, 
537
                          log text NOT NULL, 
538
                          createdAt timestamp DEFAULT CURRENT_TIMESTAMP, 
539
                          UNIQUE KEY id (id))";
540
        tep_db_query($sql);
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

540
        /** @scrutinizer ignore-call */ 
541
        tep_db_query($sql);
Loading history...
541
542
        $sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_CONFIG . " (
543
                            id int NOT NULL AUTO_INCREMENT, 
544
                            config varchar(60) NOT NULL, 
545
                            value varchar(200) NOT NULL, 
546
                            UNIQUE KEY id(id))";
547
        tep_db_query($sql);
548
549
        // check if table has records
550
        $check_query = tep_db_query("select value from " . TABLE_PAGANTIS_CONFIG);
551
        if (tep_db_num_rows($check_query) === 0) {
0 ignored issues
show
Bug introduced by
The function tep_db_num_rows 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

551
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($check_query) === 0) {
Loading history...
552
            foreach ((array)$this->defaultConfigs as $configKey => $configValue) {
553
                $query = "INSERT INTO " . TABLE_PAGANTIS_CONFIG . "
554
                (
555
                    config,
556
                    value
557
                ) 
558
                values 
559
                (
560
                    '$configKey',
561
                    '$configValue'
562
                )";
563
                tep_db_query($query);
564
            }
565
        }
566
567
        $sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_ORDERS . " (
568
                            id int NOT NULL AUTO_INCREMENT, 
569
                            os_order_id varchar(50), 
570
                            os_order_reference varchar(50) NOT NULL,
571
                            pagantis_order_id varchar(50) NOT NULL, 
572
                            globals text,
573
                            UNIQUE KEY id(id))";
574
        tep_db_query($sql);
575
576
        $sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_CONCURRENCY . " (
577
                            id varchar(50) NOT NULL,
578
                            `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
579
                            UNIQUE KEY id(id))";
580
        tep_db_query($sql);
581
    }
582
583
    /**
584
     * Standard functionality to uninstall the module.
585
     */
586
    public function remove()
587
    {
588
        $checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_LOG . "'");
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

588
        $checkTable = /** @scrutinizer ignore-call */ tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_LOG . "'");
Loading history...
589
        if (tep_db_num_rows($checkTable) > 0) {
0 ignored issues
show
Bug introduced by
The function tep_db_num_rows 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

589
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkTable) > 0) {
Loading history...
590
            tep_db_query("drop table " . TABLE_PAGANTIS_LOG);
591
        }
592
593
        $checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_CONFIG . "'");
594
        if (tep_db_num_rows($checkTable) > 0) {
595
            tep_db_query("drop table " . TABLE_PAGANTIS_CONFIG);
596
        }
597
598
        $checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_ORDERS . "'");
599
        if (tep_db_num_rows($checkTable) > 0) {
600
            tep_db_query("drop table " . TABLE_PAGANTIS_ORDERS);
601
        }
602
603
        $checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_CONCURRENCY . "'");
604
        if (tep_db_num_rows($checkTable) > 0) {
605
            tep_db_query("drop table " . TABLE_PAGANTIS_CONCURRENCY);
606
        }
607
608
        tep_db_query("DELETE FROM ". TABLE_CONFIGURATION ." where configuration_key in ('MODULE_PAYMENT_PAGANTIS_STATUS','MODULE_PAYMENT_PAGANTIS_PK','MODULE_PAYMENT_PAGANTIS_SK')");
0 ignored issues
show
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
609
610
        $query = "delete from " . TABLE_CONFIGURATION . " where configuration_key like '%_PAGANTIS_%'";
611
        tep_db_query($query);
612
613
        $this->uninstallSimulator();
614
    }
615
616
    /**
617
     * Internal list of configuration keys used for configuration of the module
618
     *
619
     * @return array
620
     */
621
    public function keys()
622
    {
623
        return array(
624
            'MODULE_PAYMENT_PAGANTIS_STATUS',
625
            'MODULE_PAYMENT_PAGANTIS_PK',
626
            'MODULE_PAYMENT_PAGANTIS_SK',
627
            'MODULE_PAYMENT_PAGANTIS_SIMULATOR'
628
        );
629
    }
630
631
    /**
632
     * @return array
633
     */
634
    private function getOrders()
635
    {
636
        $this->is_guest = 'true';
637
        if (trim($_SESSION['customer_id']) != '') {
638
            $this->is_guest = 'false';
639
            $query = sprintf(
640
                "select orders_total.value, orders.date_purchased from orders 
641
JOIN orders_status_history ON orders.orders_id=orders_status_history.orders_id 
642
JOIN orders_total ON orders.orders_id=orders_total.orders_id 
643
where orders.customers_id='%s' and orders_status_history.orders_status_id in ('2','3') 
644
and orders_total.class='ot_total'",
645
                $_SESSION['customer_id']
646
            );
647
648
            $response = array();
649
            $resultsSelect = tep_db_query($query);
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

649
            $resultsSelect = /** @scrutinizer ignore-call */ tep_db_query($query);
Loading history...
650
            while ($orderRow = tep_db_fetch_array($resultsSelect)) {
0 ignored issues
show
Bug introduced by
The function tep_db_fetch_array 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

650
            while ($orderRow = /** @scrutinizer ignore-call */ tep_db_fetch_array($resultsSelect)) {
Loading history...
651
                $response[] = $orderRow;
652
            }
653
        }
654
655
        return $response;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $response does not seem to be defined for all execution paths leading up to this point.
Loading history...
656
    }
657
658
    /**
659
     * @return array
660
     */
661
    private function getMemberSince()
662
    {
663
        $memberSince = null;
664
        if (trim($_SESSION['customer_id']) != '') {
665
            $query = sprintf(
666
                "select customers_info_date_account_created from customers_info where customers_info_id='%s'",
667
                $_SESSION['customer_id']
668
            );
669
670
            $response = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
671
            $resultsSelect = tep_db_query($query);
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

671
            $resultsSelect = /** @scrutinizer ignore-call */ tep_db_query($query);
Loading history...
672
            $orderRow = tep_db_fetch_array($resultsSelect);
0 ignored issues
show
Bug introduced by
The function tep_db_fetch_array 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

672
            $orderRow = /** @scrutinizer ignore-call */ tep_db_fetch_array($resultsSelect);
Loading history...
673
            $memberSince = date('Y-m-d', strtotime($orderRow['customers_info_date_account_created']));
674
        }
675
        return $memberSince;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $memberSince also could return the type string which is incompatible with the documented return type array.
Loading history...
676
    }
677
678
    /**
679
     * @param $orderId
680
     * @param $pagantisOrderId
681
     * @param $globalVars
682
     */
683
    private function insertRow($orderId, $pagantisOrderId, $globalVars)
684
    {
685
        $query = "select * from " . TABLE_PAGANTIS_ORDERS . " where os_order_reference='$orderId'";
686
        $resultsSelect = tep_db_query($query);
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

686
        $resultsSelect = /** @scrutinizer ignore-call */ tep_db_query($query);
Loading history...
687
        $countResults = tep_db_num_rows($resultsSelect);
0 ignored issues
show
Bug introduced by
The function tep_db_num_rows 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

687
        $countResults = /** @scrutinizer ignore-call */ tep_db_num_rows($resultsSelect);
Loading history...
688
        if ($countResults == 0) {
689
            $query = "INSERT INTO " . TABLE_PAGANTIS_ORDERS . " 
690
                (os_order_reference, pagantis_order_id, globals) values ('$orderId', '$pagantisOrderId','$globalVars')";
691
        } else {
692
            $query = "UPDATE ".TABLE_PAGANTIS_ORDERS." set pagantis_order_id='$pagantisOrderId' 
693
                        where os_order_reference='$orderId'";
694
        }
695
        tep_db_query($query);
696
    }
697
698
    /**
699
     * @return array
700
     */
701
    private function getExtraConfig()
702
    {
703
        $checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'");
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

703
        $checkTable = /** @scrutinizer ignore-call */ tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'");
Loading history...
704
        $response = array();
705
        if (tep_db_num_rows($checkTable) > 0) {
0 ignored issues
show
Bug introduced by
The function tep_db_num_rows 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

705
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkTable) > 0) {
Loading history...
706
            $query       = "select * from ".TABLE_PAGANTIS_CONFIG;
707
            $result      = tep_db_query($query);
708
            $response    = array();
709
            while ($resultArray = tep_db_fetch_array($result)) {
0 ignored issues
show
Bug introduced by
The function tep_db_fetch_array 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

709
            while ($resultArray = /** @scrutinizer ignore-call */ tep_db_fetch_array($result)) {
Loading history...
710
                $response[$resultArray['config']] = $resultArray['value'];
711
            }
712
        }
713
714
        return $response;
715
    }
716
717
    /**
718
     * @param $item
719
     *
720
     * @return bool
721
     */
722
    private function isPromoted($item)
723
    {
724
        $productId = explode('{', $item['id'], 1);
725
        $productId = $productId['0'];
726
727
        if ($this->extraConfig['PAGANTIS_PROMOTION'] == '') {
728
            $promotedProducts = array();
729
        } else {
730
            $promotedProducts = array_values((array)unserialize($this->extraConfig['PAGANTIS_PROMOTION']));
731
        }
732
733
        return (in_array($productId, $promotedProducts));
734
    }
735
736
    /**
737
     * @return string
738
     */
739
    private function getDescription()
740
    {
741
        $descriptionCode = "<img src=\"images/icon_info.gif\" border=\"0\" alt=\"Info\" title=\"Info\">&nbsp;<strong>Module version:</strong> $this->version<br/><br/>";
742
        $descriptionCode.= "<img src=\"images/icon_info.gif\" border=\"0\">&nbsp;<a href='https://developer.pagantis.com/' target=\"_blank\" style=\"text-decoration: underline; font-weight: bold;\">View Online Documentation</a><br/><br/>";
743
        $descriptionCode.= "<img src='images/icon_popup.gif'  border='0'>        <a href='http://pagantis.com' target='_blank' style='text-decoration: underline; font-weight: bold;'>Visit Pagantis Website</a><br/><br/><br/>";
744
745
        if (MODULE_PAYMENT_PAGANTIS_STATUS == 'True') {
0 ignored issues
show
Bug introduced by
The constant MODULE_PAYMENT_PAGANTIS_STATUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
746
            $pagantisPromotionUrl = $this->base_url.'/admin/promotion.php';
747
            $linkDescription = "Si deseas ofrecer financiación sin intereses para alguno de tus productos ";
748
            $descriptionCode.= "<img src='images/icon_info.gif' border='0'/> $linkDescription<a href='$pagantisPromotionUrl' style='text-decoration: underline; font-weight: bold;'>haz click aquí</a>";
749
750
            $pagantisAllowedCountriesUrl = $this->base_url.'/admin/allowedCountries.php';
751
            $linkDescription = "Para gestionar paises en los que operar con Pagantis ";
752
            $descriptionCode.= "<br/><br/><img src='images/icon_info.gif' border='0'/> $linkDescription<a href='$pagantisAllowedCountriesUrl' style='text-decoration: underline; font-weight: bold;'>haz click aquí</a>";
753
        }
754
755
        return $descriptionCode;
756
    }
757
758
    /**
759
     * @return bool
760
     */
761
    private function installSimulator()
762
    {
763
        $checkSimulator = tep_db_query("select configuration_key, configuration_value from " .TABLE_CONFIGURATION ." 
0 ignored issues
show
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function tep_db_query 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

763
        $checkSimulator = /** @scrutinizer ignore-call */ tep_db_query("select configuration_key, configuration_value from " .TABLE_CONFIGURATION ." 
Loading history...
764
                                    where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'
765
                                    and configuration_value like '%ht_pagantis.php%';");
766
        if (tep_db_num_rows($checkSimulator) > 0) {
0 ignored issues
show
Bug introduced by
The function tep_db_num_rows 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

766
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkSimulator) > 0) {
Loading history...
767
            return true;
768
        }
769
770
        $query = "UPDATE " . TABLE_CONFIGURATION . " set configuration_value = concat(configuration_value, ';ht_pagantis.php')
771
                        where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'";
772
        tep_db_query($query);
773
774
        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Pagantis Module', 'MODULE_HEADER_TAGS_PAGANTIS_STATUS', 'True', '', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
775
    }
776
777
    /**
778
     * @return bool
779
     */
780
    private function uninstallSimulator()
781
    {
782
        $checkSimulator = tep_db_query("select configuration_key, configuration_value from " .TABLE_CONFIGURATION ." 
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

782
        $checkSimulator = /** @scrutinizer ignore-call */ tep_db_query("select configuration_key, configuration_value from " .TABLE_CONFIGURATION ." 
Loading history...
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
783
                                    where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'
784
                                    and configuration_value like '%ht_pagantis.php%';");
785
        if (tep_db_num_rows($checkSimulator) == 0) {
0 ignored issues
show
Bug introduced by
The function tep_db_num_rows 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

785
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkSimulator) == 0) {
Loading history...
786
            return true;
787
        }
788
789
        $query = "UPDATE " . TABLE_CONFIGURATION . " set configuration_value = REPLACE(configuration_value, ';ht_pagantis.php', '')
790
                        where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'";
791
        tep_db_query($query);
792
793
        $query = "delete from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_HEADER_TAGS_PAGANTIS_STATUS'";
794
        tep_db_query($query);
795
    }
796
797
    /**
798
     * @param $exception
799
     */
800
    private function insertLog($exception)
801
    {
802
        if ($exception instanceof \Exception) {
803
            $logEntry= new LogEntry();
804
            $logEntryJson = $logEntry->error($exception)->toJson();
805
            $logEntryJson = addslashes($logEntryJson);
806
807
            $query = "insert into ".TABLE_PAGANTIS_LOG."(log) values ('$logEntryJson')";
808
            tep_db_query($query);
0 ignored issues
show
Bug introduced by
The function tep_db_query 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

808
            /** @scrutinizer ignore-call */ 
809
            tep_db_query($query);
Loading history...
809
        }
810
    }
811
812
    /**
813
     * @return null
814
     */
815
    private function getNationalId()
816
    {
817
        global $order;
818
        if (isset($order->customer['national_id'])) {
819
            return $order->customer['national_id'];
820
        } elseif (isset($order->billing['piva'])) {
821
            return $order->billing['piva'];
822
        } else {
823
            return null;
824
        }
825
    }
826
827
    /**
828
     * @return null
829
     */
830
    private function getTaxId()
831
    {
832
        global $order;
833
        if (isset($order->customer['tax_id'])) {
834
            return $order->customer['tax_id'];
835
        } elseif (isset($order->billing['cf'])) {
836
            return $order->billing['cf'];
837
        } else {
838
            return null;
839
        }
840
    }
841
}
842