vendor/store.shopware.com/unzerpayment6/src/Controllers/Storefront/UnzerCheckoutController.php line 39

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