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

WcPagantisNotify::verifyOrderConformity()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 2
nop 0
dl 0
loc 22
rs 9.7998
c 0
b 0
f 0
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
        $tokenCount=$wpdb->get_var($wpdb->prepare(
158
            "SELECT COUNT(order_id) 
159
                 FROM $tableName 
160
                 WHERE token=%s",
161
            $this->getUrlToken()
162
        ));
163
        $orderIDCount = $wpdb->get_var(
164
            $wpdb->prepare(
165
                "SELECT COUNT(token) 
166
                      FROM $tableName 
167
                      WHERE order_id=%s",
168
                $this->pagantisOrderId
169
            )
170
        );
171
172
        if (!($tokenCount == 1 && $orderIDCount == 1)) {
173
            throw new MerchantOrderNotFoundException();
174
        }
175
    }
176
177
    private function getPagantisOrderId()
178
    {
179
        global $wpdb;
180
        $this->setUrlToken();
181
        $this->checkDbTable();
182
        $tableName = $wpdb->prefix.PG_CART_PROCESS_TABLE;
183
        $order_id = $wpdb->get_var("SELECT order_id FROM $tableName WHERE token='{$this->getUrlToken()}'");
184
        $this->pagantisOrderId = $order_id;
185
        if (empty($this->pagantisOrderId)) {
186
            throw new NoIdentificationException();
187
        }
188
189
        $this->verifyOrderConformity();
190
    }
191
192
193
194
    /**
195
     * @throws OrderNotFoundException
196
     */
197
    private function getPagantisOrder()
198
    {
199
        try {
200
            $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

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

246
        $isValidStatus = /** @scrutinizer ignore-call */ apply_filters(
Loading history...
247
            'woocommerce_valid_order_statuses_for_payment_complete',
248
            $validStatus,
249
            $this
250
        );
251
252
        if (!$this->woocommerceOrder->has_status($isValidStatus)) { // TO CONFIRM
253
            $logMessage = "WARNING checkMerchantOrderStatus." .
254
                          " Merchant order id:".$this->woocommerceOrder->get_id().
255
                          " Merchant order status:".$this->woocommerceOrder->get_status().
256
                          " Pagantis order id:".$this->pagantisOrder->getStatus().
257
                          " Pagantis order status:".$this->pagantisOrder->getId();
258
            $this->insertLog(null, $logMessage);
259
            $this->woocommerceOrder->add_order_note($logMessage);
260
            $this->woocommerceOrder->save();
261
            return false;
262
        }
263
264
        return true; //TO SAVE
265
    }
266
267
    /**
268
     * @throws AmountMismatchException
269
     */
270
    private function validateAmount()
271
    {
272
        $pagantisAmount = $this->pagantisOrder->getShoppingCart()->getTotalAmount();
273
        $wcAmount = intval(strval(100 * $this->woocommerceOrder->get_total()));
274
        if ($pagantisAmount != $wcAmount) {
275
            throw new AmountMismatchException($pagantisAmount, $wcAmount);
276
        }
277
    }
278
279
    /**
280
     * @throws Exception
281
     */
282
    private function processMerchantOrder()
283
    {
284
        $this->saveOrder();
285
        $this->updateBdInfo();
286
    }
287
288
    /**
289
     * @return false|string
290
     * @throws UnknownException
291
     */
292
    private function confirmPagantisOrder()
293
    {
294
        try {
295
            $this->pagantisOrder = $this->orderClient->confirmOrder($this->pagantisOrderId);
296
        } catch (\Exception $e) {
297
            $this->pagantisOrder = $this->orderClient->getOrder($this->pagantisOrderId);
298
            if ($this->pagantisOrder->getStatus() !== Order::STATUS_CONFIRMED) {
299
                throw new UnknownException($e->getMessage());
300
            } else {
301
                $logMessage = 'Concurrency issue: Order_id '.$this->pagantisOrderId.' was confirmed by other process';
302
                $this->insertLog(null, $logMessage);
303
            }
304
        }
305
306
        $jsonResponse = new JsonSuccessResponse();
307
        return $jsonResponse->toJson();
308
    }
309
310
    /**
311
     * UTILS FUNCTIONS
312
     */
313
    /** STEP 1 CC - Check concurrency */
314
315
    /**
316
     * Check if cart processing table exists
317
     */
318
    private function checkDbTable()
319
    {
320
321
        global $wpdb;
322
        if (isPgTableCreated(PG_CART_PROCESS_TABLE)) {
323
            alterCartProcessingTable();
324
        }
325
326
        $tableName = $wpdb->prefix.PG_CART_PROCESS_TABLE;
327
328
        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
329
            $charset_collate = $wpdb->get_charset_collate();
330
            $sql = "CREATE TABLE IF NOT EXISTS $tableName  
331
            (id VARCHAR(60) NOT NULL,
332
            order_id VARCHAR(60) NOT NULL,
333
            wc_order_id VARCHAR(50) NOT NULL,
334
            token VARCHAR(32) NOT NULL,
335
            PRIMARY KEY(id,order_id))$charset_collate";
336
337
            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...
338
            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

338
            /** @scrutinizer ignore-call */ 
339
            dbDelta($sql);
Loading history...
339
        }
340
    }
