src/Payum/PayumHipay/Action/AfterCaptureAction.php line 87

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\Payum\PayumHipay\Action;
  12. use Payum\Core\Model\GatewayConfigInterface;
  13. use Payum\Core\Payum;
  14. use Payum\Core\Request\Generic;
  15. use Payum\Core\Request\GetStatusInterface;
  16. use Payum\Core\Security\GenericTokenFactoryInterface;
  17. use Payum\Core\Security\HttpRequestVerifierInterface;
  18. use Payum\Core\Security\TokenInterface;
  19. use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface;
  20. use Sylius\Bundle\PayumBundle\Factory\ResolveNextRouteFactoryInterface;
  21. use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface;
  22. use Sylius\Bundle\ResourceBundle\Controller\ViewHandlerInterface;
  23. use Sylius\Component\Core\Model\OrderInterface;
  24. use Sylius\Component\Core\Model\PaymentInterface;
  25. use Sylius\Component\Core\Model\PaymentMethodInterface;
  26. use Sylius\Component\Order\Repository\OrderRepositoryInterface;
  27. use Sylius\Component\Resource\Metadata\MetadataInterface;
  28. use Symfony\Component\HttpFoundation\RedirectResponse;
  29. use Symfony\Component\HttpFoundation\Request;
  30. use Symfony\Component\HttpFoundation\Response;
  31. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  32. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  33. use Symfony\Component\Routing\RouterInterface;
  34. use Payum\Core\Action\ActionInterface;
  35. use Payum\Core\Request\Capture;
  36. use Symfony\Component\DependencyInjection\ContainerInterface;
  37. use Psr\Log\LoggerInterface;
  38. class AfterCaptureAction implements ActionInterface
  39. {
  40.     private $container;
  41.     public function __construct(
  42.         private Payum $payum,
  43.         private OrderRepositoryInterface $orderRepository,
  44.         private MetadataInterface $orderMetadata,
  45.         private RequestConfigurationFactoryInterface $requestConfigurationFactory,
  46.         private ViewHandlerInterface $viewHandler,
  47.         private RouterInterface $router,
  48.         private GetStatusFactoryInterface $getStatusRequestFactory,
  49.         private ResolveNextRouteFactoryInterface $resolveNextRouteRequestFactory
  50.         private LoggerInterface $logger,
  51.         ContainerInterface $container
  52.     ) {
  53.         $this->container $container;
  54.     }
  55.     private function getHttpRequestVerifier(): HttpRequestVerifierInterface
  56.     {
  57.         return $this->payum->getHttpRequestVerifier();
  58.     }
  59.     public function execute($request)
  60.     {
  61.         dump($request);
  62.         exit();
  63.     }
  64.     /**
  65.      * {@inheritDoc}
  66.      */
  67.     public function supports($request)
  68.     {
  69.         return
  70.             $request instanceof Capture &&
  71.             $request->getModel() instanceof \ArrayAccess;
  72.     }
  73.     public function afterCaptureAction(Request $request): Response {
  74.         
  75.         $configuration $this->requestConfigurationFactory->create($this->orderMetadata$request);
  76.         $token $this->getHttpRequestVerifier()->verify($request);
  77.         $this->logger->debug("token : ".print_r($tokentrue));
  78.         // $this->payLog($token);
  79.         /** @var Generic&GetStatusInterface $status */
  80.         $status $this->getStatusRequestFactory->createNewWithModel($token);
  81.         $this->logger->debug("status : ".print_r($statustrue));
  82.         $this->payum->getGateway($token->getGatewayName())->execute($status);
  83.         $this->logger->debug("status getValue : ".print_r($status->getValue(), true));
  84.         $resolveNextRoute $this->resolveNextRouteRequestFactory->createNewWithModel($status->getFirstModel());
  85.         $this->payum->getGateway($token->getGatewayName())->execute($resolveNextRoute);
  86.         // $this->logger->debug(print_r($resolveNextRoute, true));
  87.         $this->getHttpRequestVerifier()->invalidate($token);
  88.         if (PaymentInterface::STATE_NEW !== $status->getValue()) {
  89.             /** @var FlashBagInterface $flashBag */
  90.             $flashBag $request->getSession()->getBag('flashes');
  91.             $flashBag->add('info'sprintf('sylius.payment.%s'$status->getValue()));
  92.         }
  93.         return new RedirectResponse($this->router->generate($resolveNextRoute->getRouteName(), $resolveNextRoute->getRouteParameters()));
  94.     }
  95.     // protected function payLog($data) {
  96.         
  97.     //     // $log = "Cart id - ".$cartId;
  98.     //     // $log .= print_r();;
  99.     //     $logger = $this->container->get('monolog.logger.hipaydebug');
  100.     //     // $logger = new Logger('paydebug');
  101.     //     // $logger->debug($log);
  102.     //     $logger->debug(print_r($data, true));
  103.     //     // 
  104.     //     // dump($data);
  105.     // } 
  106. }