| @@ -149,7 +149,7 @@ discard block | ||
| 149 | 149 |          } catch (\Exception $exception) { | 
| 150 | 150 | $thrownException = true; | 
| 151 | 151 | $this->getMerchantOrderId(); | 
| 152 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; | |
| 152 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; | |
| 153 | 153 |              if ($this->isPost()) { | 
| 154 | 154 | $this->jsonResponse = new JsonExceptionResponse(); | 
| 155 | 155 | $this->jsonResponse->setMerchantOrderId($theId); | 
| @@ -164,7 +164,7 @@ discard block | ||
| 164 | 164 |              if (!$thrownException) { | 
| 165 | 165 | $this->jsonResponse = new JsonSuccessResponse(); | 
| 166 | 166 | $this->getMerchantOrderId(); | 
| 167 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; | |
| 167 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; | |
| 168 | 168 | $this->jsonResponse->setMerchantOrderId($theId); | 
| 169 | 169 | $this->jsonResponse->setPagantisOrderId($this->pagantisOrderId); | 
| 170 | 170 | $this->confirmPagantisOrder(); | 
| @@ -173,7 +173,7 @@ discard block | ||
| 173 | 173 | $this->rollbackMerchantOrder(); | 
| 174 | 174 |              if ($this->isNotification()) { | 
| 175 | 175 | $this->getMerchantOrderId(); | 
| 176 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; | |
| 176 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; | |
| 177 | 177 | $this->jsonResponse = new JsonExceptionResponse(); | 
| 178 | 178 | $this->jsonResponse->setMerchantOrderId($theId); | 
| 179 | 179 | $this->jsonResponse->setPagantisOrderId($this->pagantisOrderId); | 
| @@ -190,7 +190,7 @@ discard block | ||
| 190 | 190 |          } catch (\Exception $exception) { | 
| 191 | 191 | $thrownException = true; | 
| 192 | 192 | $this->getMerchantOrderId(); | 
| 193 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; | |
| 193 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; | |
| 194 | 194 |              if ($this->isPost()) { | 
| 195 | 195 | $this->jsonResponse = new JsonExceptionResponse(); | 
| 196 | 196 | $this->jsonResponse->setMerchantOrderId($theId); | 
| @@ -259,13 +259,13 @@ discard block | ||
| 259 | 259 |          $products = explode(',', Pagantis::getExtraConfig('PRODUCTS', null)); | 
| 260 | 260 |          if (!in_array(Tools::strtoupper($productCode), $products)) { | 
| 261 | 261 | throw new UnknownException( | 
| 262 | -                'No valid Pagantis product provided in the url: ' . Tools::getValue('product') | |
| 262 | +                'No valid Pagantis product provided in the url: '.Tools::getValue('product') | |
| 263 | 263 | ); | 
| 264 | 264 | } | 
| 265 | - $this->productName = "Pagantis " . Tools::strtolower($productCode); | |
| 265 | + $this->productName = "Pagantis ".Tools::strtolower($productCode); | |
| 266 | 266 | |
| 267 | - $this->config['publicKey'] = trim(Configuration::get(Tools::strtolower($productCode) . '_public_key')); | |
| 268 | - $this->config['privateKey'] = trim(Configuration::get(Tools::strtolower($productCode) . '_private_key')); | |
| 267 | + $this->config['publicKey'] = trim(Configuration::get(Tools::strtolower($productCode).'_public_key')); | |
| 268 | + $this->config['privateKey'] = trim(Configuration::get(Tools::strtolower($productCode).'_private_key')); | |
| 269 | 269 | |
| 270 | 270 |          $this->merchantCartId = Tools::getValue('id_cart'); | 
| 271 | 271 | |
| @@ -285,8 +285,8 @@ discard block | ||
| 285 | 285 | public function getMerchantOrderId() | 
| 286 | 286 |      { | 
| 287 | 287 |          try { | 
| 288 | - $sql = 'select ps_order_id from ' . _DB_PREFIX_ .self::ORDERS_TABLE .' where id = ' | |
| 289 | - .(int)$this->merchantCartId . ' and token = \'' . $this->token . '\''; | |
| 288 | + $sql = 'select ps_order_id from '._DB_PREFIX_.self::ORDERS_TABLE.' where id = ' | |
| 289 | + .(int) $this->merchantCartId.' and token = \''.$this->token.'\''; | |
| 290 | 290 | $this->merchantOrderId = Db::getInstance()->getValue($sql); | 
| 291 | 291 |          } catch (\Exception $exception) { | 
| 292 | 292 | $exceptionMessage = sprintf( | 
| @@ -330,9 +330,9 @@ discard block | ||
| 330 | 330 | private function getPagantisOrderId() | 
| 331 | 331 |      { | 
| 332 | 332 |          try { | 
| 333 | - $sql = 'select order_id from ' . _DB_PREFIX_.self::ORDERS_TABLE .' where id = ' | |
| 334 | - .(int)$this->merchantCartId . ' and token = \'' . $this->token . '\''; | |
| 335 | - $this->pagantisOrderId= Db::getInstance()->getValue($sql); | |
| 333 | + $sql = 'select order_id from '._DB_PREFIX_.self::ORDERS_TABLE.' where id = ' | |
| 334 | + .(int) $this->merchantCartId.' and token = \''.$this->token.'\''; | |
| 335 | + $this->pagantisOrderId = Db::getInstance()->getValue($sql); | |
| 336 | 336 | |
| 337 | 337 |              if (is_null($this->pagantisOrderId)) { | 
| 338 | 338 | throw new NoIdentificationException(); | 
| @@ -365,7 +365,7 @@ discard block | ||
| 365 | 365 |      { | 
| 366 | 366 |          if ($this->pagantisOrder->getStatus() === PagantisModelOrder::STATUS_CONFIRMED) { | 
| 367 | 367 | $this->getMerchantOrderId(); | 
| 368 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; | |
| 368 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; | |
| 369 | 369 | $this->jsonResponse = new JsonSuccessResponse(); | 
| 370 | 370 | $this->jsonResponse->setMerchantOrderId($theId); | 
| 371 | 371 | $this->jsonResponse->setPagantisOrderId($this->pagantisOrderId); | 
| @@ -396,7 +396,7 @@ discard block | ||
| 396 | 396 | $psTotalAmount = substr_replace( | 
| 397 | 397 | $merchantAmount, | 
| 398 | 398 | '.', | 
| 399 | - (Tools::strlen($merchantAmount) -2), | |
| 399 | + (Tools::strlen($merchantAmount) - 2), | |
| 400 | 400 | 0 | 
| 401 | 401 | ); | 
| 402 | 402 | |
| @@ -404,14 +404,14 @@ discard block | ||
| 404 | 404 | $pgTotalAmount = substr_replace( | 
| 405 | 405 | $pgTotalAmountInCents, | 
| 406 | 406 | '.', | 
| 407 | - (Tools::strlen($pgTotalAmountInCents) -2), | |
| 407 | + (Tools::strlen($pgTotalAmountInCents) - 2), | |
| 408 | 408 | 0 | 
| 409 | 409 | ); | 
| 410 | 410 | |
| 411 | - $this->amountMismatchError = '. Amount mismatch in PrestaShop Cart #'. $this->merchantCartId . | |
| 412 | - ' compared with Pagantis Order: ' . $this->pagantisOrderId . | |
| 413 | - '. The Cart in PrestaShop has an amount of ' . $psTotalAmount . ' and in Pagantis ' . | |
| 414 | - $pgTotalAmount . ' PLEASE REVIEW THE ORDER'; | |
| 411 | + $this->amountMismatchError = '. Amount mismatch in PrestaShop Cart #'.$this->merchantCartId. | |
| 412 | + ' compared with Pagantis Order: '.$this->pagantisOrderId. | |
| 413 | + '. The Cart in PrestaShop has an amount of '.$psTotalAmount.' and in Pagantis '. | |
| 414 | + $pgTotalAmount.' PLEASE REVIEW THE ORDER'; | |
| 415 | 415 | |
| 416 | 416 | $this->saveLog(array( | 
| 417 | 417 | 'requestId' => $this->requestId, | 
| @@ -419,7 +419,7 @@ discard block | ||
| 419 | 419 | )); | 
| 420 | 420 | $numberPagantisAmount = (integer) $this->pagantisOrder->getShoppingCart()->getTotalAmount(); | 
| 421 | 421 | $numberMerchantAmount = (integer) (100 * $this->merchantCart->getOrderTotal(true)); | 
| 422 | - $amountDff = $numberMerchantAmount - $numberPagantisAmount; | |
| 422 | + $amountDff = $numberMerchantAmount - $numberPagantisAmount; | |
| 423 | 423 |              if (abs($amountDff) > self::MISMATCH_AMOUNT_THRESHOLD) { | 
| 424 | 424 | throw new AmountMismatchException($totalAmount, $merchantAmount); | 
| 425 | 425 | } | 
| @@ -446,12 +446,12 @@ discard block | ||
| 446 | 446 | } | 
| 447 | 447 | |
| 448 | 448 | // Double check | 
| 449 | - $tableName = _DB_PREFIX_ . self::ORDERS_TABLE; | |
| 449 | + $tableName = _DB_PREFIX_.self::ORDERS_TABLE; | |
| 450 | 450 | $fieldName = 'ps_order_id'; | 
| 451 | -            $sql = ('select ' . $fieldName . ' from `' . $tableName . '` where `id` = ' . (int)$this->merchantCartId | |
| 452 | - . ' and `order_id` = \'' . $this->pagantisOrderId . '\'' | |
| 453 | - . ' and `token` = \'' . $this->token . '\'' | |
| 454 | - . ' and `' . $fieldName . '` is not null'); | |
| 451 | +            $sql = ('select '.$fieldName.' from `'.$tableName.'` where `id` = '.(int) $this->merchantCartId | |
| 452 | + . ' and `order_id` = \''.$this->pagantisOrderId.'\'' | |
| 453 | + . ' and `token` = \''.$this->token.'\'' | |
| 454 | + . ' and `'.$fieldName.'` is not null'); | |
| 455 | 455 | $results = Db::getInstance()->ExecuteS($sql); | 
| 456 | 456 |              if (is_array($results) && count($results) === 1) { | 
| 457 | 457 | $this->getMerchantOrderId(); | 
| @@ -491,9 +491,9 @@ discard block | ||
| 491 | 491 |                  Configuration::get('PS_OS_PAYMENT'), | 
| 492 | 492 | $this->merchantCart->getOrderTotal(true), | 
| 493 | 493 | $this->productName, | 
| 494 | - 'pagantisOrderId: ' . $this->pagantisOrder->getId() . ' ' . | |
| 495 | - 'pagantisOrderStatus: '. $this->pagantisOrder->getStatus() . | |
| 496 | - $this->amountMismatchError . | |
| 494 | + 'pagantisOrderId: '.$this->pagantisOrder->getId().' '. | |
| 495 | + 'pagantisOrderStatus: '.$this->pagantisOrder->getStatus(). | |
| 496 | + $this->amountMismatchError. | |
| 497 | 497 | $metadataInfo, | 
| 498 | 498 |                  array('transaction_id' => $this->pagantisOrderId), | 
| 499 | 499 | null, | 
| @@ -507,9 +507,9 @@ discard block | ||
| 507 | 507 | Db::getInstance()->update( | 
| 508 | 508 | self::ORDERS_TABLE, | 
| 509 | 509 |                  array('ps_order_id' => $this->module->currentOrder), | 
| 510 | - 'id = '. (int)$this->merchantCartId | |
| 511 | - . ' and order_id = \'' . $this->pagantisOrderId . '\'' | |
| 512 | - . ' and token = \'' . $this->token . '\'' | |
| 510 | + 'id = '.(int) $this->merchantCartId | |
| 511 | + . ' and order_id = \''.$this->pagantisOrderId.'\'' | |
| 512 | + . ' and token = \''.$this->token.'\'' | |
| 513 | 513 | ); | 
| 514 | 514 | |
| 515 | 515 |          } catch (\Exception $exception) { | 
| @@ -536,9 +536,9 @@ discard block | ||
| 536 | 536 | $this->orderClient->confirmOrder($this->pagantisOrderId); | 
| 537 | 537 |              try { | 
| 538 | 538 | $mode = ($this->isPost()) ? 'NOTIFICATION' : 'REDIRECTION'; | 
| 539 | - $message = 'Order CONFIRMED. The order was confirmed by a ' . $mode . | |
| 540 | - '. Pagantis OrderId=' . $this->pagantisOrderId . | |
| 541 | - '. Prestashop OrderId=' . $this->module->currentOrder; | |
| 539 | + $message = 'Order CONFIRMED. The order was confirmed by a '.$mode. | |
| 540 | + '. Pagantis OrderId='.$this->pagantisOrderId. | |
| 541 | + '. Prestashop OrderId='.$this->module->currentOrder; | |
| 542 | 542 |                  $this->saveLog(array('requestId' => $this->requestId, 'message' => $message)); | 
| 543 | 543 |              } catch (\Exception $exception) { | 
| 544 | 544 | $exceptionMessage = sprintf( | 
| @@ -565,16 +565,16 @@ discard block | ||
| 565 | 565 |      { | 
| 566 | 566 |          try { | 
| 567 | 567 | $this->getMerchantOrderId(); | 
| 568 | - $message = 'Roolback method: ' . | |
| 569 | - '. Pagantis OrderId=' . $this->pagantisOrderId . | |
| 570 | - '. Prestashop CartId=' . $this->merchantCartId . | |
| 571 | - '. Prestashop OrderId=' . $this->merchantOrderId; | |
| 568 | + $message = 'Roolback method: '. | |
| 569 | + '. Pagantis OrderId='.$this->pagantisOrderId. | |
| 570 | + '. Prestashop CartId='.$this->merchantCartId. | |
| 571 | + '. Prestashop OrderId='.$this->merchantOrderId; | |
| 572 | 572 |              if ($this->module->currentOrder) { | 
| 573 | 573 | $objOrder = new Order($this->module->currentOrder); | 
| 574 | 574 | $history = new OrderHistory(); | 
| 575 | - $history->id_order = (int)$objOrder->id; | |
| 576 | - $history->changeIdOrderState(8, (int)($objOrder->id)); | |
| 577 | - $message .= ' Prestashop OrderId=' . $this->merchantCartId; | |
| 575 | + $history->id_order = (int) $objOrder->id; | |
| 576 | + $history->changeIdOrderState(8, (int) ($objOrder->id)); | |
| 577 | + $message .= ' Prestashop OrderId='.$this->merchantCartId; | |
| 578 | 578 | } | 
| 579 | 579 | $this->saveLog(array( | 
| 580 | 580 | 'requestId' => $this->requestId, | 
| @@ -599,7 +599,7 @@ discard block | ||
| 599 | 599 |      { | 
| 600 | 600 |          try { | 
| 601 | 601 | $table = self::CART_TABLE; | 
| 602 | -            $insertBlock = Db::getInstance()->insert($table, array('id' =>(int)$orderId, 'timestamp' =>(time()))); | |
| 602 | +            $insertBlock = Db::getInstance()->insert($table, array('id' =>(int) $orderId, 'timestamp' =>(time()))); | |
| 603 | 603 |              if ($insertBlock === false) { | 
| 604 | 604 |                  if ($this->isNotification()) { | 
| 605 | 605 | throw new ConcurrencyException(); | 
| @@ -609,11 +609,11 @@ discard block | ||
| 609 | 609 | as rest FROM %s WHERE %s", | 
| 610 | 610 | self::CONCURRENCY_TIMEOUT, | 
| 611 | 611 | _DB_PREFIX_.$table, | 
| 612 | - 'id='.(int)$orderId | |
| 612 | + 'id='.(int) $orderId | |
| 613 | 613 | ); | 
| 614 | 614 | $resultSeconds = Db::getInstance()->getValue($query); | 
| 615 | 615 | $restSeconds = isset($resultSeconds) ? ($resultSeconds) : 0; | 
| 616 | - $secondsToExpire = ($restSeconds>self::CONCURRENCY_TIMEOUT) ? | |
| 616 | + $secondsToExpire = ($restSeconds > self::CONCURRENCY_TIMEOUT) ? | |
| 617 | 617 | self::CONCURRENCY_TIMEOUT : $restSeconds; | 
| 618 | 618 |                      if ($secondsToExpire > 0) { | 
| 619 | 619 | sleep($secondsToExpire + 1); | 
| @@ -622,7 +622,7 @@ discard block | ||
| 622 | 622 | $this->getMerchantOrderId(); | 
| 623 | 623 | $this->getPagantisOrderId(); | 
| 624 | 624 | |
| 625 | - $logMessage = sprintf( | |
| 625 | + $logMessage = sprintf( | |
| 626 | 626 | "User has waited %s seconds, default %s, bd time to expire %s [cartId=%s][origin=%s]", | 
| 627 | 627 | $secondsToExpire, | 
| 628 | 628 | self::CONCURRENCY_TIMEOUT, | 
| @@ -651,10 +651,10 @@ discard block | ||
| 651 | 651 |      { | 
| 652 | 652 |          try { | 
| 653 | 653 |              if (is_null($orderId)) { | 
| 654 | - Db::getInstance()->delete(self::CART_TABLE, 'timestamp < ' . (time() - self::CONCURRENCY_TIMEOUT)); | |
| 654 | + Db::getInstance()->delete(self::CART_TABLE, 'timestamp < '.(time() - self::CONCURRENCY_TIMEOUT)); | |
| 655 | 655 | return; | 
| 656 | 656 | } | 
| 657 | - Db::getInstance()->delete(self::CART_TABLE, 'id = ' . (int)$orderId); | |
| 657 | + Db::getInstance()->delete(self::CART_TABLE, 'id = '.(int) $orderId); | |
| 658 | 658 |          } catch (\Exception $exception) { | 
| 659 | 659 | throw new ConcurrencyException(); | 
| 660 | 660 | } | 
| @@ -679,8 +679,8 @@ discard block | ||
| 679 | 679 | 'merchantCartId' => $this->merchantCartId, | 
| 680 | 680 | 'merchantOrderId' => $this->merchantOrderId, | 
| 681 | 681 | 'pagantisOrderId' => $this->pagantisOrderId, | 
| 682 | - 'message' => ($exception)? $exception->getMessage() : 'Unable to get Exception message', | |
| 683 | - 'statusCode' => ($exception)? $exception->getCode() : 'Unable to get Exception statusCode', | |
| 682 | + 'message' => ($exception) ? $exception->getMessage() : 'Unable to get Exception message', | |
| 683 | + 'statusCode' => ($exception) ? $exception->getCode() : 'Unable to get Exception statusCode', | |
| 684 | 684 | 'method' => $method, | 
| 685 | 685 | 'file' => __FILE__, | 
| 686 | 686 | 'line' => $line, | 
| @@ -716,7 +716,7 @@ discard block | ||
| 716 | 716 | 'id_module' => $this->module->id, | 
| 717 | 717 | 'id_order' => ($this->pagantisOrder) ? $this->pagantisOrder->getId() : null, | 
| 718 | 718 | ); | 
| 719 | - $url = ($error)? $this->config['urlKO'] : $this->config['urlOK']; | |
| 719 | + $url = ($error) ? $this->config['urlKO'] : $this->config['urlOK']; | |
| 720 | 720 | $returnMessage = sprintf( | 
| 721 | 721 | "[origin=%s][cartId=%s][prestashopOrderId=%s][pagantisOrderId=%s][returnUrl=%s]", | 
| 722 | 722 | $this->getOrigin(), |