341
342
    /**
343
     * Check if logs table exists
344
     */
345
    private function checkDbLogTable()
346
    {
347
        global $wpdb;
348
        $tableName = $wpdb->prefix.PG_LOGS_TABLE_NAME;
349
350
        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
351
            $charset_collate = $wpdb->get_charset_collate();
352
            $sql = "CREATE TABLE $tableName ( id int NOT NULL AUTO_INCREMENT, log text NOT NULL, 
353
                    createdAt timestamp DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY id (id)) $charset_collate";
354
355
            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...
356
            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

356
            /** @scrutinizer ignore-call */ 
357
            dbDelta($sql);
Loading history...
357
        }
358
        return;
359
    }
360
361
    /** STEP 2 GMO - Get Merchant Order */
362
    /** STEP 3 GPOI - Get Pagantis OrderId */
363
    /** STEP 4 GPO - Get Pagantis Order */
364
    /** STEP 5 COS - Check Order Status */
365
366
    /**
367
     * @param $statusArray
368
     *
369
     * @throws \Exception
370
     */
371
    private function checkPagantisStatus($statusArray)
372
    {
373
        $pagantisStatus = array();
374
        foreach ($statusArray as $status) {
375
            $pagantisStatus[] = constant("\Pagantis\OrdersApiClient\Model\Order::STATUS_$status");
376
        }
377
378
        if ($this->pagantisOrder instanceof Order) {
379
            $payed = in_array($this->pagantisOrder->getStatus(), $pagantisStatus);
380
            if (!$payed) {
381
                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...
382
                    $status = $this->pagantisOrder->getStatus();
383
                } else {
384
                    $status = '-';
385
                }
386
                throw new WrongStatusException($status);
387
            }
388
        } else {
389
            throw new OrderNotFoundException();
390
        }
391
    }
392
393
    /** STEP 6 CMOS - Check Merchant Order Status */
394
    /** STEP 7 VA - Validate Amount */
395
    /** STEP 8 PMO - Process Merchant Order */
396
    /**
397
     * @throws \Exception
398
     */
399
    private function saveOrder()
400
    {
401
        global $woocommerce;
402
        $paymentResult = $this->woocommerceOrder->payment_complete();
403
        if ($paymentResult) {
404
            $metadataOrder = $this->pagantisOrder->getMetadata();
405
            $metadataInfo = null;
406
            foreach ($metadataOrder as $metadataKey => $metadataValue) {
407
                if ($metadataKey == 'promotedProduct') {
408
                    $metadataInfo.= "/Producto promocionado = $metadataValue";
409
                }
410
            }
411
412
            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...
413
                $this->woocommerceOrder->add_order_note($metadataInfo);
414
            }
415
416
            $this->woocommerceOrder->add_order_note("Notification received via $this->origin");
417
            $this->woocommerceOrder->reduce_order_stock();
418
            $this->woocommerceOrder->save();
419
420
            $woocommerce->cart->empty_cart();
421
            sleep(3);
422
        } else {
423
            throw new UnknownException('Order can not be saved');
424
        }
425
    }
426
427
    /**
428
     * Save the merchant order_id with the related identification
429
     */
430
    private function updateBdInfo()
431
    {
432
        global $wpdb;
433
434
        $this->checkDbTable();
435
        $tableName = $wpdb->prefix.PG_CART_PROCESS_TABLE;
436
437
        $wpdb->update(
438
            $tableName,
439
            array('wc_order_id' => $this->woocommerceOrderId,array('order_id' => $this->pagantisOrderId)),
440
            array('token' => $this->getUrlToken()),
441
            array('%s','%s'),
442
            array('%s')
443
        );
444
    }
445
446
    /** STEP 9 CPO - Confirmation Pagantis Order */
447
    private function rollbackMerchantOrder()
448
    {
449
        $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

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