@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | } catch (\Exception $exception) { |
| 139 | 139 | $thrownException = true; |
| 140 | 140 | $this->getMerchantOrderId(); |
| 141 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; |
|
| 141 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; |
|
| 142 | 142 | if ($this->isPost()) { |
| 143 | 143 | $this->jsonResponse = new JsonExceptionResponse(); |
| 144 | 144 | $this->jsonResponse->setMerchantOrderId($theId); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | if (!$thrownException) { |
| 154 | 154 | $this->jsonResponse = new JsonSuccessResponse(); |
| 155 | 155 | $this->getMerchantOrderId(); |
| 156 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; |
|
| 156 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; |
|
| 157 | 157 | $this->jsonResponse->setMerchantOrderId($theId); |
| 158 | 158 | $this->jsonResponse->setPagantisOrderId($this->pagantisOrderId); |
| 159 | 159 | $this->confirmPagantisOrder(); |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | $this->rollbackMerchantOrder(); |
| 163 | 163 | if ($this->isNotification()) { |
| 164 | 164 | $this->getMerchantOrderId(); |
| 165 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; |
|
| 165 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; |
|
| 166 | 166 | $this->jsonResponse = new JsonExceptionResponse(); |
| 167 | 167 | $this->jsonResponse->setMerchantOrderId($theId); |
| 168 | 168 | $this->jsonResponse->setPagantisOrderId($this->pagantisOrderId); |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | } catch (\Exception $exception) { |
| 180 | 180 | $thrownException = true; |
| 181 | 181 | $this->getMerchantOrderId(); |
| 182 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; |
|
| 182 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; |
|
| 183 | 183 | if ($this->isPost()) { |
| 184 | 184 | $this->jsonResponse = new JsonExceptionResponse(); |
| 185 | 185 | $this->jsonResponse->setMerchantOrderId($theId); |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | $products = explode(',', Pagantis::getExtraConfig('PRODUCTS', null)); |
| 248 | 248 | if (!in_array(Tools::strtoupper($productCode), $products)) { |
| 249 | 249 | throw new UnknownException( |
| 250 | - 'No valid Pagantis product provided in the url: ' . Tools::getValue('product') |
|
| 250 | + 'No valid Pagantis product provided in the url: '.Tools::getValue('product') |
|
| 251 | 251 | ); |
| 252 | 252 | } |
| 253 | - $this->productName = "Pagantis " . Tools::strtolower($productCode); |
|
| 253 | + $this->productName = "Pagantis ".Tools::strtolower($productCode); |
|
| 254 | 254 | |
| 255 | - $this->config['publicKey'] = trim(Configuration::get(Tools::strtolower($productCode) . '_public_key')); |
|
| 256 | - $this->config['privateKey'] = trim(Configuration::get(Tools::strtolower($productCode) . '_private_key')); |
|
| 255 | + $this->config['publicKey'] = trim(Configuration::get(Tools::strtolower($productCode).'_public_key')); |
|
| 256 | + $this->config['privateKey'] = trim(Configuration::get(Tools::strtolower($productCode).'_private_key')); |
|
| 257 | 257 | |
| 258 | 258 | $this->merchantCartId = Tools::getValue('id_cart'); |
| 259 | 259 | |
@@ -273,8 +273,8 @@ discard block |
||
| 273 | 273 | public function getMerchantOrderId() |
| 274 | 274 | { |
| 275 | 275 | try { |
| 276 | - $table = _DB_PREFIX_ .self::ORDERS_TABLE; |
|
| 277 | - $sql = 'select ps_order_id from ' . $table .' where id = ' .(int)$this->merchantCartId; |
|
| 276 | + $table = _DB_PREFIX_.self::ORDERS_TABLE; |
|
| 277 | + $sql = 'select ps_order_id from '.$table.' where id = '.(int) $this->merchantCartId; |
|
| 278 | 278 | $this->merchantOrderId = Db::getInstance()->getValue($sql); |
| 279 | 279 | } catch (\Exception $exception) { |
| 280 | 280 | $exceptionMessage = sprintf( |
@@ -318,8 +318,8 @@ discard block |
||
| 318 | 318 | private function getPagantisOrderId() |
| 319 | 319 | { |
| 320 | 320 | try { |
| 321 | - $this->pagantisOrderId= Db::getInstance()->getValue( |
|
| 322 | - 'select order_id from '._DB_PREFIX_.self::ORDERS_TABLE.' where id = '.(int)$this->merchantCartId |
|
| 321 | + $this->pagantisOrderId = Db::getInstance()->getValue( |
|
| 322 | + 'select order_id from '._DB_PREFIX_.self::ORDERS_TABLE.' where id = '.(int) $this->merchantCartId |
|
| 323 | 323 | ); |
| 324 | 324 | |
| 325 | 325 | if (is_null($this->pagantisOrderId)) { |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | { |
| 354 | 354 | if ($this->pagantisOrder->getStatus() === PagantisModelOrder::STATUS_CONFIRMED) { |
| 355 | 355 | $this->getMerchantOrderId(); |
| 356 | - $theId = ($this->merchantOrderId)? $this->merchantOrderId : $this->merchantCartId; |
|
| 356 | + $theId = ($this->merchantOrderId) ? $this->merchantOrderId : $this->merchantCartId; |
|
| 357 | 357 | $this->jsonResponse = new JsonSuccessResponse(); |
| 358 | 358 | $this->jsonResponse->setMerchantOrderId($theId); |
| 359 | 359 | $this->jsonResponse->setPagantisOrderId($this->pagantisOrderId); |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | $psTotalAmount = substr_replace( |
| 386 | 386 | $merchantAmount, |
| 387 | 387 | '.', |
| 388 | - (Tools::strlen($merchantAmount) -2), |
|
| 388 | + (Tools::strlen($merchantAmount) - 2), |
|
| 389 | 389 | 0 |
| 390 | 390 | ); |
| 391 | 391 | |
@@ -393,14 +393,14 @@ discard block |
||
| 393 | 393 | $pgTotalAmount = substr_replace( |
| 394 | 394 | $pgTotalAmountInCents, |
| 395 | 395 | '.', |
| 396 | - (Tools::strlen($pgTotalAmountInCents) -2), |
|
| 396 | + (Tools::strlen($pgTotalAmountInCents) - 2), |
|
| 397 | 397 | 0 |
| 398 | 398 | ); |
| 399 | 399 | |
| 400 | - $this->amountMismatchError = '. Amount mismatch in PrestaShop Cart #'. $this->merchantCartId . |
|
| 401 | - ' compared with Pagantis Order: ' . $this->pagantisOrderId . |
|
| 402 | - '. The Cart in PrestaShop has an amount of ' . $psTotalAmount . ' and in Pagantis ' . |
|
| 403 | - $pgTotalAmount . ' PLEASE REVIEW THE ORDER'; |
|
| 400 | + $this->amountMismatchError = '. Amount mismatch in PrestaShop Cart #'.$this->merchantCartId. |
|
| 401 | + ' compared with Pagantis Order: '.$this->pagantisOrderId. |
|
| 402 | + '. The Cart in PrestaShop has an amount of '.$psTotalAmount.' and in Pagantis '. |
|
| 403 | + $pgTotalAmount.' PLEASE REVIEW THE ORDER'; |
|
| 404 | 404 | |
| 405 | 405 | $this->saveLog(array( |
| 406 | 406 | 'requestId' => $this->requestId, |
@@ -440,11 +440,11 @@ discard block |
||
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | // Double check |
| 443 | - $tableName = _DB_PREFIX_ . self::ORDERS_TABLE; |
|
| 443 | + $tableName = _DB_PREFIX_.self::ORDERS_TABLE; |
|
| 444 | 444 | $fieldName = 'ps_order_id'; |
| 445 | - $sql = ('select ' . $fieldName . ' from `' . $tableName . '` where `id` = ' . (int)$this->merchantCartId |
|
| 446 | - . ' and `order_id` = \'' . $this->pagantisOrderId . '\'' |
|
| 447 | - . ' and `' . $fieldName . '` is not null'); |
|
| 445 | + $sql = ('select '.$fieldName.' from `'.$tableName.'` where `id` = '.(int) $this->merchantCartId |
|
| 446 | + . ' and `order_id` = \''.$this->pagantisOrderId.'\'' |
|
| 447 | + . ' and `'.$fieldName.'` is not null'); |
|
| 448 | 448 | $results = Db::getInstance()->ExecuteS($sql); |
| 449 | 449 | if (is_array($results) && count($results) === 1) { |
| 450 | 450 | $this->getMerchantOrderId(); |
@@ -484,9 +484,9 @@ discard block |
||
| 484 | 484 | Configuration::get('PS_OS_PAYMENT'), |
| 485 | 485 | $this->merchantCart->getOrderTotal(true), |
| 486 | 486 | $this->productName, |
| 487 | - 'pagantisOrderId: ' . $this->pagantisOrder->getId() . ' ' . |
|
| 488 | - 'pagantisOrderStatus: '. $this->pagantisOrder->getStatus() . |
|
| 489 | - $this->amountMismatchError . |
|
| 487 | + 'pagantisOrderId: '.$this->pagantisOrder->getId().' '. |
|
| 488 | + 'pagantisOrderStatus: '.$this->pagantisOrder->getStatus(). |
|
| 489 | + $this->amountMismatchError. |
|
| 490 | 490 | $metadataInfo, |
| 491 | 491 | array('transaction_id' => $this->pagantisOrderId), |
| 492 | 492 | null, |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | Db::getInstance()->update( |
| 501 | 501 | self::ORDERS_TABLE, |
| 502 | 502 | array('ps_order_id' => $this->module->currentOrder), |
| 503 | - 'id = '. (int)$this->merchantCartId . ' and order_id = \'' . $this->pagantisOrderId . '\'' |
|
| 503 | + 'id = '.(int) $this->merchantCartId.' and order_id = \''.$this->pagantisOrderId.'\'' |
|
| 504 | 504 | ); |
| 505 | 505 | |
| 506 | 506 | } catch (\Exception $exception) { |
@@ -527,9 +527,9 @@ discard block |
||
| 527 | 527 | $this->orderClient->confirmOrder($this->pagantisOrderId); |
| 528 | 528 | try { |
| 529 | 529 | $mode = ($this->isPost()) ? 'NOTIFICATION' : 'REDIRECTION'; |
| 530 | - $message = 'Order CONFIRMED. The order was confirmed by a ' . $mode . |
|
| 531 | - '. Pagantis OrderId=' . $this->pagantisOrderId . |
|
| 532 | - '. Prestashop OrderId=' . $this->module->currentOrder; |
|
| 530 | + $message = 'Order CONFIRMED. The order was confirmed by a '.$mode. |
|
| 531 | + '. Pagantis OrderId='.$this->pagantisOrderId. |
|
| 532 | + '. Prestashop OrderId='.$this->module->currentOrder; |
|
| 533 | 533 | $this->saveLog(array('requestId' => $this->requestId, 'message' => $message)); |
| 534 | 534 | } catch (\Exception $exception) { |
| 535 | 535 | $exceptionMessage = sprintf( |
@@ -556,16 +556,16 @@ discard block |
||
| 556 | 556 | { |
| 557 | 557 | try { |
| 558 | 558 | $this->getMerchantOrderId(); |
| 559 | - $message = 'Roolback method: ' . |
|
| 560 | - '. Pagantis OrderId=' . $this->pagantisOrderId . |
|
| 561 | - '. Prestashop CartId=' . $this->merchantCartId . |
|
| 562 | - '. Prestashop OrderId=' . $this->merchantOrderId; |
|
| 559 | + $message = 'Roolback method: '. |
|
| 560 | + '. Pagantis OrderId='.$this->pagantisOrderId. |
|
| 561 | + '. Prestashop CartId='.$this->merchantCartId. |
|
| 562 | + '. Prestashop OrderId='.$this->merchantOrderId; |
|
| 563 | 563 | if ($this->module->currentOrder) { |
| 564 | 564 | $objOrder = new Order($this->module->currentOrder); |
| 565 | 565 | $history = new OrderHistory(); |
| 566 | - $history->id_order = (int)$objOrder->id; |
|
| 567 | - $history->changeIdOrderState(8, (int)($objOrder->id)); |
|
| 568 | - $message .= ' Prestashop OrderId=' . $this->merchantCartId; |
|
| 566 | + $history->id_order = (int) $objOrder->id; |
|
| 567 | + $history->changeIdOrderState(8, (int) ($objOrder->id)); |
|
| 568 | + $message .= ' Prestashop OrderId='.$this->merchantCartId; |
|
| 569 | 569 | } |
| 570 | 570 | $this->saveLog(array( |
| 571 | 571 | 'requestId' => $this->requestId, |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | { |
| 591 | 591 | try { |
| 592 | 592 | $table = self::CART_TABLE; |
| 593 | - $insertBlock = Db::getInstance()->insert($table, array('id' =>(int)$orderId, 'timestamp' =>(time()))); |
|
| 593 | + $insertBlock = Db::getInstance()->insert($table, array('id' =>(int) $orderId, 'timestamp' =>(time()))); |
|
| 594 | 594 | if ($insertBlock === false) { |
| 595 | 595 | if ($this->isNotification()) { |
| 596 | 596 | throw new ConcurrencyException(); |
@@ -600,11 +600,11 @@ discard block |
||
| 600 | 600 | as rest FROM %s WHERE %s", |
| 601 | 601 | self::CONCURRENCY_TIMEOUT, |
| 602 | 602 | _DB_PREFIX_.$table, |
| 603 | - 'id='.(int)$orderId |
|
| 603 | + 'id='.(int) $orderId |
|
| 604 | 604 | ); |
| 605 | 605 | $resultSeconds = Db::getInstance()->getValue($query); |
| 606 | 606 | $restSeconds = isset($resultSeconds) ? ($resultSeconds) : 0; |
| 607 | - $secondsToExpire = ($restSeconds>self::CONCURRENCY_TIMEOUT) ? |
|
| 607 | + $secondsToExpire = ($restSeconds > self::CONCURRENCY_TIMEOUT) ? |
|
| 608 | 608 | self::CONCURRENCY_TIMEOUT : $restSeconds; |
| 609 | 609 | if ($secondsToExpire > 0) { |
| 610 | 610 | sleep($secondsToExpire + 1); |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | $this->getMerchantOrderId(); |
| 614 | 614 | $this->getPagantisOrderId(); |
| 615 | 615 | |
| 616 | - $logMessage = sprintf( |
|
| 616 | + $logMessage = sprintf( |
|
| 617 | 617 | "User has waited %s seconds, default %s, bd time to expire %s [cartId=%s][origin=%s]", |
| 618 | 618 | $secondsToExpire, |
| 619 | 619 | self::CONCURRENCY_TIMEOUT, |
@@ -642,10 +642,10 @@ discard block |
||
| 642 | 642 | { |
| 643 | 643 | try { |
| 644 | 644 | if (is_null($orderId)) { |
| 645 | - Db::getInstance()->delete(self::CART_TABLE, 'timestamp < ' . (time() - self::CONCURRENCY_TIMEOUT)); |
|
| 645 | + Db::getInstance()->delete(self::CART_TABLE, 'timestamp < '.(time() - self::CONCURRENCY_TIMEOUT)); |
|
| 646 | 646 | return; |
| 647 | 647 | } |
| 648 | - Db::getInstance()->delete(self::CART_TABLE, 'id = ' . (int)$orderId); |
|
| 648 | + Db::getInstance()->delete(self::CART_TABLE, 'id = '.(int) $orderId); |
|
| 649 | 649 | } catch (\Exception $exception) { |
| 650 | 650 | throw new ConcurrencyException(); |
| 651 | 651 | } |
@@ -670,8 +670,8 @@ discard block |
||
| 670 | 670 | 'merchantCartId' => $this->merchantCartId, |
| 671 | 671 | 'merchantOrderId' => $this->merchantOrderId, |
| 672 | 672 | 'pagantisOrderId' => $this->pagantisOrderId, |
| 673 | - 'message' => ($exception)? $exception->getMessage() : 'Unable to get Exception message', |
|
| 674 | - 'statusCode' => ($exception)? $exception->getCode() : 'Unable to get Exception statusCode', |
|
| 673 | + 'message' => ($exception) ? $exception->getMessage() : 'Unable to get Exception message', |
|
| 674 | + 'statusCode' => ($exception) ? $exception->getCode() : 'Unable to get Exception statusCode', |
|
| 675 | 675 | 'method' => $method, |
| 676 | 676 | 'file' => __FILE__, |
| 677 | 677 | 'line' => $line, |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | 'id_module' => $this->module->id, |
| 708 | 708 | 'id_order' => ($this->pagantisOrder) ? $this->pagantisOrder->getId() : null, |
| 709 | 709 | ); |
| 710 | - $url = ($error)? $this->config['urlKO'] : $this->config['urlOK']; |
|
| 710 | + $url = ($error) ? $this->config['urlKO'] : $this->config['urlOK']; |
|
| 711 | 711 | $returnMessage = sprintf( |
| 712 | 712 | "[origin=%s][cartId=%s][prestashopOrderId=%s][pagantisOrderId=%s][returnUrl=%s]", |
| 713 | 713 | $this->getOrigin(), |