| @@ -216,8 +216,8 @@ discard block | ||
| 216 | 216 | private function getPagantisOrderId() | 
| 217 | 217 |      { | 
| 218 | 218 |          try { | 
| 219 | - $this->pagantisOrderId= Db::getInstance()->getValue( | |
| 220 | - 'select order_id from '._DB_PREFIX_.'pagantis_order where id = '.(int)$this->merchantOrderId | |
| 219 | + $this->pagantisOrderId = Db::getInstance()->getValue( | |
| 220 | + 'select order_id from '._DB_PREFIX_.'pagantis_order where id = '.(int) $this->merchantOrderId | |
| 221 | 221 | ); | 
| 222 | 222 | |
| 223 | 223 |              if (is_null($this->pagantisOrderId)) { | 
| @@ -278,20 +278,20 @@ discard block | ||
| 278 | 278 |          $merchantAmount = explode('.', explode(',', $merchantAmount)[0])[0]; | 
| 279 | 279 |          if ($totalAmount != $merchantAmount) { | 
| 280 | 280 |              try { | 
| 281 | - $psTotalAmount = substr_replace($merchantAmount, '.', (Tools::strlen($merchantAmount) -2), 0); | |
| 281 | + $psTotalAmount = substr_replace($merchantAmount, '.', (Tools::strlen($merchantAmount) - 2), 0); | |
| 282 | 282 | |
| 283 | 283 | $pgTotalAmountInCents = (string) $this->pagantisOrder->getShoppingCart()->getTotalAmount(); | 
| 284 | 284 | $pgTotalAmount = substr_replace( | 
| 285 | 285 | $pgTotalAmountInCents, | 
| 286 | 286 | '.', | 
| 287 | - (Tools::strlen($pgTotalAmountInCents) -2), | |
| 287 | + (Tools::strlen($pgTotalAmountInCents) - 2), | |
| 288 | 288 | 0 | 
| 289 | 289 | ); | 
| 290 | 290 | |
| 291 | - $this->amountMismatchError = '. Amount mismatch in PrestaShop Order #'. $this->merchantOrderId . | |
| 292 | - ' compared with Pagantis Order: ' . $this->pagantisOrderId . | |
| 293 | - '. The order in PrestaShop has an amount of ' . $psTotalAmount . ' and in Pagantis ' . | |
| 294 | - $pgTotalAmount . ' PLEASE REVIEW THE ORDER'; | |
| 291 | + $this->amountMismatchError = '. Amount mismatch in PrestaShop Order #'.$this->merchantOrderId. | |
| 292 | + ' compared with Pagantis Order: '.$this->pagantisOrderId. | |
| 293 | + '. The order in PrestaShop has an amount of '.$psTotalAmount.' and in Pagantis '. | |
| 294 | + $pgTotalAmount.' PLEASE REVIEW THE ORDER'; | |
| 295 | 295 | $this->saveLog(array( | 
| 296 | 296 | 'message' => $this->amountMismatchError | 
| 297 | 297 | )); | 
| @@ -311,21 +311,21 @@ discard block | ||
| 311 | 311 |          try { | 
| 312 | 312 |              if ($this->merchantOrder->orderExists() !== false) { | 
| 313 | 313 |                  throw new WrongStatusException('PS->orderExists() cart_id = ' | 
| 314 | - . $this->merchantOrderId . ' pagantis_id = ' | |
| 315 | - . $this->pagantisOrderId . '): already_processed'); | |
| 314 | + . $this->merchantOrderId.' pagantis_id = ' | |
| 315 | + . $this->pagantisOrderId.'): already_processed'); | |
| 316 | 316 | } | 
| 317 | 317 | |
| 318 | 318 | // Double check | 
| 319 | - $tableName = _DB_PREFIX_ . 'pagantis_order'; | |
| 319 | + $tableName = _DB_PREFIX_.'pagantis_order'; | |
| 320 | 320 | $fieldName = 'ps_order_id'; | 
| 321 | -            $sql = ('select ' . $fieldName . ' from `' . $tableName . '` where `id` = ' . (int)$this->merchantOrderId | |
| 322 | - . ' and `order_id` = \'' . $this->pagantisOrderId . '\'' | |
| 323 | - . ' and `' . $fieldName . '` is not null'); | |
| 321 | +            $sql = ('select '.$fieldName.' from `'.$tableName.'` where `id` = '.(int) $this->merchantOrderId | |
| 322 | + . ' and `order_id` = \''.$this->pagantisOrderId.'\'' | |
| 323 | + . ' and `'.$fieldName.'` is not null'); | |
| 324 | 324 | $results = Db::getInstance()->ExecuteS($sql); | 
| 325 | 325 |              if (is_array($results) && count($results) === 1) { | 
| 326 | -                throw new WrongStatusException('PS->record found in ' . $tableName | |
| 327 | - . ' (cart_id = ' . $this->merchantOrderId . ' pagantis_id = ' | |
| 328 | - . $this->pagantisOrderId . '): already_processed'); | |
| 326 | +                throw new WrongStatusException('PS->record found in '.$tableName | |
| 327 | + . ' (cart_id = '.$this->merchantOrderId.' pagantis_id = ' | |
| 328 | + . $this->pagantisOrderId.'): already_processed'); | |
| 329 | 329 | } | 
| 330 | 330 |          } catch (\Exception $exception) { | 
| 331 | 331 | throw new UnknownException($exception->getMessage()); | 
| @@ -354,9 +354,9 @@ discard block | ||
| 354 | 354 |                  Configuration::get('PS_OS_PAYMENT'), | 
| 355 | 355 | $this->merchantOrder->getOrderTotal(true), | 
| 356 | 356 | $this->module->displayName, | 
| 357 | - 'pagantisOrderId: ' . $this->pagantisOrder->getId() . ' ' . | |
| 358 | - 'pagantisOrderStatus: '. $this->pagantisOrder->getStatus() . | |
| 359 | - $this->amountMismatchError . | |
| 357 | + 'pagantisOrderId: '.$this->pagantisOrder->getId().' '. | |
| 358 | + 'pagantisOrderStatus: '.$this->pagantisOrder->getStatus(). | |
| 359 | + $this->amountMismatchError. | |
| 360 | 360 | $metadataInfo, | 
| 361 | 361 |                  array('transaction_id' => $this->pagantisOrderId), | 
| 362 | 362 | null, | 
| @@ -370,7 +370,7 @@ discard block | ||
| 370 | 370 | Db::getInstance()->update( | 
| 371 | 371 | 'pagantis_order', | 
| 372 | 372 |                  array('ps_order_id' => $this->module->currentOrder), | 
| 373 | - 'id = '. (int)$this->merchantOrderId . ' and order_id = \'' . $this->pagantisOrderId . '\'' | |
| 373 | + 'id = '.(int) $this->merchantOrderId.' and order_id = \''.$this->pagantisOrderId.'\'' | |
| 374 | 374 | ); | 
| 375 | 375 |          } catch (\Exception $exception) { | 
| 376 | 376 | // Do nothing | 
| @@ -388,9 +388,9 @@ discard block | ||
| 388 | 388 | $this->orderClient->confirmOrder($this->pagantisOrderId); | 
| 389 | 389 |              try { | 
| 390 | 390 | $mode = ($_SERVER['REQUEST_METHOD'] == 'POST') ? 'NOTIFICATION' : 'REDIRECTION'; | 
| 391 | - $message = 'Order CONFIRMED. The order was confirmed by a ' . $mode . | |
| 392 | - '. Pagantis OrderId=' . $this->pagantisOrderId . | |
| 393 | - '. Prestashop OrderId=' . $this->module->currentOrder; | |
| 391 | + $message = 'Order CONFIRMED. The order was confirmed by a '.$mode. | |
| 392 | + '. Pagantis OrderId='.$this->pagantisOrderId. | |
| 393 | + '. Prestashop OrderId='.$this->module->currentOrder; | |
| 394 | 394 |                  $this->saveLog(array('message' => $message)); | 
| 395 | 395 |              } catch (\Exception $exception) { | 
| 396 | 396 | // Do nothing | 
| @@ -408,15 +408,15 @@ discard block | ||
| 408 | 408 | public function rollbackMerchantOrder() | 
| 409 | 409 |      { | 
| 410 | 410 |          try { | 
| 411 | - $message = 'Roolback method: ' . | |
| 412 | - '. Pagantis OrderId=' . $this->pagantisOrderId . | |
| 413 | - '. Prestashop CartId=' . $this->merchantOrderId; | |
| 411 | + $message = 'Roolback method: '. | |
| 412 | + '. Pagantis OrderId='.$this->pagantisOrderId. | |
| 413 | + '. Prestashop CartId='.$this->merchantOrderId; | |
| 414 | 414 |              if ($this->module->currentOrder) { | 
| 415 | 415 | $objOrder = new Order($this->module->currentOrder); | 
| 416 | 416 | $history = new OrderHistory(); | 
| 417 | - $history->id_order = (int)$objOrder->id; | |
| 418 | - $history->changeIdOrderState(8, (int)($objOrder->id)); | |
| 419 | - $message .= ' Prestashop OrderId=' . $this->merchantOrderId; | |
| 417 | + $history->id_order = (int) $objOrder->id; | |
| 418 | + $history->changeIdOrderState(8, (int) ($objOrder->id)); | |
| 419 | + $message .= ' Prestashop OrderId='.$this->merchantOrderId; | |
| 420 | 420 | } | 
| 421 | 421 |              $this->saveLog(array('message' => $message)); | 
| 422 | 422 |          } catch (\Exception $exception) { | 
| @@ -435,7 +435,7 @@ discard block | ||
| 435 | 435 |      { | 
| 436 | 436 |          try { | 
| 437 | 437 | $table = 'pagantis_cart_process'; | 
| 438 | -            if (Db::getInstance()->insert($table, array('id' => (int)$orderId, 'timestamp' => (time()))) === false) { | |
| 438 | +            if (Db::getInstance()->insert($table, array('id' => (int) $orderId, 'timestamp' => (time()))) === false) { | |
| 439 | 439 |                  if ($_SERVER['REQUEST_METHOD'] == 'POST') { | 
| 440 | 440 | throw new ConcurrencyException(); | 
| 441 | 441 | } | 
| @@ -445,14 +445,14 @@ discard block | ||
| 445 | 445 | FROM %s WHERE %s", | 
| 446 | 446 | self::CONCURRENCY_TIMEOUT, | 
| 447 | 447 | _DB_PREFIX_.$table, | 
| 448 | - 'id='.(int)$orderId | |
| 448 | + 'id='.(int) $orderId | |
| 449 | 449 | ); | 
| 450 | 450 | $resultSeconds = Db::getInstance()->getValue($query); | 
| 451 | 451 | $restSeconds = isset($resultSeconds) ? ($resultSeconds) : 0; | 
| 452 | - $secondsToExpire = ($restSeconds>self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds; | |
| 452 | + $secondsToExpire = ($restSeconds > self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds; | |
| 453 | 453 | |
| 454 | 454 | $logMessage = sprintf( | 
| 455 | - "Redirect concurrency, User have to wait %s seconds, default seconds %s. CartId=" . $orderId, | |
| 455 | + "Redirect concurrency, User have to wait %s seconds, default seconds %s. CartId=".$orderId, | |
| 456 | 456 | $secondsToExpire, | 
| 457 | 457 | self::CONCURRENCY_TIMEOUT, | 
| 458 | 458 | $restSeconds | 
| @@ -461,7 +461,7 @@ discard block | ||
| 461 | 461 | $this->saveLog(array( | 
| 462 | 462 | 'message' => $logMessage | 
| 463 | 463 | )); | 
| 464 | - sleep($secondsToExpire+1); | |
| 464 | + sleep($secondsToExpire + 1); | |
| 465 | 465 | // After waiting...user continue the confirmation, hoping that previous call have finished. | 
| 466 | 466 | return true; | 
| 467 | 467 | } | 
| @@ -481,11 +481,11 @@ discard block | ||
| 481 | 481 |              if (is_null($orderId)) { | 
| 482 | 482 | Db::getInstance()->delete( | 
| 483 | 483 | 'pagantis_cart_process', | 
| 484 | - 'timestamp < ' . (time() - self::CONCURRENCY_TIMEOUT) | |
| 484 | + 'timestamp < '.(time() - self::CONCURRENCY_TIMEOUT) | |
| 485 | 485 | ); | 
| 486 | 486 | return; | 
| 487 | 487 | } | 
| 488 | -            Db::getInstance()->delete('pagantis_cart_process', 'id = ' . (int)$orderId); | |
| 488 | +            Db::getInstance()->delete('pagantis_cart_process', 'id = '.(int) $orderId); | |
| 489 | 489 |          } catch (\Exception $exception) { | 
| 490 | 490 | throw new ConcurrencyException(); | 
| 491 | 491 | } | 
| @@ -507,8 +507,8 @@ discard block | ||
| 507 | 507 | $data = array( | 
| 508 | 508 | 'merchantOrderId' => $this->merchantOrderId, | 
| 509 | 509 | 'pagantisOrderId' => $this->pagantisOrderId, | 
| 510 | - 'message' => ($exception)? $exception->getMessage() : 'Unable to get Exception message', | |
| 511 | - 'statusCode' => ($exception)? $exception->getCode() : 'Unable to get Exception statusCode', | |
| 510 | + 'message' => ($exception) ? $exception->getMessage() : 'Unable to get Exception message', | |
| 511 | + 'statusCode' => ($exception) ? $exception->getCode() : 'Unable to get Exception statusCode', | |
| 512 | 512 | 'method' => $method, | 
| 513 | 513 | 'file' => __FILE__, | 
| 514 | 514 | 'line' => $line, | 
| @@ -533,9 +533,9 @@ discard block | ||
| 533 | 533 | 'id_cart' => $this->merchantOrderId, | 
| 534 | 534 | 'key' => $this->config['secureKey'], | 
| 535 | 535 | 'id_module' => $this->module->id, | 
| 536 | - 'id_order' => ($this->pagantisOrder)?$this->pagantisOrder->getId(): null, | |
| 536 | + 'id_order' => ($this->pagantisOrder) ? $this->pagantisOrder->getId() : null, | |
| 537 | 537 | ); | 
| 538 | - $url = ($error)? $this->config['urlKO'] : $this->config['urlOK']; | |
| 538 | + $url = ($error) ? $this->config['urlKO'] : $this->config['urlOK']; | |
| 539 | 539 | return $this->redirect($url, $parameters); | 
| 540 | 540 | } | 
| 541 | 541 | } |