Skip to content

Commit

Permalink
Merge branch 'RC/rc-1.2.4' of github.com:Invertus/saferpayofficial in…
Browse files Browse the repository at this point in the history
…to SV-26/opc-compatibility
  • Loading branch information
MarijusCoding committed Oct 23, 2024
2 parents d83f822 + a4d3799 commit 4fa2e88
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions controllers/front/return.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Invertus\SaferPay\Core\Payment\DTO\CheckoutData;
use Invertus\SaferPay\DTO\Response\Assert\AssertBody;
use Invertus\SaferPay\Enum\ControllerName;
use Invertus\SaferPay\Enum\PaymentType;
use Invertus\SaferPay\Exception\Api\SaferPayApiException;
use Invertus\SaferPay\Logger\LoggerInterface;
use Invertus\SaferPay\Processor\CheckoutProcessor;
Expand Down Expand Up @@ -58,14 +59,16 @@ public function postProcess()

$cart = new Cart($cartId);

$failController = $this->getFailController($order);

if (!Validate::isLoadedObject($cart)) {
$this->warning[] = $this->module->l('An unknown error error occurred. Please contact support', self::FILE_NAME);
$this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail'));
$this->redirectWithNotifications($this->getRedirectionToControllerUrl($failController));
}

if ($cart->secure_key !== $secureKey) {
$this->warning[] = $this->module->l('Error. Insecure cart', self::FILE_NAME);
$this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail'));
$this->redirectWithNotifications($this->getRedirectionToControllerUrl($failController));
}

/** @var SaferPayTransactionAssertion $transactionAssert */
Expand All @@ -80,9 +83,13 @@ public function postProcess()
);
$transactionStatus = $assertResponseBody->getTransaction()->getStatus();
} catch (Exception $e) {
\PrestaShopLogger::addLog($e->getMessage());
$logger->error($e->getMessage(), [
'context' => [],
'exceptions' => ExceptionUtility::getExceptions($e),
]);

$this->warning[] = $this->module->l('An error occurred. Please contact support', self::FILE_NAME);
$this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail'));
$this->redirectWithNotifications($this->getRedirectionToControllerUrl($failController));
}

$orderPayment = $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod();
Expand Down Expand Up @@ -372,4 +379,17 @@ private function createAndValidateOrder($assertResponseBody, $transactionStatus,
return;
}
}

private function getFailController($order)
{
/** @var \Invertus\SaferPay\Provider\PaymentTypeProvider $paymentTypeProvider */
$paymentTypeProvider = $this->module->getService(\Invertus\SaferPay\Provider\PaymentTypeProvider::class);
$paymentRedirectType = $paymentTypeProvider->get($order->payment);

if ($paymentRedirectType === PaymentType::IFRAME) {
return ControllerName::FAIL_IFRAME;
}

return ControllerName::FAIL;
}
}

0 comments on commit 4fa2e88

Please sign in to comment.