Passed
Pull Request — master (#82)
by
unknown
02:32
created

WcPagantisNotify::checkDbTable()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 12
rs 10
1
<?php
2
3
use Pagantis\OrdersApiClient\Client;
4
use Pagantis\ModuleUtils\Exception\ConcurrencyException;
5
use Pagantis\ModuleUtils\Exception\AlreadyProcessedException;
6
use Pagantis\ModuleUtils\Exception\AmountMismatchException;
7
use Pagantis\ModuleUtils\Exception\MerchantOrderNotFoundException;
8
use Pagantis\ModuleUtils\Exception\NoIdentificationException;
9
use Pagantis\ModuleUtils\Exception\OrderNotFoundException;
10
use Pagantis\ModuleUtils\Exception\QuoteNotFoundException;
11
use Pagantis\ModuleUtils\Exception\UnknownException;
12
use Pagantis\ModuleUtils\Exception\WrongStatusException;
13
use Pagantis\ModuleUtils\Model\Response\JsonSuccessResponse;
14
use Pagantis\ModuleUtils\Model\Response\JsonExceptionResponse;
15
use Pagantis\ModuleUtils\Model\Log\LogEntry;
16
use Pagantis\OrdersApiClient\Model\Order;
17
18
if (!defined('ABSPATH')) {
19
    exit;
20
}
21
22
class WcPagantisNotify extends WcPagantisGateway
23
{
24
25
26
    /** Seconds to expire a locked request */
27
    const CONCURRENCY_TIMEOUT = 5;
28
29
    /** @var mixed $pagantisOrder */
30
    protected $pagantisOrder;
31
32
    /** @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...
33
    public $origin;
34
35
    /** @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...
36
    public $order;
37
38
    /** @var mixed $woocommerceOrderId */
39
    protected $woocommerceOrderId = '';
40
41
    /** @var mixed $cfg */
42
    protected $cfg;
43
44
    /** @var Client $orderClient */
45
    protected $orderClient;
46
47
    /** @var  WC_Order $woocommerceOrder */
0 ignored issues
show
Bug introduced by
The type WC_Order 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...
48
    protected $woocommerceOrder;
49
50
    /** @var mixed $pagantisOrderId */
51
    protected $pagantisOrderId = '';
52
53
    /** @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...
54
    protected $product;
55
56
    /** @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...
57
    protected $urlToken = null;
58
59
    /**
60
     * Validation vs PagantisClient
61
     *
62
     * @return JsonExceptionResponse|JsonSuccessResponse
63
     * @throws ConcurrencyException
64
     */
65
    public function processInformation()
66
    {
67
        try {
68
            require_once(__ROOT__ . '/vendor/autoload.php');
69
            try {
70
                if ($_SERVER['REQUEST_METHOD'] == 'GET' && $_GET['origin'] == 'notification') {
71
                    return $this->buildResponse();
72
                }
73
74
75
                $this->checkConcurrency();
76
                $this->getProductType();
77
                $this->getMerchantOrder();
78
                $this->getPagantisOrderId();
79
                $this->getPagantisOrder();
80
                $checkAlreadyProcessed = $this->checkOrderStatus();
81
                if ($checkAlreadyProcessed) {
82
                    return $this->buildResponse();
83
                }
84
                $this->validateAmount();
85
                if ($this->checkMerchantOrderStatus()) {
86
                    $this->processMerchantOrder();
87
                }
88
            } catch (\Exception $exception) {
89
                $this->insertLog($exception);
90
91
                return $this->buildResponse($exception);
92
            }
93
94
            try {
95
                $this->confirmPagantisOrder();
96
97
                return $this->buildResponse();
98
            } catch (\Exception $exception) {
99
                $this->rollbackMerchantOrder();
100
                $this->insertLog($exception);
101
102
                return $this->buildResponse($exception);
103
            }
104
        } catch (\Exception $exception) {
105
            $this->insertLog($exception);
106
            return $this->buildResponse($exception);
107
        }
108
    }
109
110
    /**
111
     * COMMON FUNCTIONS
112
     */
113
114
    /**
115
     * @throws ConcurrencyException|QuoteNotFoundException
116
     */
117
    private function checkConcurrency()
118
    {
119
        $this->setWoocommerceOrderId();
120
        $this->unblockConcurrency();
121
        $this->blockConcurrency($this->woocommerceOrderId);
122
    }
123
124
    /**
125
     * getProductType
126
     */
127
    private function getProductType()
128
    {
129
        if ($_GET['product'] == '') {
130
            $this->setProduct(WcPagantisGateway::METHOD_ID);
131
        } else {
132
            $this->setProduct($_GET['product']);
133
        }
134
    }
135
136
    /**
137
     * @throws MerchantOrderNotFoundException
138
     */
139
    private function getMerchantOrder()
140
    {
141
        try {
142
            $this->woocommerceOrder = new WC_Order($this->woocommerceOrderId);
143
            $this->woocommerceOrder->set_payment_method_title($this->getProduct());
144
        } catch (\Exception $e) {
145
            throw new MerchantOrderNotFoundException();
146
        }
147
    }
148
149
    /**
150
     * @throws MerchantOrderNotFoundException
151
     */
152
    private function verifyOrderConformity()
153
    {
154
        global $wpdb;
155
        $this->checkDbTable();
156
        $tableName =$wpdb->prefix.PG_CART_PROCESS_TABLE;
157
        $tokenQuery = $wpdb->prepare(
158
            "SELECT COUNT(wc_order_id) 
159
                 FROM $tableName 
160
                 WHERE token=%s AND order_id=%s",
161
            array($this->getUrlToken(),$this->pagantisOrderId)
162
        );
163
        $tokenCount=$wpdb->get_var($tokenQuery);
164
165
        $orderIDQuery = $wpdb->prepare(
166
            "SELECT COUNT(token) 
167
                      FROM $tableName 
168
                      WHERE wc_order_id=%s AND order_id=%s",
169
            array($this->woocommerceOrderId,$this->pagantisOrderId)
170
        );
171
        $orderIDCount = $wpdb->get_var($orderIDQuery);
172
173
        if (!($tokenCount == 1 && $orderIDCount == 1)) {
174
            throw new MerchantOrderNotFoundException();
175
        }
176
    }
177
178
    private function getPagantisOrderId()
179
    {
180
        global $wpdb;
181
        $this->setUrlToken();
182
        $this->checkDbTable();
183
        $tableName = $wpdb->prefix.PG_CART_PROCESS_TABLE;
184
        $order_id = $wpdb->get_var("SELECT order_id FROM $tableName WHERE token='{$this->getUrlToken()}' ");
185
        $this->pagantisOrderId = $order_id;
186
        if (empty($this->pagantisOrderId)) {
187
            throw new NoIdentificationException();
188
        }
189
190
        $this->verifyOrderConformity();
191
    }
192
193
194
195
    /**
196
     * @throws OrderNotFoundException
197
     */
198
    private function getPagantisOrder()
199
    {
200
        try {
201
            $this->cfg = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

201
            $this->cfg = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
202
            $this->cfg = get_option('woocommerce_pagantis_settings');
203
            if ($this->isProduct4x()) {
204
                $publicKey = $this->cfg['pagantis_public_key_4x'];
205
                $secretKey = $this->cfg['pagantis_private_key_4x'];
206
            } else {
207
                $publicKey = $this->cfg['pagantis_public_key'];
208
                $secretKey = $this->cfg['pagantis_private_key'];
209
            }
210
211
            $this->orderClient = new Client($publicKey, $secretKey);
212
            $this->pagantisOrder = $this->orderClient->getOrder($this->pagantisOrderId);
213
        } catch (\Exception $e) {
214
            throw new OrderNotFoundException();
215
        }
216
    }
217
218
    /**
219
     * @return bool
220
     * @throws WrongStatusException
221
     */
222
    private function checkOrderStatus()
223
    {
224
        try {
225
            $this->checkPagantisStatus(array('AUTHORIZED'));
226
        } catch (\Exception $e) {
227
            if ($this->pagantisOrder instanceof Order) {
228
                $status = $this->pagantisOrder->getStatus();
229
            } else {
230
                $status = '-';
231
            }
232
233
            if ($status === Order::STATUS_CONFIRMED) {
234
                return true;
235
            }
236
            throw new WrongStatusException($status);
237
        }
238
    }
239
240
    /**
241
     * @return bool
242
     */
243
    private function checkMerchantOrderStatus()
244
    {
245
        //Order status reference => https://docs.woocommerce.com/document/managing-orders/
246
        $validStatus=array('on-hold', 'pending', 'failed', 'processing', 'completed');
247
        $isValidStatus = apply_filters(
0 ignored issues
show
Bug introduced by
The function apply_filters 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

247
        $isValidStatus = /** @scrutinizer ignore-call */ apply_filters(
Loading history...
248
            'woocommerce_valid_order_statuses_for_payment_complete',
249
            $validStatus,
250
            $this
251
        );
252
253
        if (!$this->woocommerceOrder->has_status($isValidStatus)) { // TO CONFIRM
254
            $logMessage = "WARNING checkMerchantOrderStatus." .
255
                          " Merchant order id:".$this->woocommerceOrder->get_id().
256
                          " Merchant order status:".$this->woocommerceOrder->get_status().
257
                          " Pagantis order id:".$this->pagantisOrder->getStatus().
258
                          " Pagantis order status:".$this->pagantisOrder->getId();
259
            $this->insertLog(null, $logMessage);
260
            $this->woocommerceOrder->add_order_note($logMessage);
261
            $this->woocommerceOrder->save();
262
            return false;
263
        }
264
265
        return true; //TO SAVE
266
    }
267
268
    /**
269
     * @throws AmountMismatchException
270
     */
271
    private function validateAmount()
272
    {
273
        $pagantisAmount = $this->pagantisOrder->getShoppingCart()->getTotalAmount();
274
        $wcAmount = intval(strval(100 * $this->woocommerceOrder->get_total()));
275
        if ($pagantisAmount != $wcAmount) {
276
            throw new AmountMismatchException($pagantisAmount, $wcAmount);
277
        }
278
    }
279
280
    /**
281
     * @throws Exception
282
     */
283
    private function processMerchantOrder()
284
    {
285
        $this->saveOrder();
286
        $this->updateBdInfo();
287
    }
288
289
    /**
290
     * @return false|string
291
     * @throws UnknownException
292
     */
293
    private function confirmPagantisOrder()
294
    {
295
        try {
296
            $this->pagantisOrder = $this->orderClient->confirmOrder($this->pagantisOrderId);
297
        } catch (\Exception $e) {
298
            $this->pagantisOrder = $this->orderClient->getOrder($this->pagantisOrderId);
299
            if ($this->pagantisOrder->getStatus() !== Order::STATUS_CONFIRMED) {
300
                throw new UnknownException($e->getMessage());
301
            } else {
302
                $logMessage = 'Concurrency issue: Order_id '.$this->pagantisOrderId.' was confirmed by other process';
303
                $this->insertLog(null, $logMessage);
304
            }
305
        }
306
307
        $jsonResponse = new JsonSuccessResponse();
308
        return $jsonResponse->toJson();
309
    }
310
311
    /**
312
     * UTILS FUNCTIONS
313
     */
314
    /** STEP 1 CC - Check concurrency */
315
316
    /**
317
     * Check if cart processing table exists
318
     */
319
    private function checkDbTable()
320
    {
321
322
        global $wpdb;
323
        if (isPgTableCreated(PG_CART_PROCESS_TABLE)) {
324
            alterCartProcessingTable();
325
        }
326
327
        $tableName = $wpdb->prefix.PG_CART_PROCESS_TABLE;
328
329
        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
330
            createOrderProcessingTable();
331
        }
332
    }
333
334
    /**
335
     * Check if logs table exists
336
     */
337
    private function checkDbLogTable()
338
    {
339
        global $wpdb;
340
        $tableName = $wpdb->prefix.PG_LOGS_TABLE_NAME;
341
342
        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
343
            $charset_collate = $wpdb->get_charset_collate();
344
            $sql = "CREATE TABLE $tableName ( id int NOT NULL AUTO_INCREMENT, log text NOT NULL, 
345
                    createdAt timestamp DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY id (id)) $charset_collate";
346
347
            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
348
            dbDelta($sql);
0 ignored issues
show
Bug introduced by
The function dbDelta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

348
            /** @scrutinizer ignore-call */ 
349
            dbDelta($sql);
Loading history...
349
        }
350
        return;
351
    }
