Passed
Pull Request — master (#60)
by Raúl
03:27
created
controllers/front/notify.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     private function getPagantisOrderId()
208 208
     {
209 209
         try {
210
-            $this->pagantisOrderId= Db::getInstance()->getValue(
210
+            $this->pagantisOrderId = Db::getInstance()->getValue(
211 211
                 'select order_id from '._DB_PREFIX_.'pagantis_order where id = '.$this->merchantOrderId
212 212
             );
213 213
 
@@ -269,20 +269,20 @@  discard block
 block discarded – undo
269 269
         $merchantAmount = explode('.', explode(',', $merchantAmount)[0])[0];
270 270
         if ($totalAmount != $merchantAmount) {
271 271
             try {
272
-                $psTotalAmount = substr_replace($merchantAmount, '.', (Tools::strlen($merchantAmount) -2), 0);
272
+                $psTotalAmount = substr_replace($merchantAmount, '.', (Tools::strlen($merchantAmount) - 2), 0);
273 273
 
274 274
                 $pgTotalAmountInCents = (string) $this->pagantisOrder->getShoppingCart()->getTotalAmount();
275 275
                 $pgTotalAmount = substr_replace(
276 276
                     $pgTotalAmountInCents,
277 277
                     '.',
278
-                    (Tools::strlen($pgTotalAmountInCents) -2),
278
+                    (Tools::strlen($pgTotalAmountInCents) - 2),
279 279
                     0
280 280
                 );
281 281
 
282
-                $this->amountMismatchError = '. Amount mismatch in PrestaShop Order #'. $this->merchantOrderId .
283
-                    ' compared with Pagantis Order: ' . $this->pagantisOrderId .
284
-                    '. The order in PrestaShop has an amount of ' . $psTotalAmount . ' and in Pagantis ' .
285
-                    $pgTotalAmount . ' PLEASE REVIEW THE ORDER';
282
+                $this->amountMismatchError = '. Amount mismatch in PrestaShop Order #'.$this->merchantOrderId.
283
+                    ' compared with Pagantis Order: '.$this->pagantisOrderId.
284
+                    '. The order in PrestaShop has an amount of '.$psTotalAmount.' and in Pagantis '.
285
+                    $pgTotalAmount.' PLEASE REVIEW THE ORDER';
286 286
                 $this->saveLog(array(
287 287
                     'message' => $this->amountMismatchError
288 288
                 ));
@@ -302,20 +302,20 @@  discard block
 block discarded – undo
302 302
         try {
303 303
             if ($this->merchantOrder->orderExists() !== false) {
304 304
                 throw new WrongStatusException('PS->orderExists() cart_id = '
305
-                    . $this->merchantOrderId . ' pagantis_id = '
306
-                    . $this->pagantisOrderId . '): already_processed');
305
+                    . $this->merchantOrderId.' pagantis_id = '
306
+                    . $this->pagantisOrderId.'): already_processed');
307 307
             }
308 308
 
309 309
             // Double check
310
-            $tableName = _DB_PREFIX_ . 'pagantis_order';
311
-            $sql = ('select ps_order_id from `' . $tableName . '` where `id` = ' . $this->merchantOrderId
312
-                . ' and `order_id` = \'' . $this->pagantisOrderId . '\''
310
+            $tableName = _DB_PREFIX_.'pagantis_order';
311
+            $sql = ('select ps_order_id from `'.$tableName.'` where `id` = '.$this->merchantOrderId
312
+                . ' and `order_id` = \''.$this->pagantisOrderId.'\''
313 313
                 . ' and `ps_order_id` is not null');
314 314
             $results = Db::getInstance()->ExecuteS($sql);
315 315
             if (is_array($results) && count($results) === 1) {
316
-                throw new WrongStatusException('PS->record found in ' . $tableName
317
-                    . ' (cart_id = ' . $this->merchantOrderId . ' pagantis_id = '
318
-                    . $this->pagantisOrderId . '): already_processed');
316
+                throw new WrongStatusException('PS->record found in '.$tableName
317
+                    . ' (cart_id = '.$this->merchantOrderId.' pagantis_id = '
318
+                    . $this->pagantisOrderId.'): already_processed');
319 319
             }
320 320
         } catch (\Exception $exception) {
321 321
             throw new UnknownException($exception->getMessage());
@@ -344,9 +344,9 @@  discard block
 block discarded – undo
344 344
                 Configuration::get('PS_OS_PAYMENT'),
345 345
                 $this->merchantOrder->getOrderTotal(true),
346 346
                 $this->module->displayName,
347
-                'pagantisOrderId: ' . $this->pagantisOrder->getId() . ' ' .
348
-                'pagantisOrderStatus: '. $this->pagantisOrder->getStatus() .
349
-                $this->amountMismatchError .
347
+                'pagantisOrderId: '.$this->pagantisOrder->getId().' '.
348
+                'pagantisOrderStatus: '.$this->pagantisOrder->getStatus().
349
+                $this->amountMismatchError.
350 350
                 $metadataInfo,
351 351
                 array('transaction_id' => $this->pagantisOrderId),
352 352
                 null,
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
             Db::getInstance()->update(
361 361
                 'pagantis_order',
362 362
                 array('ps_order_id' => $this->module->currentOrder),
363
-                'id = \''. $this->merchantOrderId . '\' and order_id = \'' . $this->pagantisOrderId . '\''
363
+                'id = \''.$this->merchantOrderId.'\' and order_id = \''.$this->pagantisOrderId.'\''
364 364
             );
365 365
         } catch (\Exception $exception) {
366 366
             // Do nothing
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
             $this->orderClient->confirmOrder($this->pagantisOrderId);
379 379
             try {
380 380
                 $mode = ($_SERVER['REQUEST_METHOD'] == 'POST') ? 'NOTIFICATION' : 'REDIRECTION';
381
-                $message = 'Order CONFIRMED. The order was confirmed by a ' . $mode .
382
-                    '. Pagantis OrderId=' . $this->pagantisOrderId .
383
-                    '. Prestashop OrderId=' . $this->module->currentOrder;
381
+                $message = 'Order CONFIRMED. The order was confirmed by a '.$mode.
382
+                    '. Pagantis OrderId='.$this->pagantisOrderId.
383
+                    '. Prestashop OrderId='.$this->module->currentOrder;
384 384
                 $this->saveLog(array(
385 385
                     'message' => $message
386 386
                 ));
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
             );
428 428
             $resultSeconds = Db::getInstance()->getValue($query);
429 429
             $restSeconds = isset($resultSeconds) ? ($resultSeconds) : 0;
430
-            $secondsToExpire = ($restSeconds>self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds;
430
+            $secondsToExpire = ($restSeconds > self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds;
431 431
 
432 432
             $logMessage = sprintf(
433 433
                 "Redirect concurrency, User have to wait %s seconds, default seconds %s, bd time to expire %s seconds",
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
             $this->saveLog(array(
440 440
                 'message' => $logMessage
441 441
             ));
442
-            sleep($secondsToExpire+1);
442
+            sleep($secondsToExpire + 1);
443 443
             // After waiting...user continue the confirmation, hoping that previous call have finished.
444 444
             return true;
445 445
         }
@@ -456,12 +456,12 @@  discard block
 block discarded – undo
456 456
             if (is_null($orderId)) {
457 457
                 Db::getInstance()->delete(
458 458
                     'pagantis_cart_process',
459
-                    'timestamp < ' . (time() - self::CONCURRENCY_TIMEOUT
459
+                    'timestamp < '.(time() - self::CONCURRENCY_TIMEOUT
460 460
                     )
461 461
                 );
462 462
                 return;
463 463
             }
464
-            Db::getInstance()->delete('pagantis_cart_process', 'id = \'' . $orderId . '\'');
464
+            Db::getInstance()->delete('pagantis_cart_process', 'id = \''.$orderId.'\'');
465 465
         } catch (\Exception $exception) {
466 466
             throw new ConcurrencyException();
467 467
         }
@@ -483,8 +483,8 @@  discard block
 block discarded – undo
483 483
         $data = array(
484 484
             'merchantOrderId' => $this->merchantOrderId,
485 485
             'pagantisOrderId' => $this->pagantisOrderId,
486
-            'message' => ($exception)? $exception->getMessage() : 'Unable to get Exception message',
487
-            'statusCode' => ($exception)? $exception->getCode() : 'Unable to get Exception statusCode',
486
+            'message' => ($exception) ? $exception->getMessage() : 'Unable to get Exception message',
487
+            'statusCode' => ($exception) ? $exception->getCode() : 'Unable to get Exception statusCode',
488 488
             'method' => $method,
489 489
             'file' => __FILE__,
490 490
             'line' => $line,
@@ -508,9 +508,9 @@  discard block
 block discarded – undo
508 508
             'id_cart' => $this->merchantOrderId,
509 509
             'key' => $this->config['secureKey'],
510 510
             'id_module' => $this->module->id,
511
-            'id_order' => ($this->pagantisOrder)?$this->pagantisOrder->getId(): null,
511
+            'id_order' => ($this->pagantisOrder) ? $this->pagantisOrder->getId() : null,
512 512
         );
513
-        $url = ($error)? $this->config['urlKO'] : $this->config['urlOK'];
513
+        $url = ($error) ? $this->config['urlKO'] : $this->config['urlOK'];
514 514
         return $this->redirect($url, $parameters);
515 515
     }
516 516
 }
517 517
\ No newline at end of file
Please login to merge, or discard this patch.