@@ -207,7 +207,7 @@ discard block  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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('message' => $message)); | 
                                                        
| 385 | 385 |              } catch (\Exception $exception) { | 
                                                        
| 386 | 386 | // Do nothing  | 
                                                        
@@ -399,9 +399,9 @@ discard block  | 
                                                    ||
| 399 | 399 |      { | 
                                                        
| 400 | 400 | // Do nothing because the order is created only when the purchase was successfully  | 
                                                        
| 401 | 401 |          try { | 
                                                        
| 402 | - $message = 'Roolback method: ' .  | 
                                                        |
| 403 | - '. Pagantis OrderId=' . $this->pagantisOrderId .  | 
                                                        |
| 404 | - '. Prestashop CartId=' . $this->merchantOrderId;  | 
                                                        |
| 402 | + $message = 'Roolback method: '.  | 
                                                        |
| 403 | + '. Pagantis OrderId='.$this->pagantisOrderId.  | 
                                                        |
| 404 | + '. Prestashop CartId='.$this->merchantOrderId;  | 
                                                        |
| 405 | 405 |              $this->saveLog(array('message' => $message)); | 
                                                        
| 406 | 406 |          } catch (\Exception $exception) { | 
                                                        
| 407 | 407 | // Do nothing  | 
                                                        
@@ -433,7 +433,7 @@ discard block  | 
                                                    ||
| 433 | 433 | );  | 
                                                        
| 434 | 434 | $resultSeconds = Db::getInstance()->getValue($query);  | 
                                                        
| 435 | 435 | $restSeconds = isset($resultSeconds) ? ($resultSeconds) : 0;  | 
                                                        
| 436 | - $secondsToExpire = ($restSeconds>self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds;  | 
                                                        |
| 436 | + $secondsToExpire = ($restSeconds > self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds;  | 
                                                        |
| 437 | 437 | |
| 438 | 438 | $logMessage = sprintf(  | 
                                                        
| 439 | 439 | "Redirect concurrency, User have to wait %s seconds, default seconds %s, bd time to expire %s seconds",  | 
                                                        
@@ -445,7 +445,7 @@ discard block  | 
                                                    ||
| 445 | 445 | $this->saveLog(array(  | 
                                                        
| 446 | 446 | 'message' => $logMessage  | 
                                                        
| 447 | 447 | ));  | 
                                                        
| 448 | - sleep($secondsToExpire+1);  | 
                                                        |
| 448 | + sleep($secondsToExpire + 1);  | 
                                                        |
| 449 | 449 | // After waiting...user continue the confirmation, hoping that previous call have finished.  | 
                                                        
| 450 | 450 | return true;  | 
                                                        
| 451 | 451 | }  | 
                                                        
@@ -462,12 +462,12 @@ discard block  | 
                                                    ||
| 462 | 462 |              if (is_null($orderId)) { | 
                                                        
| 463 | 463 | Db::getInstance()->delete(  | 
                                                        
| 464 | 464 | 'pagantis_cart_process',  | 
                                                        
| 465 | - 'timestamp < ' . (time() - self::CONCURRENCY_TIMEOUT  | 
                                                        |
| 465 | + 'timestamp < '.(time() - self::CONCURRENCY_TIMEOUT  | 
                                                        |
| 466 | 466 | )  | 
                                                        
| 467 | 467 | );  | 
                                                        
| 468 | 468 | return;  | 
                                                        
| 469 | 469 | }  | 
                                                        
| 470 | -            Db::getInstance()->delete('pagantis_cart_process', 'id = \'' . $orderId . '\''); | 
                                                        |
| 470 | +            Db::getInstance()->delete('pagantis_cart_process', 'id = \''.$orderId.'\''); | 
                                                        |
| 471 | 471 |          } catch (\Exception $exception) { | 
                                                        
| 472 | 472 | throw new ConcurrencyException();  | 
                                                        
| 473 | 473 | }  | 
                                                        
@@ -489,8 +489,8 @@ discard block  | 
                                                    ||
| 489 | 489 | $data = array(  | 
                                                        
| 490 | 490 | 'merchantOrderId' => $this->merchantOrderId,  | 
                                                        
| 491 | 491 | 'pagantisOrderId' => $this->pagantisOrderId,  | 
                                                        
| 492 | - 'message' => ($exception)? $exception->getMessage() : 'Unable to get Exception message',  | 
                                                        |
| 493 | - 'statusCode' => ($exception)? $exception->getCode() : 'Unable to get Exception statusCode',  | 
                                                        |
| 492 | + 'message' => ($exception) ? $exception->getMessage() : 'Unable to get Exception message',  | 
                                                        |
| 493 | + 'statusCode' => ($exception) ? $exception->getCode() : 'Unable to get Exception statusCode',  | 
                                                        |
| 494 | 494 | 'method' => $method,  | 
                                                        
| 495 | 495 | 'file' => __FILE__,  | 
                                                        
| 496 | 496 | 'line' => $line,  | 
                                                        
@@ -514,9 +514,9 @@ discard block  | 
                                                    ||
| 514 | 514 | 'id_cart' => $this->merchantOrderId,  | 
                                                        
| 515 | 515 | 'key' => $this->config['secureKey'],  | 
                                                        
| 516 | 516 | 'id_module' => $this->module->id,  | 
                                                        
| 517 | - 'id_order' => ($this->pagantisOrder)?$this->pagantisOrder->getId(): null,  | 
                                                        |
| 517 | + 'id_order' => ($this->pagantisOrder) ? $this->pagantisOrder->getId() : null,  | 
                                                        |
| 518 | 518 | );  | 
                                                        
| 519 | - $url = ($error)? $this->config['urlKO'] : $this->config['urlOK'];  | 
                                                        |
| 519 | + $url = ($error) ? $this->config['urlKO'] : $this->config['urlOK'];  | 
                                                        |
| 520 | 520 | return $this->redirect($url, $parameters);  | 
                                                        
| 521 | 521 | }  | 
                                                        
| 522 | 522 | }  | 
                                                        
| 523 | 523 | \ No newline at end of file  |