Passed
Pull Request — master (#28)
by Raúl
02:16
created

pagantis::getMemberSince()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 15
rs 9.9332
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
                ->setTaxId($tax_id);
238
239
            $orderBillingAddress = $userAddress;
240
            $orderShippingAddress = new Address();
241
            $orderShippingAddress
242
                ->setZipCode($order->delivery['postcode'])
243
                ->setFullName($fullName)
244
                ->setCountryCode($order->delivery['country']['iso_code'])
245
                ->setCity($order->delivery['city'])
246
                ->setAddress($order->delivery['street_address'])
247
                ->setFixPhone($order->customer['telephone'])
248
                ->setMobilePhone($order->customer['telephone']);
249
250
            $orderUser = new \Pagantis\OrdersApiClient\Model\Order\User();
251
            $orderUser
252
                ->setAddress($userAddress)
253
                ->setFullName($fullName)
254
                ->setBillingAddress($orderBillingAddress)
255
                ->setEmail($order->customer['email_address'])
256
                ->setFixPhone($order->customer['telephone'])
257
                ->setMobilePhone($order->customer['telephone'])
258
                ->setShippingAddress($orderShippingAddress)
259
                ->setNationalId($national_id)
260
                ->setTaxId($tax_id);
261
262
            $previousOrders = $this->getOrders();
263
            foreach ((array)$previousOrders as $k => $previousOrder) {
264
                $orderHistory = new \Pagantis\OrdersApiClient\Model\Order\User\OrderHistory();
265
                $orderHistory
266
                    ->setAmount(intval(100 * $previousOrder['value']))
267
                    ->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

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

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

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

419
            $check_query = /** @scrutinizer ignore-call */ tep_db_query($query);
Loading history...
420
            $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

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

434
            /** @scrutinizer ignore-call */ 
435
            tep_redirect(tep_href_link(FILENAME_MODULES, 'set=payment&module=pagantis', 'NONSSL'));
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

434
            tep_redirect(/** @scrutinizer ignore-call */ tep_href_link(FILENAME_MODULES, 'set=payment&module=pagantis', 'NONSSL'));
Loading history...
435
            return 'failed';
436
        }
437
438
        tep_db_query("insert into " . 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

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

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

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

586
        $checkTable = /** @scrutinizer ignore-call */ tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_LOG . "'");
Loading history...
587
        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

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

647
            $resultsSelect = /** @scrutinizer ignore-call */ tep_db_query($query);
Loading history...
648
            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

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

669
            $resultsSelect = /** @scrutinizer ignore-call */ tep_db_query($query);
Loading history...
670
            $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

670
            $orderRow = /** @scrutinizer ignore-call */ tep_db_fetch_array($resultsSelect);
Loading history...
671
            $memberSince = date('Y-m-d', strtotime($orderRow['customers_info_date_account_created']));
672
        }
673
        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...
674
    }
675
676
    /**
677
     * @param $orderId
678
     * @param $pagantisOrderId
679
     * @param $globalVars
680
     */
681
    private function insertRow($orderId, $pagantisOrderId, $globalVars)
682
    {
683
        $query = "select * from " . TABLE_PAGANTIS_ORDERS . " where os_order_reference='$orderId'";
684
        $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

684
        $resultsSelect = /** @scrutinizer ignore-call */ tep_db_query($query);
Loading history...
685
        $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

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

701
        $checkTable = /** @scrutinizer ignore-call */ tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'");
Loading history...
702
        $response = array();
703
        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

703
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkTable) > 0) {
Loading history...
704
            $query       = "select * from ".TABLE_PAGANTIS_CONFIG;
705
            $result      = tep_db_query($query);
706
            $response    = array();
707
            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

707
            while ($resultArray = /** @scrutinizer ignore-call */ tep_db_fetch_array($result)) {
Loading history...
708
                $response[$resultArray['config']] = $resultArray['value'];
709
            }
710
        }
711
712
        return $response;
713
    }
714
715
    /**
716
     * @param $item
717
     *
718
     * @return bool
719
     */
720
    private function isPromoted($item)
721
    {
722
        $productId = explode('{', $item['id'], 1);
723
        $productId = $productId['0'];
724
725
        if ($this->extraConfig['PAGANTIS_PROMOTION'] == '') {
726
            $promotedProducts = array();
727
        } else {
728
            $promotedProducts = array_values((array)unserialize($this->extraConfig['PAGANTIS_PROMOTION']));
729
        }
730
731
        return (in_array($productId, $promotedProducts));
732
    }
733
734
    /**
735
     * @return string
736
     */
737
    private function getDescription()
738
    {
739
        $descriptionCode = "<img src=\"images/icon_info.gif\" border=\"0\" alt=\"Info\" title=\"Info\">&nbsp;<strong>Module version:</strong> $this->version<br/><br/>";
740
        $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/>";
741
        $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/>";
742
743
        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...
744
            $pagantisPromotionUrl = $this->base_url.'/admin/promotion.php';
745
            $linkDescription = "Si deseas ofrecer financiación sin intereses para alguno de tus productos ";
746
            $descriptionCode.= "<img src='images/icon_info.gif' border='0'/> $linkDescription<a href='$pagantisPromotionUrl' style='text-decoration: underline; font-weight: bold;'>haz click aquí</a>";
747
748
            $pagantisAllowedCountriesUrl = $this->base_url.'/admin/allowedCountries.php';
749
            $linkDescription = "Para gestionar paises en los que operar con Pagantis ";
750
            $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>";
751
        }
752
753
        return $descriptionCode;
754
    }
755
756
    /**
757
     * @return bool
758
     */
759
    private function installSimulator()
760
    {
761
        $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

761
        $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...
762
                                    where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'
763
                                    and configuration_value like '%ht_pagantis.php%';");
764
        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

764
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkSimulator) > 0) {
Loading history...
765
            return true;
766
        }
767
768
        $query = "UPDATE " . TABLE_CONFIGURATION . " set configuration_value = concat(configuration_value, ';ht_pagantis.php')
769
                        where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'";
770
        tep_db_query($query);
771
772
        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())");
773
    }
774
775
    /**
776
     * @return bool
777
     */
778
    private function uninstallSimulator()
779
    {
780
        $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

780
        $checkSimulator = /** @scrutinizer ignore-call */ tep_db_query("select configuration_key, configuration_value from " .TABLE_CONFIGURATION ." 
Loading history...
781
                                    where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'
782
                                    and configuration_value like '%ht_pagantis.php%';");
783
        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

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

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