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

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