<?php

namespace Autogedal\Extend\Plugin\Netopia\Netcard\Controller\Payment;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\Result\RedirectFactory;

class Success
{
    public function __construct(
        private readonly ScopeConfigInterface $scopeConfig,
        private readonly RedirectFactory $resultRedirectFactory
    ) {

    }

    /**
     * @param \Netopia\Netcard\Controller\Payment\Success $subject
     * @param \Closure $proceed
     *
     * @return mixed|null
     */
    public function aroundExecute(\Netopia\Netcard\Controller\Payment\Success $subject, \Closure $proceed): mixed
    {
        $orderId = $subject->getRequest()->getParam('orderId');
        if (!$orderId) {
            return $this->resultRedirectFactory->create()->setPath('/');
        }
        return $proceed();
    }
}