Passed
Pull Request — master (#76)
by Raúl
03:03
created
controllers/front/notify.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
     private function getPagantisOrderId()
225 225
     {
226 226
         try {
227
-            $this->pagantisOrderId= Db::getInstance()->getValue(
228
-                'select order_id from '._DB_PREFIX_.'pagantis_order where id = '.(int)$this->merchantOrderId
227
+            $this->pagantisOrderId = Db::getInstance()->getValue(
228
+                'select order_id from '._DB_PREFIX_.'pagantis_order where id = '.(int) $this->merchantOrderId
229 229
             );
230 230
 
231 231
             if (is_null($this->pagantisOrderId)) {
@@ -286,20 +286,20 @@  discard block
 block discarded – undo
286 286
         $merchantAmount = explode('.', explode(',', $merchantAmount)[0])[0];
287 287
         if ($totalAmount != $merchantAmount) {
288 288
             try {
289
-                $psTotalAmount = substr_replace($merchantAmount, '.', (Tools::strlen($merchantAmount) -2), 0);
289
+                $psTotalAmount = substr_replace($merchantAmount, '.', (Tools::strlen($merchantAmount) - 2), 0);
290 290
 
291 291
                 $pgTotalAmountInCents = (string) $this->pagantisOrder->getShoppingCart()->getTotalAmount();
292 292
                 $pgTotalAmount = substr_replace(
293 293
                     $pgTotalAmountInCents,
294 294
                     '.',
295
-                    (Tools::strlen($pgTotalAmountInCents) -2),
295
+                    (Tools::strlen($pgTotalAmountInCents) - 2),
296 296
                     0
297 297
                 );
298 298
 
299
-                $this->amountMismatchError = '. Amount mismatch in PrestaShop Order #'. $this->merchantOrderId .
300
-                    ' compared with Pagantis Order: ' . $this->pagantisOrderId .
301
-                    '. The order in PrestaShop has an amount of ' . $psTotalAmount . ' and in Pagantis ' .
302
-                    $pgTotalAmount . ' PLEASE REVIEW THE ORDER';
299
+                $this->amountMismatchError = '. Amount mismatch in PrestaShop Order #'.$this->merchantOrderId.
300
+                    ' compared with Pagantis Order: '.$this->pagantisOrderId.
301
+                    '. The order in PrestaShop has an amount of '.$psTotalAmount.' and in Pagantis '.
302
+                    $pgTotalAmount.' PLEASE REVIEW THE ORDER';
303 303
                 $this->saveLog(array(
304 304
                     'message' => $this->amountMismatchError
305 305
                 ));
@@ -319,21 +319,21 @@  discard block
 block discarded – undo
319 319
         try {
320 320
             if ($this->merchantOrder->orderExists() !== false) {
321 321
                 throw new WrongStatusException('PS->orderExists() cart_id = '
322
-                    . $this->merchantOrderId . ' pagantis_id = '
323
-                    . $this->pagantisOrderId . '): already_processed');
322
+                    . $this->merchantOrderId.' pagantis_id = '
323
+                    . $this->pagantisOrderId.'): already_processed');
324 324
             }
325 325
 
326 326
             // Double check
327
-            $tableName = _DB_PREFIX_ . 'pagantis_order';
327
+            $tableName = _DB_PREFIX_.'pagantis_order';
328 328
             $fieldName = 'ps_order_id';
329
-            $sql = ('select ' . $fieldName . ' from `' . $tableName . '` where `id` = ' . (int)$this->merchantOrderId
330
-                . ' and `order_id` = \'' . $this->pagantisOrderId . '\''
331
-                . ' and `' . $fieldName . '` is not null');
329
+            $sql = ('select '.$fieldName.' from `'.$tableName.'` where `id` = '.(int) $this->merchantOrderId
330
+                . ' and `order_id` = \''.$this->pagantisOrderId.'\''
331
+                . ' and `'.$fieldName.'` is not null');
332 332
             $results = Db::getInstance()->ExecuteS($sql);
333 333
             if (is_array($results) && count($results) === 1) {
334
-                throw new WrongStatusException('PS->record found in ' . $tableName
335
-                    . ' (cart_id = ' . $this->merchantOrderId . ' pagantis_id = '
336
-                    . $this->pagantisOrderId . '): already_processed');
334
+                throw new WrongStatusException('PS->record found in '.$tableName
335
+                    . ' (cart_id = '.$this->merchantOrderId.' pagantis_id = '
336
+                    . $this->pagantisOrderId.'): already_processed');
337 337
             }
338 338
         } catch (\Exception $exception) {
339 339
             throw new UnknownException($exception->getMessage());
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
                 Configuration::get('PS_OS_PAYMENT'),
363 363
                 $this->merchantOrder->getOrderTotal(true),
364 364
                 $this->module->displayName,
365
-                'pagantisOrderId: ' . $this->pagantisOrder->getId() . ' ' .
366
-                'pagantisOrderStatus: '. $this->pagantisOrder->getStatus() .
367
-                $this->amountMismatchError .
365
+                'pagantisOrderId: '.$this->pagantisOrder->getId().' '.
366
+                'pagantisOrderStatus: '.$this->pagantisOrder->getStatus().
367
+                $this->amountMismatchError.
368 368
                 $metadataInfo,
369 369
                 array('transaction_id' => $this->pagantisOrderId),
370 370
                 null,
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
             Db::getInstance()->update(
379 379
                 'pagantis_order',
380 380
                 array('ps_order_id' => $this->module->currentOrder),
381
-                'id = '. (int)$this->merchantOrderId . ' and order_id = \'' . $this->pagantisOrderId . '\''
381
+                'id = '.(int) $this->merchantOrderId.' and order_id = \''.$this->pagantisOrderId.'\''
382 382
             );
383 383
         } catch (\Exception $exception) {
384 384
             // Do nothing
@@ -396,9 +396,9 @@  discard block
 block discarded – undo
396 396
             $this->orderClient->confirmOrder($this->pagantisOrderId);
397 397
             try {
398 398
                 $mode = ($_SERVER['REQUEST_METHOD'] == 'POST') ? 'NOTIFICATION' : 'REDIRECTION';
399
-                $message = 'Order CONFIRMED. The order was confirmed by a ' . $mode .
400
-                    '. Pagantis OrderId=' . $this->pagantisOrderId .
401
-                    '. Prestashop OrderId=' . $this->module->currentOrder;
399
+                $message = 'Order CONFIRMED. The order was confirmed by a '.$mode.
400
+                    '. Pagantis OrderId='.$this->pagantisOrderId.
401
+                    '. Prestashop OrderId='.$this->module->currentOrder;
402 402
                 $this->saveLog(array('message' => $message));
403 403
             } catch (\Exception $exception) {
404 404
                 // Do nothing
@@ -416,15 +416,15 @@  discard block
 block discarded – undo
416 416
     public function rollbackMerchantOrder()
417 417
     {
418 418
         try {
419
-            $message = 'Roolback method: ' .
420
-                '. Pagantis OrderId=' . $this->pagantisOrderId .
421
-                '. Prestashop CartId=' . $this->merchantOrderId;
419
+            $message = 'Roolback method: '.
420
+                '. Pagantis OrderId='.$this->pagantisOrderId.
421
+                '. Prestashop CartId='.$this->merchantOrderId;
422 422
             if ($this->module->currentOrder) {
423 423
                 $objOrder = new Order($this->module->currentOrder);
424 424
                 $history = new OrderHistory();
425
-                $history->id_order = (int)$objOrder->id;
426
-                $history->changeIdOrderState(8, (int)($objOrder->id));
427
-                $message .= ' Prestashop OrderId=' . $this->merchantOrderId;
425
+                $history->id_order = (int) $objOrder->id;
426
+                $history->changeIdOrderState(8, (int) ($objOrder->id));
427
+                $message .= ' Prestashop OrderId='.$this->merchantOrderId;
428 428
             }
429 429
             $this->saveLog(array('message' => $message));
430 430
         } catch (\Exception $exception) {
@@ -440,17 +440,17 @@  discard block
 block discarded – undo
440 440
     {
441 441
         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
442 442
             $this->getPagantisOrderId();
443
-            $tableName = _DB_PREFIX_ . 'pagantis_order';
443
+            $tableName = _DB_PREFIX_.'pagantis_order';
444 444
             $tries = Db::getInstance()->getValue(
445
-                'SELECT tries FROM ' . $tableName . ' WHERE id = ' .
446
-                (int)$this->merchantOrderId . ' and order_id = \'' . $this->pagantisOrderId . '\''
445
+                'SELECT tries FROM '.$tableName.' WHERE id = '.
446
+                (int) $this->merchantOrderId.' and order_id = \''.$this->pagantisOrderId.'\''
447 447
             );
448 448
             if ($tries < self::MAX_TRIES) {
449 449
                 try {
450 450
                     Db::getInstance()->update(
451 451
                         'pagantis_order',
452 452
                         array('tries' => $tries + 1),
453
-                        'id = ' . (int)$this->merchantOrderId . ' and order_id = \'' . $this->pagantisOrderId . '\''
453
+                        'id = '.(int) $this->merchantOrderId.' and order_id = \''.$this->pagantisOrderId.'\''
454 454
                     );
455 455
                 } catch (\Exception $exception) {
456 456
                     // Do nothing
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
     {
474 474
         try {
475 475
             $table = 'pagantis_cart_process';
476
-            if (Db::getInstance()->insert($table, array('id' => (int)$orderId, 'timestamp' => (time()))) === false) {
476
+            if (Db::getInstance()->insert($table, array('id' => (int) $orderId, 'timestamp' => (time()))) === false) {
477 477
                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
478 478
                     throw new ConcurrencyException();
479 479
                 }
@@ -483,14 +483,14 @@  discard block
 block discarded – undo
483 483
                             FROM %s WHERE %s",
484 484
                     self::CONCURRENCY_TIMEOUT,
485 485
                     _DB_PREFIX_.$table,
486
-                    'id='.(int)$orderId
486
+                    'id='.(int) $orderId
487 487
                 );
488 488
                 $resultSeconds = Db::getInstance()->getValue($query);
489 489
                 $restSeconds = isset($resultSeconds) ? ($resultSeconds) : 0;
490
-                $secondsToExpire = ($restSeconds>self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds;
490
+                $secondsToExpire = ($restSeconds > self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds;
491 491
 
492 492
                 $logMessage = sprintf(
493
-                    "Redirect concurrency, User have to wait %s seconds, default seconds %s. CartId=" . $orderId,
493
+                    "Redirect concurrency, User have to wait %s seconds, default seconds %s. CartId=".$orderId,
494 494
                     $secondsToExpire,
495 495
                     self::CONCURRENCY_TIMEOUT,
496 496
                     $restSeconds
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
                 $this->saveLog(array(
500 500
                     'message' => $logMessage
501 501
                 ));
502
-                sleep($secondsToExpire+1);
502
+                sleep($secondsToExpire + 1);
503 503
                 // After waiting...user continue the confirmation, hoping that previous call have finished.
504 504
                 return true;
505 505
             }
@@ -519,11 +519,11 @@  discard block
 block discarded – undo
519 519
             if (is_null($orderId)) {
520 520
                 Db::getInstance()->delete(
521 521
                     'pagantis_cart_process',
522
-                    'timestamp < ' . (time() - self::CONCURRENCY_TIMEOUT)
522
+                    'timestamp < '.(time() - self::CONCURRENCY_TIMEOUT)
523 523
                 );
524 524
                 return;
525 525
             }
526
-            Db::getInstance()->delete('pagantis_cart_process', 'id = ' . (int)$orderId);
526
+            Db::getInstance()->delete('pagantis_cart_process', 'id = '.(int) $orderId);
527 527
         } catch (\Exception $exception) {
528 528
             throw new ConcurrencyException();
529 529
         }
@@ -545,8 +545,8 @@  discard block
 block discarded – undo
545 545
         $data = array(
546 546
             'merchantOrderId' => $this->merchantOrderId,
547 547
             'pagantisOrderId' => $this->pagantisOrderId,
548
-            'message' => ($exception)? $exception->getMessage() : 'Unable to get Exception message',
549
-            'statusCode' => ($exception)? $exception->getCode() : 'Unable to get Exception statusCode',
548
+            'message' => ($exception) ? $exception->getMessage() : 'Unable to get Exception message',
549
+            'statusCode' => ($exception) ? $exception->getCode() : 'Unable to get Exception statusCode',
550 550
             'method' => $method,
551 551
             'file' => __FILE__,
552 552
             'line' => $line,
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
             'id_cart' => $this->merchantOrderId,
577 577
             'key' => $this->config['secureKey'],
578 578
             'id_module' => $this->module->id,
579
-            'id_order' => ($this->pagantisOrder)?$this->pagantisOrder->getId(): null,
579
+            'id_order' => ($this->pagantisOrder) ? $this->pagantisOrder->getId() : null,
580 580
         );
581
-        $url = ($error)? $this->config['urlKO'] : $this->config['urlOK'];
581
+        $url = ($error) ? $this->config['urlKO'] : $this->config['urlOK'];
582 582
         return $this->redirect($url, $parameters);
583 583
     }
584 584
 }
Please login to merge, or discard this patch.