vendor/shopware/core/Checkout/Payment/SalesChannel/SortedPaymentMethodRoute.php line 39

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Payment\SalesChannel;
  3. use Shopware\Core\Checkout\Payment\Hook\PaymentMethodRouteHook;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\Log\Package;
  6. use Shopware\Core\Framework\Script\Execution\ScriptExecutor;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. #[Route(defaults: ['_routeScope' => ['store-api']])]
  11. #[Package('checkout')]
  12. class SortedPaymentMethodRoute extends AbstractPaymentMethodRoute
  13. {
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(
  18.         private readonly AbstractPaymentMethodRoute $decorated,
  19.         private readonly ScriptExecutor $scriptExecutor
  20.     ) {
  21.     }
  22.     public function getDecorated(): AbstractPaymentMethodRoute
  23.     {
  24.         return $this->decorated;
  25.     }
  26.     #[Route(path'/store-api/payment-method'name'store-api.payment.method'methods: ['GET''POST'], defaults: ['_entity' => 'payment_method'])]
  27.     public function load(Request $requestSalesChannelContext $contextCriteria $criteria): PaymentMethodRouteResponse
  28.     {
  29.         $response $this->getDecorated()->load($request$context$criteria);
  30.         $response->getPaymentMethods()->sortPaymentMethodsByPreference($context);
  31.         $this->scriptExecutor->execute(new PaymentMethodRouteHook(
  32.             $response->getPaymentMethods(),
  33.             $request->query->getBoolean('onlyAvailable') || $request->request->getBoolean('onlyAvailable'),
  34.             $context
  35.         ));
  36.         return $response;
  37.     }
  38. }