352
353
    /** STEP 2 GMO - Get Merchant Order */
354
    /** STEP 3 GPOI - Get Pagantis OrderId */
355
    /** STEP 4 GPO - Get Pagantis Order */
356
    /** STEP 5 COS - Check Order Status */
357
358
    /**
359
     * @param $statusArray
360
     *
361
     * @throws \Exception
362
     */
363
    private function checkPagantisStatus($statusArray)
364
    {
365
        $pagantisStatus = array();
366
        foreach ($statusArray as $status) {
367
            $pagantisStatus[] = constant("\Pagantis\OrdersApiClient\Model\Order::STATUS_$status");
368
        }
369
370
        if ($this->pagantisOrder instanceof Order) {
371
            $payed = in_array($this->pagantisOrder->getStatus(), $pagantisStatus);
372
            if (!$payed) {
373
                if ($this->pagantisOrder instanceof Order) {
0 ignored issues
show
introduced by
$this->pagantisOrder is always a sub-type of Pagantis\OrdersApiClient\Model\Order.
Loading history...
374
                    $status = $this->pagantisOrder->getStatus();
375
                } else {
376
                    $status = '-';
377
                }
378
                throw new WrongStatusException($status);
379
            }
380
        } else {
381
            throw new OrderNotFoundException();
382
        }
383
    }
