diff --git a/controllers/admin/AdminSaferPayOfficialSettingsController.php b/controllers/admin/AdminSaferPayOfficialSettingsController.php index fdd33062d..3b310c5cb 100755 --- a/controllers/admin/AdminSaferPayOfficialSettingsController.php +++ b/controllers/admin/AdminSaferPayOfficialSettingsController.php @@ -400,7 +400,7 @@ private function displayConfigurationSettings() 'title' => $this->module->l('Description', self::FILE_NAME), 'type' => 'text', 'desc' => 'This description is visible in payment page also in payment confirmation email', - 'class' => 'fixed-width-xxl' + 'class' => 'fixed-width-xxl', ], ], 'buttons' => [ diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index f221d68ec..34a66a144 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -71,7 +71,7 @@ protected function processGetStatus() if (!$saferPayOrder->id || $saferPayOrder->canceled) { $this->ajaxDie(json_encode([ 'isFinished' => true, - 'href' => $this->getFailControllerLink($cartId, $secureKey, $moduleId) + 'href' => $this->getFailControllerLink($cartId, $secureKey, $moduleId), ])); } @@ -88,7 +88,7 @@ protected function processGetStatus() 'secureKey' => $secureKey, 'selectedCard' => $selectedCard, ] - ) + ), ])); } diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index 7fb347097..262d30a3c 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -98,7 +98,6 @@ public function initContent() ); $redirectUrl = $checkoutController->execute($checkoutData); - } catch (\Exception $exception) { $redirectUrl = $this->context->link->getModuleLink( $this->module->name, diff --git a/controllers/front/notify.php b/controllers/front/notify.php index d9fcaf5ad..0155c5210 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -201,7 +201,8 @@ public function postProcess() die($this->module->l('Success', self::FILENAME)); } - private function assertTransaction($cartId) { + private function assertTransaction($cartId) + { /** @var SaferPayTransactionAssertion $transactionAssert */ $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); @@ -217,10 +218,9 @@ private function getOrderId($cartId) { if (method_exists('Order', 'getIdByCartId')) { return Order::getIdByCartId($cartId); - } else { - // For PrestaShop 1.6 use the alternative method - return Order::getOrderByCartId($cartId); } + // For PrestaShop 1.6 use the alternative method + return Order::getOrderByCartId($cartId); } protected function displayMaintenancePage() diff --git a/controllers/front/return.php b/controllers/front/return.php index 1ce79fd00..48cb8db7f 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -24,9 +24,11 @@ use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; +use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\SaferPay\Processor\CheckoutProcessor; use Invertus\SaferPay\Service\SaferPayOrderStatusService; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; @@ -43,19 +45,96 @@ public function postProcess() { $cartId = (int) Tools::getValue('cartId'); $order = new Order($this->getOrderId($cartId)); + $secureKey = Tools::getValue('secureKey'); + $cart = new Cart($cartId); - if (!$order->id) { - return; + if (!Validate::isLoadedObject($cart)) { + $this->warning[] = $this->module->l('An unknown error error occurred. Please contact support', self::FILENAME); + $this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail')); } + if ($cart->secure_key !== $secureKey) { + $this->warning[] = $this->module->l('Error. Insecure cart', self::FILENAME); + $this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail')); + } + + /** @var SaferPayTransactionAssertion $transactionAssert */ + $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); + try { - /** @var SaferPayTransactionAssertion $transactionAssert */ - $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); - $transactionResponse = $transactionAssert->assert($cartId, false); + $assertResponseBody = $transactionAssert->assert($cartId); + $transactionStatus = $assertResponseBody->getTransaction()->getStatus(); + } catch (Exception $e) { + \PrestaShopLogger::addLog($e->getMessage()); + $this->warning[] = $this->module->l('An error occurred. Please contact support', self::FILENAME); + $this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail')); + } + + /** + * NOTE: This flow is for hosted iframe payment method + */ + if (Tools::getValue('isBusinessLicence')) { + try { + /** @var CheckoutProcessor $checkoutProcessor * */ + $checkoutProcessor = $this->module->getService(CheckoutProcessor::class); + + $checkoutData = CheckoutData::create( + (int) $cartId, + $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(), + (int) Configuration::get(SaferPayConfig::IS_BUSINESS_LICENCE) + ); + $checkoutData->setOrderStatus($transactionStatus); + + $checkoutProcessor->run($checkoutData); + + $orderId = $this->getOrderId($cartId); + + $order = new Order($orderId); + if (!$assertResponseBody->getLiability()->getLiabilityShift() && + in_array($order->payment, SaferPayConfig::SUPPORTED_3DS_PAYMENT_METHODS) && + (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D) === SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D_CANCEL + ) { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + $orderStatusService->cancel($order); + } + + //NOTE to get latest information possible and not override new information. + $paymentMethod = $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod();// if payment does not support order capture, it means it always auto-captures it (at least with accountToAccount payment), + + // so in this case if status comes back "captured" we just update the order state accordingly + if (!SaferPayConfig::supportsOrderCapture($paymentMethod) && + $transactionStatus === TransactionStatus::CAPTURED + ) { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + $orderStatusService->setComplete($order); + + return; + } + + if (SaferPayConfig::supportsOrderCapture($paymentMethod) && + (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR) === SaferPayConfig::DEFAULT_PAYMENT_BEHAVIOR_CAPTURE && + $transactionStatus !== TransactionStatus::CAPTURED + ) { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + $orderStatusService->capture($order); + + return; + } + } catch (Exception $e) { + \PrestaShopLogger::addLog($e->getMessage()); + $this->warning[] = $this->module->l('An error occurred. Please contact support', self::FILENAME); + $this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail')); + } + } + + try { /** @var SaferPayOrderStatusService $orderStatusService */ $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); - if ($transactionResponse->getTransaction()->getStatus() === TransactionStatus::PENDING) { + if ($assertResponseBody->getTransaction()->getStatus() === TransactionStatus::PENDING) { $orderStatusService->setPending($order); } } catch (SaferPayApiException $e) { @@ -184,9 +263,27 @@ private function getOrderId($cartId) { if (method_exists('Order', 'getIdByCartId')) { return Order::getIdByCartId($cartId); - } else { - // For PrestaShop 1.6 use the alternative method - return Order::getOrderByCartId($cartId); } + // For PrestaShop 1.6 use the alternative method + return Order::getOrderByCartId($cartId); + } + + /** + * @param string $controllerName + * + * @return string + */ + private function getRedirectionToControllerUrl($controllerName) + { + return $this->context->link->getModuleLink( + $this->module->name, + $controllerName, + [ + 'cartId' => $this->context->cart->id, + 'orderId' => Order::getOrderByCartId($this->context->cart->id), + 'secureKey' => $this->context->cart->secure_key, + 'moduleId' => $this->module->id, + ] + ); } } diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 9998633d0..637947820 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -21,12 +21,9 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; if (!defined('_PS_VERSION_')) { exit; diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index a7ce3b5dd..b74503630 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -21,13 +21,9 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\SaferPay\Exception\Api\SaferPayApiException; -use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; if (!defined('_PS_VERSION_')) { exit; diff --git a/saferpayofficial.php b/saferpayofficial.php index ef9266d12..9892ed2c4 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -216,7 +216,7 @@ public function hookPaymentOptions($params) foreach ($paymentMethods as $paymentMethod) { $paymentMethod['paymentMethod'] = str_replace(' ', '', $paymentMethod['paymentMethod']); - if(!in_array($paymentMethod['paymentMethod'], $activePaymentMethods)) { + if (!in_array($paymentMethod['paymentMethod'], $activePaymentMethods)) { continue; } @@ -689,8 +689,8 @@ private function displayInAdminOrderPage(array $params) ); } else { $action = $this->context->link->getAdminLink( - self::ADMIN_ORDER_CONTROLLER - ) . '&id_order=' . (int) $orderId; + self::ADMIN_ORDER_CONTROLLER + ) . '&id_order=' . (int) $orderId; } $assertId = $orderRepo->getAssertIdBySaferPayOrderId($saferPayOrderId); diff --git a/src/Api/Request/AssertService.php b/src/Api/Request/AssertService.php index d1297a41f..fc0d28715 100755 --- a/src/Api/Request/AssertService.php +++ b/src/Api/Request/AssertService.php @@ -29,7 +29,6 @@ use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\EntityBuilder\SaferPayAssertBuilder; use Invertus\SaferPay\Exception\Api\SaferPayApiException; -use Invertus\SaferPay\Exception\Api\TransactionDeclinedException; use Invertus\SaferPay\Service\Response\AssertResponseObjectCreator; use SaferPayOrder; @@ -84,7 +83,7 @@ public function assert(AssertRequest $assertRequest, $saferPayOrderId) // also we call authorize method in some of the success controllers, so if we leave the logic here, // we get an error with TRANSACTION_IN_WRONG_STATE if ($saferPayOrder->is_transaction) { - $assertApi = self::ASSERT_API_TRANSACTION; + $assertApi = self::ASSERT_API_TRANSACTION; } try { diff --git a/src/Controller/AbstractSaferPayController.php b/src/Controller/AbstractSaferPayController.php index cac8b4a27..f6bfc003f 100755 --- a/src/Controller/AbstractSaferPayController.php +++ b/src/Controller/AbstractSaferPayController.php @@ -82,7 +82,6 @@ protected function applyLock($resource) $this->lock->create($resource); if (!$this->lock->acquire()) { - if (!SaferPayConfig::isVersion17()) { return http_response_code(409); } diff --git a/src/Controller/Front/index.php b/src/Controller/Front/index.php index 7487f261a..6b7787222 100644 --- a/src/Controller/Front/index.php +++ b/src/Controller/Front/index.php @@ -21,7 +21,7 @@ *@license SIX Payment Services */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); diff --git a/src/Core/Order/Action/UpdateOrderStatusAction.php b/src/Core/Order/Action/UpdateOrderStatusAction.php index 000ce93b6..983c5fcfc 100644 --- a/src/Core/Order/Action/UpdateOrderStatusAction.php +++ b/src/Core/Order/Action/UpdateOrderStatusAction.php @@ -60,6 +60,5 @@ public function run($orderId, $orderStatusId) } catch (\Exception $exception) { throw CouldNotChangeOrderStatus::unknownError(); } - } } diff --git a/src/Core/Payment/DTO/CheckoutData.php b/src/Core/Payment/DTO/CheckoutData.php index 7a48165d4..a5cf63369 100644 --- a/src/Core/Payment/DTO/CheckoutData.php +++ b/src/Core/Payment/DTO/CheckoutData.php @@ -44,15 +44,14 @@ class CheckoutData private $status; public function __construct( - $cartId, - $paymentMethod, - $isBusinessLicense, - $selectedCard = -1, - $fieldToken = null, - $successController = null, - $isTransaction = false - ) - { + $cartId, + $paymentMethod, + $isBusinessLicense, + $selectedCard = -1, + $fieldToken = null, + $successController = null, + $isTransaction = false + ) { $this->cartId = $cartId; $this->paymentMethod = $paymentMethod; $this->isBusinessLicense = $isBusinessLicense; @@ -65,15 +64,14 @@ public function __construct( } public static function create( - $cartId, - $paymentMethod, - $isBusinessLicense, - $selectedCard = -1, - $fieldToken = null, - $successController = null, - $isTransaction = false - ) - { + $cartId, + $paymentMethod, + $isBusinessLicense, + $selectedCard = -1, + $fieldToken = null, + $successController = null, + $isTransaction = false + ) { return new self( $cartId, $paymentMethod, diff --git a/src/DTO/Request/Initialize/InitializeRequest.php b/src/DTO/Request/Initialize/InitializeRequest.php index 4bf07ddc9..ec5ae506a 100755 --- a/src/DTO/Request/Initialize/InitializeRequest.php +++ b/src/DTO/Request/Initialize/InitializeRequest.php @@ -222,11 +222,14 @@ public function getAsArray() 'AddressSource' => $this->deliveryAddressForm->getAddressSource(), 'MandatoryFields' => $this->deliveryAddressForm->getMandatoryFields(), ], - 'CardForm' => [ - 'HolderName' => SaferPayConfig::SAFERPAY_CARDFORM_HOLDERNAME_REQUIRENCE, - ], ]; + if ($this->getPaymentMeansField() === []) { + $return['CardForm'] = [ + 'HolderName' => SaferPayConfig::SAFERPAY_CARDFORM_HOLDERNAME_REQUIRENCE, + ]; + } + if ($this->notification !== null) { $return['Notification'] = [ 'MerchantEmails' => [$this->notification->getMerchantEmail()], diff --git a/src/Exception/CouldNotProcessCheckout.php b/src/Exception/CouldNotProcessCheckout.php index b8b19281b..e495daa48 100644 --- a/src/Exception/CouldNotProcessCheckout.php +++ b/src/Exception/CouldNotProcessCheckout.php @@ -75,4 +75,4 @@ public static function failedToCreateSaferPayOrder($cartId) ] ); } -} \ No newline at end of file +} diff --git a/src/Exception/SaferPayException.php b/src/Exception/SaferPayException.php index 419067513..851bd2577 100644 --- a/src/Exception/SaferPayException.php +++ b/src/Exception/SaferPayException.php @@ -35,8 +35,7 @@ final public function __construct( $internalMessage, $code, array $context = [] - ) - { + ) { parent::__construct($internalMessage, $code); $this->context = $context; } @@ -53,4 +52,4 @@ public static function unknownError() ExceptionCode::UNKNOWN_ERROR ); } -} \ No newline at end of file +} diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index 41826f577..62405046c 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -40,7 +40,6 @@ use Order; use PrestaShopException; use SaferPayOrder; -use Validate; class CheckoutProcessor { @@ -68,7 +67,8 @@ public function __construct( $this->saferPayOrderRepository = $saferPayOrderRepository; } - public function run(CheckoutData $data) { + public function run(CheckoutData $data) + { $cart = new Cart($data->getCartId()); if (!$cart) { @@ -217,9 +217,8 @@ private function getOrder($cartId) { if (method_exists('Order', 'getIdByCartId')) { return new Order(Order::getIdByCartId($cartId)); - } else { - // For PrestaShop 1.6 use the alternative method - return new Order(Order::getOrderByCartId($cartId)); } + // For PrestaShop 1.6 use the alternative method + return new Order(Order::getOrderByCartId($cartId)); } } diff --git a/src/Processor/index.php b/src/Processor/index.php index 7487f261a..6b7787222 100644 --- a/src/Processor/index.php +++ b/src/Processor/index.php @@ -21,7 +21,7 @@ *@license SIX Payment Services */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); diff --git a/src/Service/Request/InitializeRequestObjectCreator.php b/src/Service/Request/InitializeRequestObjectCreator.php index 0ca1e5e47..906cd5aa4 100755 --- a/src/Service/Request/InitializeRequestObjectCreator.php +++ b/src/Service/Request/InitializeRequestObjectCreator.php @@ -27,10 +27,8 @@ use Configuration; use Customer; use Invertus\SaferPay\Config\SaferPayConfig; -use Invertus\SaferPay\DTO\Request\RequestHeader; use Invertus\SaferPay\DTO\Request\Initialize\InitializeRequest; use Invertus\SaferPay\DTO\Request\Payer; -use PrestaShop\PrestaShop\Adapter\Shop\Context; if (!defined('_PS_VERSION_')) { exit; diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index e1cb63005..e4822f7e0 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -34,8 +34,6 @@ use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; use Invertus\SaferPay\Factory\ModuleFactory; use Invertus\SaferPay\Service\Request\InitializeRequestObjectCreator; -use Invertus\SaferPay\Config\SaferPayConfig; -use Order; use SaferPayOfficial; if (!defined('_PS_VERSION_')) { diff --git a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php index 92c1b2fa6..b79bc3542 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php @@ -30,7 +30,6 @@ use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\Request\AuthorizationRequestObjectCreator; use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Order; use SaferPayOrder; if (!defined('_PS_VERSION_')) { diff --git a/upgrade/install-1.1.8.php b/upgrade/install-1.1.8.php index d52c8914d..636a4cb3d 100644 --- a/upgrade/install-1.1.8.php +++ b/upgrade/install-1.1.8.php @@ -41,4 +41,4 @@ function upgrade_module_1_1_8(SaferPayOfficial $module) $module->registerHook('actionObjectOrderPaymentAddAfter'); return true; -} \ No newline at end of file +} diff --git a/upgrade/install-1.2.2.php b/upgrade/install-1.2.2.php index b0b04cc53..5e3f08fc6 100644 --- a/upgrade/install-1.2.2.php +++ b/upgrade/install-1.2.2.php @@ -35,4 +35,3 @@ function upgrade_module_1_2_2($module) && $module->unregisterHook('actionOrderStatusUpdate') && Configuration::deleteByName('SAFERPAY_SEND_ORDER_CONFIRMATION'); } - diff --git a/views/templates/front/credit_cards.tpl b/views/templates/front/credit_cards.tpl index 9c69534fc..e2631bc97 100755 --- a/views/templates/front/credit_cards.tpl +++ b/views/templates/front/credit_cards.tpl @@ -51,7 +51,7 @@ {foreach $rows as $row} - {$row|escape:'htmlall':'UTF-8' nofilter} + {$row|escape:'htmlall':'UTF-8'|nofilter} {/foreach} diff --git a/views/templates/front/credit_cards_16.tpl b/views/templates/front/credit_cards_16.tpl index 292aa37ef..8065bbfef 100755 --- a/views/templates/front/credit_cards_16.tpl +++ b/views/templates/front/credit_cards_16.tpl @@ -53,7 +53,7 @@ {foreach $rows as $row} - {$row|escape:'htmlall':'UTF-8' nofilter} + {$row|escape:'htmlall':'UTF-8'|nofilter} {/foreach}