Skip to content

Commit

Permalink
Merge pull request #213 from Invertus/SL-219/iframe-fail-redirect
Browse files Browse the repository at this point in the history
Fail controller recognition
  • Loading branch information
MarijusCoding authored Oct 23, 2024
2 parents 974e8fa + 2a6987a commit a4d3799
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 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 @@ -86,7 +89,7 @@ public function postProcess()
]);

$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 @@ -376,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 a4d3799

Please sign in to comment.