vendor/shopware/storefront/Controller/AccountPaymentController.php line 50

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Controller;
  3. use Shopware\Core\Checkout\Customer\CustomerEntity;
  4. use Shopware\Core\Checkout\Customer\SalesChannel\AbstractChangePaymentMethodRoute;
  5. use Shopware\Core\Checkout\Payment\Exception\UnknownPaymentMethodException;
  6. use Shopware\Core\Framework\Routing\Annotation\LoginRequired;
  7. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  8. use Shopware\Core\Framework\Routing\Annotation\Since;
  9. use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
  10. use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
  11. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  12. use Shopware\Storefront\Framework\Routing\Annotation\NoStore;
  13. use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoadedHook;
  14. use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoader;
  15. use Symfony\Component\HttpFoundation\RedirectResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. /**
  20.  * @Route(defaults={"_routeScope"={"storefront"}})
  21.  *
  22.  * @deprecated tag:v6.5.0 - reason:becomes-internal - Will be internal
  23.  */
  24. class AccountPaymentController extends StorefrontController
  25. {
  26.     private AccountPaymentMethodPageLoader $paymentMethodPageLoader;
  27.     private AbstractChangePaymentMethodRoute $changePaymentMethodRoute;
  28.     /**
  29.      * @internal
  30.      */
  31.     public function __construct(
  32.         AccountPaymentMethodPageLoader $paymentMethodPageLoader,
  33.         AbstractChangePaymentMethodRoute $changePaymentMethodRoute
  34.     ) {
  35.         $this->paymentMethodPageLoader $paymentMethodPageLoader;
  36.         $this->changePaymentMethodRoute $changePaymentMethodRoute;
  37.     }
  38.     /**
  39.      * @Since("6.0.0.0")
  40.      * @Route("/account/payment", name="frontend.account.payment.page", options={"seo"="false"}, methods={"GET"}, defaults={"_loginRequired"=true})
  41.      * @Route("/account/payment", name="frontend.account.payment.page", options={"seo"="false"}, methods={"GET"})
  42.      * @NoStore
  43.      */
  44.     public function paymentOverview(Request $requestSalesChannelContext $context): Response
  45.     {
  46.         $page $this->paymentMethodPageLoader->load($request$context);
  47.         $this->hook(new AccountPaymentMethodPageLoadedHook($page$context));
  48.         return $this->renderStorefront('@Storefront/storefront/page/account/payment/index.html.twig', ['page' => $page]);
  49.     }
  50.     /**
  51.      * @Since("6.0.0.0")
  52.      * @Route("/account/payment", name="frontend.account.payment.save", methods={"POST"}, defaults={"_loginRequired"=true})
  53.      */
  54.     public function savePayment(RequestDataBag $requestDataBagSalesChannelContext $contextCustomerEntity $customer): Response
  55.     {
  56.         try {
  57.             $paymentMethodId $requestDataBag->getAlnum('paymentMethodId');
  58.             $this->changePaymentMethodRoute->change(
  59.                 $paymentMethodId,
  60.                 $requestDataBag,
  61.                 $context,
  62.                 $customer
  63.             );
  64.         } catch (UnknownPaymentMethodException InvalidUuidException $exception) {
  65.             $this->addFlash(self::DANGER$this->trans('error.' $exception->getErrorCode()));
  66.             return $this->forwardToRoute('frontend.account.payment.page', ['success' => false]);
  67.         }
  68.         $this->addFlash(self::SUCCESS$this->trans('account.paymentSuccess'));
  69.         return new RedirectResponse($this->generateUrl('frontend.account.payment.page'));
  70.     }
  71. }