custom/plugins/UnzerPayment6/src/Controllers/Storefront/UnzerCheckoutController.php line 37

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace UnzerPayment6\Controllers\Storefront;
  4. use ArgumentCountError;
  5. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  6. use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Shopware\Storefront\Controller\CheckoutController;
  9. use Shopware\Storefront\Controller\StorefrontController;
  10. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoader;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use UnzerPayment6\Components\PaymentHandler\Exception\UnzerPaymentProcessException;
  14. /**
  15.  * @RouteScope(scopes={"storefront"})
  16.  */
  17. class UnzerCheckoutController extends StorefrontController
  18. {
  19.     /** @var CheckoutController */
  20.     protected $innerService;
  21.     /** @var CheckoutFinishPageLoader */
  22.     private $finishPageLoader;
  23.     public function __construct(
  24.         CheckoutController $innerService,
  25.         CheckoutFinishPageLoader $finishPageLoader
  26.     ) {
  27.         $this->innerService     $innerService;
  28.         $this->finishPageLoader $finishPageLoader;
  29.     }
  30.     public function cartPage(Request $requestSalesChannelContext $context): Response
  31.     {
  32.         return $this->innerService->cartPage($request$context);
  33.     }
  34.     public function confirmPage(Request $requestSalesChannelContext $context): Response
  35.     {
  36.         return $this->innerService->confirmPage($request$context);
  37.     }
  38.     public function info(Request $requestSalesChannelContext $context): Response
  39.     {
  40.         return $this->innerService->info($request$context);
  41.     }
  42.     public function offcanvas(Request $requestSalesChannelContext $context): Response
  43.     {
  44.         return $this->innerService->offcanvas($request$context);
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     public function order(RequestDataBag $dataSalesChannelContext $contextRequest $request): Response
  50.     {
  51.         try {
  52.             return $this->innerService->order($data$context$request);
  53.         } catch (UnzerPaymentProcessException $apiException) {
  54.             return $this->forwardToRoute(
  55.                 'frontend.checkout.finish.page',
  56.                 [
  57.                     'orderId'                      => $apiException->getOrderId(),
  58.                     'changedPayment'               => false,
  59.                     'paymentFailed'                => true,
  60.                     'unzerPaymentExceptionMessage' => $apiException->getClientMessage(),
  61.                 ]
  62.             );
  63.         }
  64.     }
  65.     public function finishPage(Request $requestSalesChannelContext $context, ?RequestDataBag $dataBag null): Response
  66.     {
  67.         if (!$context->getCustomer()) {
  68.             return $this->redirectToRoute('frontend.checkout.register.page');
  69.         }
  70.         $unzerPaymentExceptionMessage $request->get('unzerPaymentExceptionMessage''');
  71.         if ($request->get('paymentFailed'false) === true && !empty($unzerPaymentExceptionMessage)) {
  72.             $page $this->finishPageLoader->load($request$context);
  73.             $this->addFlash(
  74.                 'danger',
  75.                 sprintf(
  76.                     '%s %s',
  77.                     $unzerPaymentExceptionMessage,
  78.                     $this->trans(
  79.                         'UnzerPayment.finishPaymentFailed',
  80.                         [
  81.                             '%editOrderUrl%' => $this->generateUrl(
  82.                                 'frontend.account.edit-order.page',
  83.                                 ['orderId' => $request->get('orderId')]
  84.                             ),
  85.                         ]
  86.                     )
  87.                 )
  88.             );
  89.             return $this->renderStorefront(
  90.                 '@Storefront/storefront/page/checkout/finish/index.html.twig',
  91.                 ['page' => $page]
  92.             );
  93.         }
  94.         try {
  95.             /** @phpstan-ignore-next-line */
  96.             return $this->innerService->finishPage($request$context$dataBag);
  97.         } catch (ArgumentCountError $exception) {
  98.             // signature changed with v6.4, this is the old version without dataBag Parameter
  99.             /** @phpstan-ignore-next-line */
  100.             return $this->innerService->finishPage($request$context);
  101.         }
  102.     }
  103. }