diff --git a/controllers/front/notify.php b/controllers/front/notify.php index 5ef08d56..ffb79d75 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -118,7 +118,7 @@ private function assertTransaction($cartId) { /** @var SaferPayTransactionAssertion $transactionAssert */ $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); - $assertionResponse = $transactionAssert->assert(Order::getOrderByCartId($cartId)); + $assertionResponse = $transactionAssert->assert(Order::getOrderByCartId($cartId), true); return $assertionResponse; } diff --git a/controllers/front/return.php b/controllers/front/return.php index 5f4ea003..8c8b0dce 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -60,18 +60,56 @@ public function postProcess() ])); } - Tools::redirect($this->context->link->getModuleLink( - $this->module->name, - $this->getSuccessControllerName($isBusinessLicence, $fieldToken), - [ - 'cartId' => $cartId, - 'orderId' => $orderId, - 'moduleId' => $moduleId, - 'secureKey' => $secureKey, - 'selectedCard' => $selectedCard - ], - true - )); + try { + $this->assertTransaction($orderId); + + Tools::redirect($this->context->link->getModuleLink( + $this->module->name, + $this->getSuccessControllerName($isBusinessLicence, $fieldToken), + [ + 'cartId' => $cartId, + 'orderId' => $orderId, + 'moduleId' => $moduleId, + 'secureKey' => $secureKey, + 'selectedCard' => $selectedCard, + ], + true + )); + + } catch (Exception $e) { + PrestaShopLogger::addLog( + sprintf( + 'Failed to assert transaction. Message: %s. File name: %s', + $e->getMessage(), + self::FILENAME + ) + ); + + Tools::redirect($this->context->link->getModuleLink( + $this->module->name, + 'failValidation', + [ + 'cartId' => $cartId, + 'orderId' => $orderId, + 'secureKey' => $secureKey, + ], + true + )); + } + } + + /** + * @param $cartId + * @return AssertBody + * @throws Exception + */ + private function assertTransaction($orderId) + { + /** @var SaferPayTransactionAssertion $transactionAssert */ + $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); + $assertionResponse = $transactionAssert->assert($orderId, false); + + return $assertionResponse; } private function getSuccessControllerName($isBusinessLicence, $fieldToken) @@ -88,4 +126,4 @@ private function getSuccessControllerName($isBusinessLicence, $fieldToken) return $successController; } -} \ No newline at end of file +} diff --git a/controllers/front/success.php b/controllers/front/success.php index ceba7a6e..39e56e93 100755 --- a/controllers/front/success.php +++ b/controllers/front/success.php @@ -21,9 +21,7 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Controller\AbstractSaferPayController; -use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion; class SaferPayOfficialSuccessModuleFrontController extends AbstractSaferPayController { @@ -51,49 +49,16 @@ public function postProcess() Tools::redirect($redirectLink); } - try { - // TODO The shopping cart should be locked to prevent problems with the notify.php process running at the same time. - // $this->assertTransaction($orderId); - - Tools::redirect($this->context->link->getPageLink( - 'order-confirmation', - true, - null, - [ - 'id_cart' => $cartId, - 'id_module' => $moduleId, - 'id_order' => $orderId, - 'key' => $secureKey, - ] - )); - } catch (Exception $e) { - PrestaShopLogger::addLog( - sprintf( - 'Failed to assert transaction. Message: %s. File name: %s', - $e->getMessage(), - self::FILENAME - ) - ); - - Tools::redirect($this->context->link->getModuleLink( - $this->module->name, - 'failValidation', - [ - 'cartId' => $cartId, - 'orderId' => $orderId, - 'secureKey' => $secureKey - ], - true - )); - } - } - - private function assertTransaction($orderId) - { - /** @var SaferPayTransactionAssertion $transactionAssert */ - $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); - $assertionResponse = $transactionAssert->assert($orderId); - - return $assertionResponse; + Tools::redirect($this->context->link->getPageLink( + 'order-confirmation', + true, + null, + [ + 'id_cart' => $cartId, + 'id_module' => $moduleId, + 'id_order' => $orderId, + 'key' => $secureKey, + ] + )); } } diff --git a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php index e1eca4a3..9fe8804c 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php @@ -71,7 +71,7 @@ public function __construct( * @return AssertBody * @throws \Exception */ - public function assert($orderId) + public function assert($orderId, $changeOrderStatus) { $saferPayOrder = $this->getSaferPayOrder($orderId); $order = new Order($orderId); @@ -87,7 +87,9 @@ public function assert($orderId) $saferPayOrder->transaction_id = $assertBody->getTransaction()->getId(); $saferPayOrder->update(); - $this->orderStatusService->assert($order, $assertBody->getTransaction()->getStatus()); + if ($changeOrderStatus) { + $this->orderStatusService->assert($order, $assertBody->getTransaction()->getStatus()); + } return $assertBody; }