384
385
    /** STEP 6 CMOS - Check Merchant Order Status */
386
    /** STEP 7 VA - Validate Amount */
387
    /** STEP 8 PMO - Process Merchant Order */
388
    /**
389
     * @throws \Exception
390
     */
391
    private function saveOrder()
392
    {
393
        global $woocommerce;
394
        $paymentResult = $this->woocommerceOrder->payment_complete();
395
        if ($paymentResult) {
396
            $metadataOrder = $this->pagantisOrder->getMetadata();
397
            $metadataInfo = null;
398
            foreach ($metadataOrder as $metadataKey => $metadataValue) {
399
                if ($metadataKey == 'promotedProduct') {
400
                    $metadataInfo.= "/Producto promocionado = $metadataValue";
401
                }
402
            }
403
404
            if ($metadataInfo != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $metadataInfo of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
405
                $this->woocommerceOrder->add_order_note($metadataInfo);
406
            }
407
408
            $this->woocommerceOrder->add_order_note("Notification received via $this->origin");
409
            $this->woocommerceOrder->reduce_order_stock();
410
            $this->woocommerceOrder->save();
411
412
            $woocommerce->cart->empty_cart();
413
            sleep(3);
414
        } else {
415
            throw new UnknownException('Order can not be saved');
416
        }
417
    }
