| @@ -28,9 +28,9 @@ discard block | ||
| 28 | 28 |      { | 
| 29 | 29 |          if (_PS_VERSION_ < 1.6) { | 
| 30 | 30 | Logger::addLog( | 
| 31 | - 'Pagantis Exception For user ' . | |
| 32 | - $customer->email . | |
| 33 | - ' : ' . | |
| 31 | + 'Pagantis Exception For user '. | |
| 32 | + $customer->email. | |
| 33 | + ' : '. | |
| 34 | 34 | $exception->getMessage(), | 
| 35 | 35 | 3, | 
| 36 | 36 | $exception->getCode(), | 
| @@ -40,9 +40,9 @@ discard block | ||
| 40 | 40 | ); | 
| 41 | 41 |          } else { | 
| 42 | 42 | PrestaShopLogger::addLog( | 
| 43 | - 'Pagantis Exception For user ' . | |
| 44 | - $customer->email . | |
| 45 | - ' : ' . | |
| 43 | + 'Pagantis Exception For user '. | |
| 44 | + $customer->email. | |
| 45 | + ' : '. | |
| 46 | 46 | $exception->getMessage(), | 
| 47 | 47 | 3, | 
| 48 | 48 | $exception->getCode(), | 
| @@ -107,24 +107,24 @@ discard block | ||
| 107 | 107 | |
| 108 | 108 |          try { | 
| 109 | 109 | $shippingCountry = Country::getIsoById($shippingAddress->id_country); | 
| 110 | - $userAddress = new \Pagantis\OrdersApiClient\Model\Order\User\Address(); | |
| 110 | + $userAddress = new \Pagantis\OrdersApiClient\Model\Order\User\Address(); | |
| 111 | 111 | $userAddress | 
| 112 | 112 | ->setZipCode($shippingAddress->postcode) | 
| 113 | - ->setFullName($shippingAddress->firstname . ' ' . $shippingAddress->lastname) | |
| 113 | + ->setFullName($shippingAddress->firstname.' '.$shippingAddress->lastname) | |
| 114 | 114 | ->setCountryCode($shippingCountry) | 
| 115 | 115 | ->setCity($shippingAddress->city) | 
| 116 | - ->setAddress($shippingAddress->address1 . ' ' . $shippingAddress->address2) | |
| 116 | + ->setAddress($shippingAddress->address1.' '.$shippingAddress->address2) | |
| 117 | 117 | ->setTaxId($this->getTaxId($customer, $shippingAddress, $billingAddress)) | 
| 118 | 118 | ->setNationalId($this->getNationalId($customer, $shippingAddress, $billingAddress)) | 
| 119 | 119 | ; | 
| 120 | 120 | |
| 121 | - $orderShippingAddress = new \Pagantis\OrdersApiClient\Model\Order\User\Address(); | |
| 121 | + $orderShippingAddress = new \Pagantis\OrdersApiClient\Model\Order\User\Address(); | |
| 122 | 122 | $orderShippingAddress | 
| 123 | 123 | ->setZipCode($shippingAddress->postcode) | 
| 124 | - ->setFullName($shippingAddress->firstname . ' ' . $shippingAddress->lastname) | |
| 124 | + ->setFullName($shippingAddress->firstname.' '.$shippingAddress->lastname) | |
| 125 | 125 | ->setCountryCode($shippingCountry) | 
| 126 | 126 | ->setCity($shippingAddress->city) | 
| 127 | - ->setAddress($shippingAddress->address1 . ' ' . $shippingAddress->address2) | |
| 127 | + ->setAddress($shippingAddress->address1.' '.$shippingAddress->address2) | |
| 128 | 128 | ->setTaxId($this->getTaxId($customer, $shippingAddress, $billingAddress)) | 
| 129 | 129 | ->setNationalId($this->getNationalId($customer, $shippingAddress, $billingAddress)) | 
| 130 | 130 | ->setFixPhone($shippingAddress->phone) | 
| @@ -135,10 +135,10 @@ discard block | ||
| 135 | 135 | $orderBillingAddress = new \Pagantis\OrdersApiClient\Model\Order\User\Address(); | 
| 136 | 136 | $orderBillingAddress | 
| 137 | 137 | ->setZipCode($billingAddress->postcode) | 
| 138 | - ->setFullName($billingAddress->firstname . ' ' . $billingAddress->lastname) | |
| 138 | + ->setFullName($billingAddress->firstname.' '.$billingAddress->lastname) | |
| 139 | 139 | ->setCountryCode($billingCountry) | 
| 140 | 140 | ->setCity($billingAddress->city) | 
| 141 | - ->setAddress($billingAddress->address1 . ' ' . $billingAddress->address2) | |
| 141 | + ->setAddress($billingAddress->address1.' '.$billingAddress->address2) | |
| 142 | 142 | ->setTaxId($this->getTaxId($customer, $billingAddress, $shippingAddress)) | 
| 143 | 143 | ->setNationalId($this->getNationalId($customer, $billingAddress, $shippingAddress)) | 
| 144 | 144 | ->setFixPhone($billingAddress->phone) | 
| @@ -158,7 +158,7 @@ discard block | ||
| 158 | 158 | ->setNationalId($this->getNationalId($customer, $shippingAddress, $billingAddress)) | 
| 159 | 159 | ; | 
| 160 | 160 | |
| 161 | -            if ($customer->birthday!='0000-00-00') { | |
| 161 | +            if ($customer->birthday != '0000-00-00') { | |
| 162 | 162 | $orderUser->setDateOfBirth($customer->birthday); | 
| 163 | 163 | } | 
| 164 | 164 | |
| @@ -192,13 +192,13 @@ discard block | ||
| 192 | 192 | ->setQuantity($item['quantity']) | 
| 193 | 193 | ->setDescription($item['name']); | 
| 194 | 194 |                  if ($promotedProduct) { | 
| 195 | - $promotedAmount+=$product->getAmount(); | |
| 195 | + $promotedAmount += $product->getAmount(); | |
| 196 | 196 | $productId = $item['id_product']; | 
| 197 | 197 | $finalPrice = Product::getPriceStatic($productId); | 
| 198 | - $promotedMessage = 'Promoted Item: ' . $product->getDescription() . | |
| 199 | - ' Price: ' . $finalPrice . | |
| 200 | - ' Qty: ' . $product->getQuantity() . | |
| 201 | - ' Item ID: ' . $item['id_product']; | |
| 198 | + $promotedMessage = 'Promoted Item: '.$product->getDescription(). | |
| 199 | + ' Price: '.$finalPrice. | |
| 200 | + ' Qty: '.$product->getQuantity(). | |
| 201 | + ' Item ID: '.$item['id_product']; | |
| 202 | 202 |                      $metadataOrder->addMetadata('promotedProduct', $promotedMessage); | 
| 203 | 203 | } | 
| 204 | 204 | $details->addProduct($product); | 
| @@ -249,7 +249,7 @@ discard block | ||
| 249 | 249 | Tools::redirect($cancelUrl); | 
| 250 | 250 | } | 
| 251 | 251 | |
| 252 | - $url =''; | |
| 252 | + $url = ''; | |
| 253 | 253 |          try { | 
| 254 | 254 | $orderClient = new \Pagantis\OrdersApiClient\Client( | 
| 255 | 255 | $pagantisPublicKey, | 
| @@ -260,12 +260,12 @@ discard block | ||
| 260 | 260 |              if ($order instanceof \Pagantis\OrdersApiClient\Model\Order) { | 
| 261 | 261 | $url = $order->getActionUrls()->getForm(); | 
| 262 | 262 | $orderId = $order->getId(); | 
| 263 | - $sql = "INSERT INTO `" . _DB_PREFIX_ . "pagantis_order` (`id`, `order_id`) | |
| 263 | + $sql = "INSERT INTO `"._DB_PREFIX_."pagantis_order` (`id`, `order_id`) | |
| 264 | 264 |                       VALUES ('$cart->id','$orderId')  | 
| 265 | 265 | ON DUPLICATE KEY UPDATE `order_id` = '$orderId'"; | 
| 266 | 266 | $result = Db::getInstance()->execute($sql); | 
| 267 | 267 |                  if (!$result) { | 
| 268 | -                    throw new UnknownException('Unable to save pagantis-order-id in database: '. $sql); | |
| 268 | +                    throw new UnknownException('Unable to save pagantis-order-id in database: '.$sql); | |
| 269 | 269 | } | 
| 270 | 270 |              } else { | 
| 271 | 271 | throw new OrderNotFoundException(); | 
| @@ -393,13 +393,13 @@ discard block | ||
| 393 | 393 | */ | 
| 394 | 394 | private function getUserLanguage($shippingAddress = null, $billingAddress = null) | 
| 395 | 395 |      { | 
| 396 | -        $allowedCountries    = unserialize(Pagantis::getExtraConfig('PAGANTIS_ALLOWED_COUNTRIES')); | |
| 396 | +        $allowedCountries = unserialize(Pagantis::getExtraConfig('PAGANTIS_ALLOWED_COUNTRIES')); | |
| 397 | 397 | $lang = Language::getLanguage($this->context->language->id); | 
| 398 | 398 |          $langArray = explode("-", $lang['language_code']); | 
| 399 | 399 |          if (count($langArray) != 2 && isset($lang['locale'])) { | 
| 400 | 400 |              $langArray = explode("-", $lang['locale']); | 
| 401 | 401 | } | 
| 402 | - $language = Tools::strtoupper($langArray[count($langArray)-1]); | |
| 402 | + $language = Tools::strtoupper($langArray[count($langArray) - 1]); | |
| 403 | 403 | // Prevent null language detection | 
| 404 | 404 |          if (in_array(Tools::strtolower($language), $allowedCountries)) { | 
| 405 | 405 | return $language; | 
| @@ -213,7 +213,7 @@ discard block | ||
| 213 | 213 | private function getPagantisOrderId() | 
| 214 | 214 |      { | 
| 215 | 215 |          try { | 
| 216 | - $this->pagantisOrderId= Db::getInstance()->getValue( | |
| 216 | + $this->pagantisOrderId = Db::getInstance()->getValue( | |
| 217 | 217 | 'select order_id from '._DB_PREFIX_.'pagantis_order where id = '.$this->merchantOrderId | 
| 218 | 218 | ); | 
| 219 | 219 | |
| @@ -275,20 +275,20 @@ discard block | ||
| 275 | 275 |          $merchantAmount = explode('.', explode(',', $merchantAmount)[0])[0]; | 
| 276 | 276 |          if ($totalAmount != $merchantAmount) { | 
| 277 | 277 |              try { | 
| 278 | - $psTotalAmount = substr_replace($merchantAmount, '.', (Tools::strlen($merchantAmount) -2), 0); | |
| 278 | + $psTotalAmount = substr_replace($merchantAmount, '.', (Tools::strlen($merchantAmount) - 2), 0); | |
| 279 | 279 | |
| 280 | 280 | $pgTotalAmountInCents = (string) $this->pagantisOrder->getShoppingCart()->getTotalAmount(); | 
| 281 | 281 | $pgTotalAmount = substr_replace( | 
| 282 | 282 | $pgTotalAmountInCents, | 
| 283 | 283 | '.', | 
| 284 | - (Tools::strlen($pgTotalAmountInCents) -2), | |
| 284 | + (Tools::strlen($pgTotalAmountInCents) - 2), | |
| 285 | 285 | 0 | 
| 286 | 286 | ); | 
| 287 | 287 | |
| 288 | - $this->amountMismatchError = '. Amount mismatch in PrestaShop Order #'. $this->merchantOrderId . | |
| 289 | - ' compared with Pagantis Order: ' . $this->pagantisOrderId . | |
| 290 | - '. The order in PrestaShop has an amount of ' . $psTotalAmount . ' and in Pagantis ' . | |
| 291 | - $pgTotalAmount . ' PLEASE REVIEW THE ORDER'; | |
| 288 | + $this->amountMismatchError = '. Amount mismatch in PrestaShop Order #'.$this->merchantOrderId. | |
| 289 | + ' compared with Pagantis Order: '.$this->pagantisOrderId. | |
| 290 | + '. The order in PrestaShop has an amount of '.$psTotalAmount.' and in Pagantis '. | |
| 291 | + $pgTotalAmount.' PLEASE REVIEW THE ORDER'; | |
| 292 | 292 | $this->saveLog(array( | 
| 293 | 293 | 'message' => $this->amountMismatchError | 
| 294 | 294 | )); | 
| @@ -308,21 +308,21 @@ discard block | ||
| 308 | 308 |          try { | 
| 309 | 309 |              if ($this->merchantOrder->orderExists() !== false) { | 
| 310 | 310 |                  throw new WrongStatusException('PS->orderExists() cart_id = ' | 
| 311 | - . $this->merchantOrderId . ' pagantis_id = ' | |
| 312 | - . $this->pagantisOrderId . '): already_processed'); | |
| 311 | + . $this->merchantOrderId.' pagantis_id = ' | |
| 312 | + . $this->pagantisOrderId.'): already_processed'); | |
| 313 | 313 | } | 
| 314 | 314 | |
| 315 | 315 | // Double check | 
| 316 | - $tableName = _DB_PREFIX_ . 'pagantis_order'; | |
| 316 | + $tableName = _DB_PREFIX_.'pagantis_order'; | |
| 317 | 317 | $fieldName = 'ps_order_id'; | 
| 318 | -            $sql = ('select ' . $fieldName . ' from `' . $tableName . '` where `id` = ' . $this->merchantOrderId | |
| 319 | - . ' and `order_id` = \'' . $this->pagantisOrderId . '\'' | |
| 320 | - . ' and `' . $fieldName . '` is not null'); | |
| 318 | +            $sql = ('select '.$fieldName.' from `'.$tableName.'` where `id` = '.$this->merchantOrderId | |
| 319 | + . ' and `order_id` = \''.$this->pagantisOrderId.'\'' | |
| 320 | + . ' and `'.$fieldName.'` is not null'); | |
| 321 | 321 | $results = Db::getInstance()->ExecuteS($sql); | 
| 322 | 322 |              if (is_array($results) && count($results) === 1) { | 
| 323 | -                throw new WrongStatusException('PS->record found in ' . $tableName | |
| 324 | - . ' (cart_id = ' . $this->merchantOrderId . ' pagantis_id = ' | |
| 325 | - . $this->pagantisOrderId . '): already_processed'); | |
| 323 | +                throw new WrongStatusException('PS->record found in '.$tableName | |
| 324 | + . ' (cart_id = '.$this->merchantOrderId.' pagantis_id = ' | |
| 325 | + . $this->pagantisOrderId.'): already_processed'); | |
| 326 | 326 | } | 
| 327 | 327 |          } catch (\Exception $exception) { | 
| 328 | 328 | throw new UnknownException($exception->getMessage()); | 
| @@ -351,9 +351,9 @@ discard block | ||
| 351 | 351 |                  Configuration::get('PS_OS_PAYMENT'), | 
| 352 | 352 | $this->merchantOrder->getOrderTotal(true), | 
| 353 | 353 | $this->module->displayName, | 
| 354 | - 'pagantisOrderId: ' . $this->pagantisOrder->getId() . ' ' . | |
| 355 | - 'pagantisOrderStatus: '. $this->pagantisOrder->getStatus() . | |
| 356 | - $this->amountMismatchError . | |
| 354 | + 'pagantisOrderId: '.$this->pagantisOrder->getId().' '. | |
| 355 | + 'pagantisOrderStatus: '.$this->pagantisOrder->getStatus(). | |
| 356 | + $this->amountMismatchError. | |
| 357 | 357 | $metadataInfo, | 
| 358 | 358 |                  array('transaction_id' => $this->pagantisOrderId), | 
| 359 | 359 | null, | 
| @@ -367,7 +367,7 @@ discard block | ||
| 367 | 367 | Db::getInstance()->update( | 
| 368 | 368 | 'pagantis_order', | 
| 369 | 369 |                  array('ps_order_id' => $this->module->currentOrder), | 
| 370 | - 'id = \''. $this->merchantOrderId . '\' and order_id = \'' . $this->pagantisOrderId . '\'' | |
| 370 | + 'id = \''.$this->merchantOrderId.'\' and order_id = \''.$this->pagantisOrderId.'\'' | |
| 371 | 371 | ); | 
| 372 | 372 |          } catch (\Exception $exception) { | 
| 373 | 373 | // Do nothing | 
| @@ -385,9 +385,9 @@ discard block | ||
| 385 | 385 | $this->orderClient->confirmOrder($this->pagantisOrderId); | 
| 386 | 386 |              try { | 
| 387 | 387 | $mode = ($_SERVER['REQUEST_METHOD'] == 'POST') ? 'NOTIFICATION' : 'REDIRECTION'; | 
| 388 | - $message = 'Order CONFIRMED. The order was confirmed by a ' . $mode . | |
| 389 | - '. Pagantis OrderId=' . $this->pagantisOrderId . | |
| 390 | - '. Prestashop OrderId=' . $this->module->currentOrder; | |
| 388 | + $message = 'Order CONFIRMED. The order was confirmed by a '.$mode. | |
| 389 | + '. Pagantis OrderId='.$this->pagantisOrderId. | |
| 390 | + '. Prestashop OrderId='.$this->module->currentOrder; | |
| 391 | 391 |                  $this->saveLog(array('message' => $message)); | 
| 392 | 392 |              } catch (\Exception $exception) { | 
| 393 | 393 | // Do nothing | 
| @@ -405,15 +405,15 @@ discard block | ||
| 405 | 405 | public function rollbackMerchantOrder() | 
| 406 | 406 |      { | 
| 407 | 407 |          try { | 
| 408 | - $message = 'Roolback method: ' . | |
| 409 | - '. Pagantis OrderId=' . $this->pagantisOrderId . | |
| 410 | - '. Prestashop CartId=' . $this->merchantOrderId; | |
| 408 | + $message = 'Roolback method: '. | |
| 409 | + '. Pagantis OrderId='.$this->pagantisOrderId. | |
| 410 | + '. Prestashop CartId='.$this->merchantOrderId; | |
| 411 | 411 |              if ($this->module->currentOrder) { | 
| 412 | 412 | $objOrder = new Order($this->module->currentOrder); | 
| 413 | 413 | $history = new OrderHistory(); | 
| 414 | - $history->id_order = (int)$objOrder->id; | |
| 415 | - $history->changeIdOrderState(8, (int)($objOrder->id)); | |
| 416 | - $message .= ' Prestashop OrderId=' . $this->merchantOrderId; | |
| 414 | + $history->id_order = (int) $objOrder->id; | |
| 415 | + $history->changeIdOrderState(8, (int) ($objOrder->id)); | |
| 416 | + $message .= ' Prestashop OrderId='.$this->merchantOrderId; | |
| 417 | 417 | } | 
| 418 | 418 |              $this->saveLog(array('message' => $message)); | 
| 419 | 419 |          } catch (\Exception $exception) { | 
| @@ -446,10 +446,10 @@ discard block | ||
| 446 | 446 | ); | 
| 447 | 447 | $resultSeconds = Db::getInstance()->getValue($query); | 
| 448 | 448 | $restSeconds = isset($resultSeconds) ? ($resultSeconds) : 0; | 
| 449 | - $secondsToExpire = ($restSeconds>self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds; | |
| 449 | + $secondsToExpire = ($restSeconds > self::CONCURRENCY_TIMEOUT) ? self::CONCURRENCY_TIMEOUT : $restSeconds; | |
| 450 | 450 | |
| 451 | 451 | $logMessage = sprintf( | 
| 452 | - "Redirect concurrency, User have to wait %s seconds, default seconds %s. CartId=" . $orderId, | |
| 452 | + "Redirect concurrency, User have to wait %s seconds, default seconds %s. CartId=".$orderId, | |
| 453 | 453 | $secondsToExpire, | 
| 454 | 454 | self::CONCURRENCY_TIMEOUT, | 
| 455 | 455 | $restSeconds | 
| @@ -458,7 +458,7 @@ discard block | ||
| 458 | 458 | $this->saveLog(array( | 
| 459 | 459 | 'message' => $logMessage | 
| 460 | 460 | )); | 
| 461 | - sleep($secondsToExpire+1); | |
| 461 | + sleep($secondsToExpire + 1); | |
| 462 | 462 | // After waiting...user continue the confirmation, hoping that previous call have finished. | 
| 463 | 463 | return true; | 
| 464 | 464 | } | 
| @@ -478,11 +478,11 @@ discard block | ||
| 478 | 478 |              if (is_null($orderId)) { | 
| 479 | 479 | Db::getInstance()->delete( | 
| 480 | 480 | 'pagantis_cart_process', | 
| 481 | - 'timestamp < ' . (time() - self::CONCURRENCY_TIMEOUT) | |
| 481 | + 'timestamp < '.(time() - self::CONCURRENCY_TIMEOUT) | |
| 482 | 482 | ); | 
| 483 | 483 | return; | 
| 484 | 484 | } | 
| 485 | -            Db::getInstance()->delete('pagantis_cart_process', 'id = \'' . $orderId . '\''); | |
| 485 | +            Db::getInstance()->delete('pagantis_cart_process', 'id = \''.$orderId.'\''); | |
| 486 | 486 |          } catch (\Exception $exception) { | 
| 487 | 487 | throw new ConcurrencyException(); | 
| 488 | 488 | } | 
| @@ -504,8 +504,8 @@ discard block | ||
| 504 | 504 | $data = array( | 
| 505 | 505 | 'merchantOrderId' => $this->merchantOrderId, | 
| 506 | 506 | 'pagantisOrderId' => $this->pagantisOrderId, | 
| 507 | - 'message' => ($exception)? $exception->getMessage() : 'Unable to get Exception message', | |
| 508 | - 'statusCode' => ($exception)? $exception->getCode() : 'Unable to get Exception statusCode', | |
| 507 | + 'message' => ($exception) ? $exception->getMessage() : 'Unable to get Exception message', | |
| 508 | + 'statusCode' => ($exception) ? $exception->getCode() : 'Unable to get Exception statusCode', | |
| 509 | 509 | 'method' => $method, | 
| 510 | 510 | 'file' => __FILE__, | 
| 511 | 511 | 'line' => $line, | 
| @@ -530,9 +530,9 @@ discard block | ||
| 530 | 530 | 'id_cart' => $this->merchantOrderId, | 
| 531 | 531 | 'key' => $this->config['secureKey'], | 
| 532 | 532 | 'id_module' => $this->module->id, | 
| 533 | - 'id_order' => ($this->pagantisOrder)?$this->pagantisOrder->getId(): null, | |
| 533 | + 'id_order' => ($this->pagantisOrder) ? $this->pagantisOrder->getId() : null, | |
| 534 | 534 | ); | 
| 535 | - $url = ($error)? $this->config['urlKO'] : $this->config['urlOK']; | |
| 535 | + $url = ($error) ? $this->config['urlKO'] : $this->config['urlOK']; | |
| 536 | 536 | return $this->redirect($url, $parameters); | 
| 537 | 537 | } | 
| 538 | 538 | } | 
| 539 | 539 | \ No newline at end of file |