Files
OpenCart4/catalog/controller/startup/payanyway.php
T

56 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace Opencart\Catalog\Controller\Extension\PayAnyWay\Startup;
require_once DIR_EXTENSION . '/payanyway/catalog/library/payanyway/traits/payanyway.php';
/**
* @package Opencart\Catalog\Controller\Extension\PayAnyWay\Startup
*/
class PayAnyWay extends \Opencart\System\Engine\Controller
{
use \Opencart\Catalog\Library\Extension\PayAnyWay\Traits\PayAnyWay;
public const CALLBACK_ROUTE = 'extension/payanyway/payment/callback';
// checkout/confirm.confirm (4.0.2+) и checkout/confirm|confirm (4.0.0–4.0.1); не checkout/success.
private const CHECKOUT_ROUTE_PATTERN = '/^checkout\/(checkout|confirm)([.|]|$)/';
public function index(): void
{
if (!isset($this->request->get['route'])) {
if (($this->request->post['route'] ?? null) === self::CALLBACK_ROUTE) {
$this->request->get['route'] = self::CALLBACK_ROUTE;
}
return;
}
if (is_string($this->request->get['route']) && preg_match(self::CHECKOUT_ROUTE_PATTERN, $this->request->get['route'])) {
$this->releaseClosedSessionOrder();
}
}
private function releaseClosedSessionOrder(): void
{
$this->loadOrder($this->getOrderIdFromSession());
if (([] === $this->orderInfo) || !$this->isPaidWithModule()) {
return;
}
if (0 === (int)$this->orderInfo['order_status_id']) {
unset($this->session->data['order_id']);
return;
}
$this->initializeModule();
$orderStatusId = (int)($this->orderInfo['order_status_id'] ?? 0);
if (($this->successOrderStatusId > 0) && !$this->isAwaitingPayment($orderStatusId)) {
unset($this->session->data['order_id']);
}
}
}