418
419
    /**
420
     * Save the merchant order_id with the related identification
421
     */
422
    private function updateBdInfo()
423
    {
424
        global $wpdb;
425
426
        $this->checkDbTable();
427
        $tableName = $wpdb->prefix.PG_CART_PROCESS_TABLE;
428
429
        $wpdb->update($tableName,
430
            array('order_id' => $this->pagantisOrderId,
431
                        'wc_order_id' => $this->woocommerceOrderId),
432
            array('token' => $this->getUrlToken()),
433
            array('%s', '%s'),
434
            array('%s'));
435
    }
436
437
    /** STEP 9 CPO - Confirmation Pagantis Order */
438
    private function rollbackMerchantOrder()
439
    {
440
        $this->woocommerceOrder->update_status('pending', __('Pending payment', 'woocommerce'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

440
        $this->woocommerceOrder->update_status('pending', /** @scrutinizer ignore-call */ __('Pending payment', 'woocommerce'));
Loading history...
441
    }
442
443
    /**
444
     * @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...
445
     * @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...
446
     */
447
    private function insertLog($exception = null, $message = null)
448
    {
449
        global $wpdb;
450
451
        $this->checkDbLogTable();
452
        $logEntry     = new LogEntry();
453
        if ($exception instanceof \Exception) {
454
            $logEntry = $logEntry->error($exception);
455
        } else {
456
            $logEntry = $logEntry->info($message);
457
        }
458
459
        $tableName = $wpdb->prefix.PG_LOGS_TABLE_NAME;
460
        $wpdb->insert($tableName, array('log' => $logEntry->toJson()));
461
    }
462
463
    /**
464
     * @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...
465
     *
466
     * @throws ConcurrencyException
467
     */
468
    private function unblockConcurrency($orderId = null)
469
    {
470
        global $wpdb;
471
        $tableName = $wpdb->prefix.PG_CONCURRENCY_TABLE_NAME;
472
        if ($orderId == null) {
0 ignored issues
show
introduced by
The condition $orderId == null is always true.
Loading history...
473
            $query = "DELETE FROM $tableName WHERE createdAt<(NOW()- INTERVAL ".self::CONCURRENCY_TIMEOUT." SECOND)";
474
        } else {
475
            $query = "DELETE FROM $tableName WHERE order_id = $orderId";
476
        }
477
        $resultDelete = $wpdb->query($query);
478
        if ($resultDelete === false) {
479
            throw new ConcurrencyException();
480
        }
481
    }
482
483
    /**
484
     * @param $orderId
485
     *
486
     * @throws ConcurrencyException
487
     */
488
    private function blockConcurrency($orderId)
489
    {
490
        global $wpdb;
491
        $tableName = $wpdb->prefix.PG_CONCURRENCY_TABLE_NAME;
492
        $insertResult = $wpdb->insert($tableName, array('order_id' => $orderId));
493
        if ($insertResult === false) {
494
            if ($this->getOrigin() == 'Notify') {
495
                throw new ConcurrencyException();
496
            } else {
497
                $query           =
498
                    sprintf(
499
                        "SELECT TIMESTAMPDIFF(SECOND,NOW()-INTERVAL %s SECOND, createdAt) as rest FROM %s WHERE %s",
500
                        self::CONCURRENCY_TIMEOUT,
501
                        $tableName,
502
                        "order_id=$orderId"
503
                    );
504
                $resultSeconds=$wpdb->get_row($query);
505
                $restSeconds  =isset($resultSeconds) ? ($resultSeconds->rest) : 0;
506
                $secondsToExpire = ($restSeconds > self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds;
507
                sleep($secondsToExpire + 1);
508
509
                $logMessage =
510
                    sprintf(
511
                        "User waiting %s seconds, default seconds %s, bd time to expire %s seconds",
512
                        $secondsToExpire,
513
                        self::CONCURRENCY_TIMEOUT,
514
                        $restSeconds
515
                    );
516
                $this->insertLog(null, $logMessage);
517
            }
518
        }
519
    }
520
521
    /**
522
     * @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...
523
     *
524
     *
525
     * @return JsonExceptionResponse|JsonSuccessResponse
526
     * @throws ConcurrencyException
527
     */
528
    private function buildResponse($exception = null)
529
    {
530
        $this->unblockConcurrency($this->woocommerceOrderId);
531
532
        if ($exception == null) {
0 ignored issues
show
introduced by
The condition $exception == null is always true.
Loading history...
533
            $jsonResponse = new JsonSuccessResponse();
534
        } else {
535
            $jsonResponse = new JsonExceptionResponse();
536
            $jsonResponse->setException($exception);
537
        }
538
        $jsonResponse->setMerchantOrderId($this->woocommerceOrderId);
539
        $jsonResponse->setPagantisOrderId($this->pagantisOrderId);
540
541
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
542
            $jsonResponse->printResponse();
543
        } else {
544
            return $jsonResponse;
545
        }
546
    }
547
548
    /**
549
     * GETTERS & SETTERS
550
     */
551
552
    /**
553
     * @return mixed
554
     */
555
    public function getOrigin()
556
    {
557
        return $this->origin;
558
    }
559
560
    /**
561
     * @param mixed $origin
562
     */
563
    public function setOrigin($origin)
564
    {
565
        $this->origin = $origin;
566
    }
567
568
    /**
569
     * @return bool
570
     */
571
    private function isProduct4x()
572
    {
573
        return ($this->product === Ucfirst(WcPagantis4xGateway::METHOD_ID));
574
    }
575
576
    /**
577
     * @return mixed
578
     */
579
    public function getProduct()
580
    {
581
        return $this->product;
582
    }
583
584
    /**
585
     * @param mixed $product
586
     */
587
    public function setProduct($product)
588
    {
589
        $this->product = Ucfirst($product);
590
    }
591
592
    /**
593
     * @return mixed
594
     */
595
    public function getWoocommerceOrderId()
596
    {
597
        return $this->woocommerceOrderId;
598
    }
599
600
    /**
601
     * @throws QuoteNotFoundException
602
     */
603
    public function setWoocommerceOrderId()
604
    {
605
        $this->woocommerceOrderId = $_GET['order-received'];
606
        if ($this->woocommerceOrderId == '') {
607
            throw new QuoteNotFoundException();
608
        }
609
    }
610
611
    /**
612
     * @return mixed
613
     */
614
    private function getUrlToken()
615
    {
616
        return $this->urlToken;
617
    }
618
619
    /**
620
     * @throws MerchantOrderNotFoundException
621
     */
622
    private function setUrlToken()
623
    {
624
        $this->urlToken = $_GET['token'];
625
626
        if (is_null($this->urlToken)) {
627
            throw new MerchantOrderNotFoundException();
628
        }
629
    }
630
}
631