Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail controller recognition #213

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading