notifyController::confirmInformation()   A
last analyzed

Complexity

Conditions 3
Paths 14

Size

Total Lines 24
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 20
nc 14
nop 0
dl 0
loc 24
rs 9.6
c 0
b 0
f 0
1
<?php
2
3
use Pagantis\OrdersApiClient\Client;
4
use Pagantis\ModuleUtils\Exception\AlreadyProcessedException;
5
use Pagantis\ModuleUtils\Exception\AmountMismatchException;
6
use Pagantis\ModuleUtils\Exception\MerchantOrderNotFoundException;
7
use Pagantis\ModuleUtils\Exception\NoIdentificationException;
8
use Pagantis\ModuleUtils\Exception\OrderNotFoundException;
9
use Pagantis\ModuleUtils\Exception\QuoteNotFoundException;
10
use Pagantis\ModuleUtils\Exception\UnknownException;
11
use Pagantis\ModuleUtils\Exception\WrongStatusException;
12
use Pagantis\ModuleUtils\Model\Response\JsonSuccessResponse;
13
use Pagantis\ModuleUtils\Model\Response\JsonExceptionResponse;
14
use Pagantis\ModuleUtils\Exception\ConcurrencyException;
15
use Pagantis\ModuleUtils\Model\Log\LogEntry;
16
use Pagantis\OrdersApiClient\Model\Order;
17
18
define('TABLE_PAGANTIS_LOG', 'pagantis_log');
19
define('TABLE_PAGANTIS_CONFIG', 'pagantis_config');
20
define('TABLE_PAGANTIS_ORDERS', 'pagantis_order');
21
define('TABLE_PAGANTIS_CONCURRENCY', 'pagantis_concurrency');
22
23
class notifyController
24
{
25
    /** Seconds to expire a locked request */
26
    const CONCURRENCY_TIMEOUT = 10;
27
28
    /** @var mixed $pagantisOrder */
29
    protected $pagantisOrder;
30
31
    /** @var $string $origin */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $string at position 0 could not be parsed: Unknown type name '$string' at position 0 in $string.
Loading history...
32
    public $origin;
33
34
    /** @var $string */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $string at position 0 could not be parsed: Unknown type name '$string' at position 0 in $string.
Loading history...
35
    public $order;
36
37
    /** @var mixed $oscommerceOrderId */
38
    protected $oscommerceOrderId = '';
39
40
    /** @var mixed $cfg */
41
    protected $cfg;
42
43
    /** @var Client $orderClient */
44
    protected $orderClient;
45
46
    /** @var Order $oscommerceOrder */
47
    protected $oscommerceOrder;
48
49
    /** @var mixed $pagantisOrderId */
50
    protected $pagantisOrderId = '';
51
52
    /** @var array $extraConfig */
53
    protected $extraConfig;
54
55
    /**
56
     * notifyController constructor.
57
     */
58
    public function __construct()
59
    {
60
        $this->extraConfig = $this->getExtraConfig();
61
    }
62
63
    /**
64
     * Validation vs PagantisClient
65
     *
66
     * @return array|Array_
0 ignored issues
show
Bug introduced by
The type Array_ was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
     * @throws Exception
68
     */
69
    public function processInformation()
70
    {
71
        require_once('vendor/autoload.php');
72
        try {
73
            $this->checkConcurrency();
74
            $this->getMerchantOrder();
75
            $this->getPagantisOrderId();
76
            $this->getPagantisOrder();
77
            $this->checkOrderStatus();
78
            $this->checkMerchantOrderStatus();
79
            $this->validateAmount();
80
            //$this->processMerchantOrder(); //ESTE PASO SE HACE EN EL CHECKOUT_PROCESS
81
        } catch (\Exception $exception) {
82
            $this->unblockConcurrency($this->oscommerceOrderId);
83
            $jsonResponse = new JsonExceptionResponse();
84
            $jsonResponse->setMerchantOrderId($this->merchantOrderId);
85
            $jsonResponse->setPagantisOrderId($this->pagantisOrderId);
86
            $jsonResponse->setException($exception);
87
            $this->insertLog($exception);
88
89
            if ($this->extraConfig['PAGANTIS_URL_KO'] =! '') {
90
                $koUrl = $this->extraConfig['PAGANTIS_URL_KO'];
91
            } else {
92
                $koUrl = trim(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL', false));
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

92
                $koUrl = trim(/** @scrutinizer ignore-call */ tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL', false));
Loading history...
Bug introduced by
The constant FILENAME_CHECKOUT_SHIPPING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
93
            }
94
95
            if ($this->origin == 'notify') {
96
                $jsonResponse->printResponse();
97
            } else {
98
                if ($exception->getMessage() == AlreadyProcessedException::ERROR_MESSAGE) {
99
                    if ($this->extraConfig['PAGANTIS_URL_OK']!='') {
100
                        $confirmationUrl = $this->extraConfig['PAGANTIS_URL_OK'];
101
                        $confirmationUrl.="?order_id=$this->merchantOrderId";
102
                    } else {
103
                        $confirmationUrl = trim(tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, '', 'SSL', false));
0 ignored issues
show
Bug introduced by
The constant FILENAME_ACCOUNT_HISTORY_INFO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
104
                        $confirmationUrl.="?order_id=$this->merchantOrderId";
105
                    }
106
107
                    header("Location: $confirmationUrl");
108
                    exit;
109
                }
110
111
                header("Location: $koUrl");
112
                exit;
113
            }
114
        }
115
    }
116
117
    public function confirmInformation()
118
    {
119
        try {
120
            $this->confirmPagantisOrder();
121
            $this->updateBdInfo();
122
            $jsonResponse = new JsonSuccessResponse();
123
            $jsonResponse->setMerchantOrderId($this->merchantOrderId);
124
            $jsonResponse->setPagantisOrderId($this->pagantisOrderId);
125
            $this->unblockConcurrency($this->oscommerceOrderId);
126
        } catch (\Exception $exception) {
127
            $this->rollbackMerchantOrder();
128
            $this->unblockConcurrency($this->oscommerceOrderId);
129
            $jsonResponse = new JsonExceptionResponse();
130
            $jsonResponse->setMerchantOrderId($this->merchantOrderId);
131
            $jsonResponse->setPagantisOrderId($this->pagantisOrderId);
132
            $jsonResponse->setException($exception);
133
            $jsonResponse->toJson();
134
            $this->insertLog($exception);
135
        }
136
137
        if ($this->origin == 'notify') {
138
            $jsonResponse->printResponse();
139
        } else {
140
            return $jsonResponse;
141
        }
142
    }
143
144
    /**
145
     * COMMON FUNCTIONS
146
     */
147
148
    /**
149
     * @throws Exception
150
     */
151
    private function checkConcurrency()
152
    {
153
        $this->getQuoteId();
154
        $this->checkConcurrencyTable();
155
        $this->unblockConcurrency();
156
        $this->blockConcurrency();
157
    }
158
159
    /**
160
     * @throws MerchantOrderNotFoundException
161
     */
162
    private function getMerchantOrder()
163
    {
164
        global $order;
165
        $this->oscommerceOrder = $order;
166
        if (!isset($order->info)) {
167
            throw new MerchantOrderNotFoundException();
168
        }
169
    }
170
171
    /**
172
     * @throws NoIdentificationException
173
     */
174
    private function getPagantisOrderId()
175
    {
176
        $query = sprintf(
177
            "select pagantis_order_id from %s where os_order_reference='%s'",
178
            TABLE_PAGANTIS_ORDERS,
179
            $this->oscommerceOrderId
180
        );
181
        $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

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

182
        while ($orderRow = /** @scrutinizer ignore-call */ tep_db_fetch_array($resultsSelect)) {
Loading history...
183
            $this->pagantisOrderId = $orderRow['pagantis_order_id'];
184
        }
185
186
        if ($this->pagantisOrderId == '') {
187
            throw new NoIdentificationException();
188
        }
189
    }
190
191
    /**
192
     * @throws OrderNotFoundException
193
     */
194
    private function getPagantisOrder()
195
    {
196
        try {
197
            $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...
198
            $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...
199
            $this->orderClient   = new \Pagantis\OrdersApiClient\Client($publicKey, $secretKey);
200
            /** @var Pagantis\OrdersApiClient\Model\Order pagantisOrder */
201
            $this->pagantisOrder = $this->orderClient->getOrder($this->pagantisOrderId);
202
        } catch (\Exception $e) {
203
            throw new OrderNotFoundException();
204
        }
205
    }
206
207
    /**
208
     * @throws AlreadyProcessedException
209
     * @throws WrongStatusException
210
     */
211
    private function checkOrderStatus()
212
    {
213
        try {
214
            $this->checkPagantisStatus(array('AUTHORIZED'));
215
        } catch (\Exception $e) {
216
            if ($this->findOscommerceOrderId()!='') {
217
                throw new AlreadyProcessedException();
218
            } else {
219
                if ($this->pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) {
220
                    $status = $this->pagantisOrder->getStatus();
221
                } else {
222
                    $status = '-';
223
                }
224
                throw new WrongStatusException($status);
225
            }
226
        }
227
    }
228
229
    /**
230
     * @throws AlreadyProcessedException
231
     */
232
    private function checkMerchantOrderStatus()
233
    {
234
        global $order;
235
236
        if ($order->info['order_status']!=='1') {
237
            throw new AlreadyProcessedException();
238
        }
239
    }
240
241
    /**
242
     * @throws AmountMismatchException
243
     */
244
    private function validateAmount()
245
    {
246
        $pagantisAmount = $this->pagantisOrder->getShoppingCart()->getTotalAmount();
247
        $ocAmount = intval($this->oscommerceOrder->info['total'] * 100);
0 ignored issues
show
Bug introduced by
The property info does not seem to exist on Pagantis\OrdersApiClient\Model\Order.
Loading history...
248
249
        if ($pagantisAmount != $ocAmount) {
250
            throw new AmountMismatchException($pagantisAmount, $ocAmount);
251
        }
252
    }
253
254
    /**
255
     * @return false|string
256
     * @throws UnknownException
257
     */
258
    private function confirmPagantisOrder()
259
    {
260
        try {
261
            $this->pagantisOrder = $this->orderClient->confirmOrder($this->pagantisOrderId);
262
        } catch (\Exception $e) {
263
            /** @var Pagantis\OrdersApiClient\Model\Order pagantisOrder */
264
            $this->pagantisOrder = $this->orderClient->getOrder($this->pagantisOrderId);
265
            if ($this->pagantisOrder->getStatus() !== Order::STATUS_CONFIRMED) {
266
                throw new UnknownException($e->getMessage());
267
            } else {
268
                $logMessage = 'Concurrency issue: Order_id '.$this->pagantisOrderId.' was confirmed by other process';
269
                $this->insertLog(null, $logMessage);
270
            }
271
272
        }
273
274
        $jsonResponse = new JsonSuccessResponse();
275
        return $jsonResponse->toJson();
276
    }
277
    /**
278
     * UTILS FUNCTIONS
279
     */
280
281
    /** STEP 1 CC - Check concurrency */
282
283
    /**
284
     * @throws QuoteNotFoundException
285
     */
286
    private function getQuoteId()
287
    {
288
        if ($this->oscommerceOrderId == "") {
289
            throw new QuoteNotFoundException();
290
        }
291
    }
292
293
    /**
294
     * Check if concurrency table exists
295
     */
296
    private function checkConcurrencyTable()
297
    {
298
        $checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONCURRENCY."'");
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

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

299
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkTable) == 0) {
Loading history...
300
            $sql = "CREATE TABLE IF NOT EXISTS ".TABLE_PAGANTIS_CONCURRENCY." (
301
                            id int NOT NULL,
302
                            `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
303
                            UNIQUE KEY id(id))";
304
            tep_db_query($sql);
305
        }
306
        return;
307
    }
308
309
    /**
310
     * Unlock the concurrency
311
     *
312
     * @param null $orderId
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $orderId is correct as it would always require null to be passed?
Loading history...
313
     * @throws Exception
314
     */
315
    private function unblockConcurrency($orderId = null)
316
    {
317
        try {
318
            if ($orderId == null) {
0 ignored issues
show
introduced by
The condition $orderId == null is always true.
Loading history...
319
                $query = sprintf(
320
                    "delete from %s where timestamp<TIMESTAMPADD(SECOND, -%s, CURRENT_TIMESTAMP)",
321
                    TABLE_PAGANTIS_CONCURRENCY,
322
                    self::CONCURRENCY_TIMEOUT
323
                );
324
                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

324
                /** @scrutinizer ignore-call */ 
325
                tep_db_query($query);
Loading history...
325
            } elseif ($orderId!='') {
326
                $query = "delete from ".TABLE_PAGANTIS_CONCURRENCY." where id='$orderId'";
327
                tep_db_query($query);
328
            }
329
        } catch (Exception $exception) {
330
            throw new ConcurrencyException();
331
        }
332
    }
333
334
    /**
335
     * @throws \Exception
336
     */
337
    private function blockConcurrency()
338
    {
339
        try {
340
            $query = "SELECT timestamp FROM ".TABLE_PAGANTIS_CONCURRENCY." where id='$this->oscommerceOrderId'";
341
            $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

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

342
            $orderRow = /** @scrutinizer ignore-call */ tep_db_fetch_array($resultsSelect);
Loading history...
343
            if (isset($orderRow['timestamp'])) {
344
                if ($this->origin == 'notify') {
345
                    throw new ConcurrencyException();
346
                } else {
347
                    $query = sprintf(
348
                        "SELECT TIMESTAMPDIFF(SECOND,NOW()-INTERVAL %s SECOND, timestamp) as rest FROM %s %s",
349
                        self::CONCURRENCY_TIMEOUT,
350
                        TABLE_PAGANTIS_CONCURRENCY,
351
                        "WHERE id='".$this->oscommerceOrderId."'"
352
                    );
353
                    $resultsSelect = tep_db_query($query);
354
                    $resultsArray = tep_db_fetch_array($resultsSelect);
355
                    $restSeconds = isset($resultsArray['rest']) ? ($resultsArray['rest']) : 0;
356
                    $expirationSec = ($restSeconds>self::CONCURRENCY_TIMEOUT)? self::CONCURRENCY_TIMEOUT : $restSeconds;
357
                    if ($expirationSec > 0) {
358
                        sleep($expirationSec + 1);
359
                    }
360
361
                    //Check if the notification have been processed
362
                    $query = sprintf(
363
                        "select os_order_id from %s where os_order_reference='%s'",
364
                        TABLE_PAGANTIS_ORDERS,
365
                        $this->oscommerceOrderId
366
                    );
367
                    $resultsSelect = tep_db_query($query);
368
                    $os_order_id = tep_db_fetch_array($resultsSelect);
369
                    if (isset($os_order_id['os_order_id'])) {
370
                        $redirectUrl = trim(tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, '', 'SSL', false));
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

370
                        $redirectUrl = trim(/** @scrutinizer ignore-call */ tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, '', 'SSL', false));
Loading history...
Bug introduced by
The constant FILENAME_ACCOUNT_HISTORY_INFO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
371
                        $redirectUrl.="?order_id=$this->oscommerceOrderId";
372
                    } else {
373
                        $redirectUrl = 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...
374
                    }
375
376
                    $logMessage = sprintf(
377
                        "User waiting %s seconds, default seconds %s, bd time to expire %s seconds => Url: %s",
378
                        $expirationSec,
379
                        self::CONCURRENCY_TIMEOUT,
380
                        $restSeconds,
381
                        $redirectUrl
382
                    );
383
                    $this->insertLog(null, $logMessage);
384
385
                    header("Location: $redirectUrl");
386
                    exit;
387
                }
388
            } else {
389
                $query = "INSERT INTO ".TABLE_PAGANTIS_CONCURRENCY." (id) VALUES ('$this->oscommerceOrderId');";
390
                tep_db_query($query);
391
            }
392
        } catch (Exception $exception) {
393
            throw new ConcurrencyException();
394
        }
395
    }
396
397
    /** STEP 2 GMO - Get Merchant Order */
398
    /** STEP 3 GPOI - Get Pagantis OrderId */
399
    /** STEP 4 GPO - Get Pagantis Order */
400
    /** STEP 5 COS - Check Order Status */
401
    /**
402
     * @param $statusArray
403
     *
404
     * @throws \Exception
405
     */
406
    private function checkPagantisStatus($statusArray)
407
    {
408
        $pagantisStatus = array();
409
        foreach ($statusArray as $status) {
410
            $pagantisStatus[] = constant("\Pagantis\OrdersApiClient\Model\Order::STATUS_$status");
411
        }
412
413
        if ($this->pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) {
414
            $payed = in_array($this->pagantisOrder->getStatus(), $pagantisStatus);
415
            if (!$payed) {
416
                if ($this->pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) {
0 ignored issues
show
introduced by
$this->pagantisOrder is always a sub-type of Pagantis\OrdersApiClient\Model\Order.
Loading history...
417
                    $status = $this->pagantisOrder->getStatus();
418
                } else {
419
                    $status = '-';
420
                }
421
                throw new WrongStatusException($status);
422
            }
423
        } else {
424
            throw new OrderNotFoundException();
425
        }
426
    }
427
428
    /**
429
     * @return mixed
430
     */
431
    private function findOscommerceOrderId()
432
    {
433
        $query = sprintf(
434
            "select os_order_id from %s where os_order_reference='%s'",
435
            TABLE_PAGANTIS_ORDERS,
436
            $this->oscommerceOrderId
437
        );
438
        $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

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

439
        $orderRow = /** @scrutinizer ignore-call */ tep_db_fetch_array($resultsSelect);
Loading history...
440
        $this->merchantOrderId = $orderRow['os_order_id'];
0 ignored issues
show
Bug Best Practice introduced by
The property merchantOrderId does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
441
442
        return $orderRow['os_order_id'];
443
    }
444
445
    /** STEP 6 CMOS - Check Merchant Order Status */
446
    /** STEP 7 VA - Validate Amount */
447
    /** STEP 8 PMO - Process Merchant Order */
448
449
    /**
450
     * Save the order status with the related identification
451
     */
452
    private function updateBdInfo()
453
    {
454
        global $insert_id;
455
        $this->merchantOrderId = $insert_id;
0 ignored issues
show
Bug Best Practice introduced by
The property merchantOrderId does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
456
        $query = sprintf(
457
            "update %s set os_order_id='%s' where os_order_reference='%s'",
458
            TABLE_PAGANTIS_ORDERS,
459
            $insert_id,
460
            $this->oscommerceOrderId
461
        );
462
        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

462
        /** @scrutinizer ignore-call */ 
463
        tep_db_query($query);
Loading history...
463
464
        $metadataOrder = $this->pagantisOrder->getMetadata();
465
466
        $metadataInfo = '';
467
        foreach ($metadataOrder as $metadataKey => $metadataValue) {
468
            if ($metadataKey == 'promotedProduct') {
469
                $metadataInfo.= "/Producto promocionado = $metadataValue";
470
            }
471
        }
472
473
        $comment = "Pagantis id=$this->pagantisOrderId/Via=".ucfirst($this->origin)."/".$metadataInfo;
474
        $query = "insert into ".TABLE_ORDERS_STATUS_HISTORY ."(comments, orders_id, orders_status_id, customer_notified,
0 ignored issues
show
Bug introduced by
The constant TABLE_ORDERS_STATUS_HISTORY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
475
        date_added) values ('$comment', ".$insert_id.", '2', -1, now() )";
476
        tep_db_query($query);
477
478
        $query = "update ".TABLE_ORDERS." set orders_status='2' where orders_id='$insert_id'";
0 ignored issues
show
Bug introduced by
The constant TABLE_ORDERS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
479
        tep_db_query($query);
480
    }
481
482
    /** STEP 9 CPO - Confirmation Pagantis Order */
483
    private function rollbackMerchantOrder()
484
    {
485
        global $insert_id;
486
        $query = "update orders set orders_status='1' where orders_id='$insert_id' ";
487
        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

487
        /** @scrutinizer ignore-call */ 
488
        tep_db_query($query);
Loading history...
488
489
        $query = sprintf(
490
            "update %s set os_order_id='' where os_order_reference='%s'",
491
            TABLE_PAGANTIS_ORDERS,
492
            $this->oscommerceOrderId
493
        );
494
495
        tep_db_query($query);
496
    }
497
498
    /**
499
     * @param null $exception
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $exception is correct as it would always require null to be passed?
Loading history...
500
     * @param null $message
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $message is correct as it would always require null to be passed?
Loading history...
501
     */
502
    private function insertLog($exception = null, $message = null)
503
    {
504
        $logEntry= new LogEntry();
505
        if ($exception instanceof \Exception) {
506
            $logEntryJson = $logEntry->error($exception)->toJson();
507
        } else {
508
            $logEntryJson = $logEntry->info($message)->toJson();
509
        }
510
            $query = "insert into ".TABLE_PAGANTIS_LOG."(log) values ('$logEntryJson')";
511
            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

511
            /** @scrutinizer ignore-call */ 
512
            tep_db_query($query);
Loading history...
512
    }
513
514
    /**
515
     * @return array
516
     */
517
    private function getExtraConfig()
518
    {
519
        $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

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

521
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkTable) > 0) {
Loading history...
522
            $query       = "select * from ".TABLE_PAGANTIS_CONFIG;
523
            $result      = tep_db_query($query);
524
            $response    = array();
525
            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

525
            while ($resultArray = /** @scrutinizer ignore-call */ tep_db_fetch_array($result)) {
Loading history...
526
                $response[$resultArray['config']] = $resultArray['value'];
527
            }
528
        }
529
530
        return $response;
531
    }
532
533
    /***
534
     * SETTERS Y GETTERS
535
     */
536
537
    /**
538
     * @return mixed
539
     */
540
    public function getOscommerceOrderId()
541
    {
542
        return $this->oscommerceOrderId;
543
    }
544
545
    /**
546
     * @param $oscommerceOrderId
547
     */
548
    public function setOscommerceOrderId($oscommerceOrderId)
549
    {
550
        $this->oscommerceOrderId = $oscommerceOrderId;
551
    }
552
553
    /**
554
     * @return mixed
555
     */
556
    public function getOrigin()
557
    {
558
        return $this->origin;
559
    }
560
561
    /**
562
     * @param mixed $origin
563
     */
564
    public function setOrigin($origin)
565
    {
566
        $this->origin = $origin;
567
    }
568
569
    /**
570
     * @return String
571
     */
572
    public function getOrderStatus()
573
    {
574
        return $this->orderStatus;
575
    }
576
577
    /**
578
     * @param String $orderStatus
579
     */
580
    public function setOrderStatus($orderStatus)
581
    {
582
        $this->orderStatus = $orderStatus;
0 ignored issues
show
Bug Best Practice introduced by
The property orderStatus does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
583
    }
584
}
585