vendor/shopware/core/Checkout/Payment/SalesChannel/HandlePaymentMethodRoute.php line 55

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Payment\SalesChannel;
  3. use Shopware\Core\Checkout\Payment\PaymentService;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
  6. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  7. use Shopware\Core\Framework\Routing\Annotation\Since;
  8. use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
  9. use Shopware\Core\Framework\Validation\DataValidationDefinition;
  10. use Shopware\Core\Framework\Validation\DataValidator;
  11. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\Validator\Constraints\NotBlank;
  15. use Symfony\Component\Validator\Constraints\Type;
  16. /**
  17.  * @Route(defaults={"_routeScope"={"store-api"}})
  18.  */
  19. #[Package('checkout')]
  20. class HandlePaymentMethodRoute extends AbstractHandlePaymentMethodRoute
  21. {
  22.     /**
  23.      * @var PaymentService
  24.      */
  25.     private $paymentService;
  26.     /**
  27.      * @var DataValidator
  28.      */
  29.     private $dataValidator;
  30.     /**
  31.      * @internal
  32.      */
  33.     public function __construct(
  34.         PaymentService $paymentService,
  35.         DataValidator $dataValidator
  36.     ) {
  37.         $this->paymentService $paymentService;
  38.         $this->dataValidator $dataValidator;
  39.     }
  40.     public function getDecorated(): AbstractHandlePaymentMethodRoute
  41.     {
  42.         throw new DecorationPatternException(self::class);
  43.     }
  44.     /**
  45.      * @Since("6.2.0.0")
  46.      * @Route("/store-api/handle-payment", name="store-api.payment.handle", methods={"GET", "POST"})
  47.      */
  48.     public function load(Request $requestSalesChannelContext $context): HandlePaymentMethodRouteResponse
  49.     {
  50.         $data array_merge($request->query->all(), $request->request->all());
  51.         $this->dataValidator->validate($data$this->createDataValidation());
  52.         $response $this->paymentService->handlePaymentByOrder(
  53.             $request->get('orderId'),
  54.             new RequestDataBag($request->request->all()),
  55.             $context,
  56.             $request->get('finishUrl'),
  57.             $request->get('errorUrl')
  58.         );
  59.         return new HandlePaymentMethodRouteResponse($response);
  60.     }
  61.     private function createDataValidation(): DataValidationDefinition
  62.     {
  63.         return (new DataValidationDefinition())
  64.             ->add('orderId', new NotBlank(), new Type('string'))
  65.             ->add('finishUrl', new Type('string'))
  66.             ->add('errorUrl', new Type('string'));
  67.     }
  68. }