vendor/shopware/core/Checkout/Payment/SalesChannel/PaymentMethodRoute.php line 40

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Payment\SalesChannel;
  3. use Shopware\Core\Checkout\Payment\PaymentMethodCollection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  7. use Shopware\Core\Framework\Log\Package;
  8. use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
  9. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepository;
  10. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. #[Route(defaults: ['_routeScope' => ['store-api']])]
  14. #[Package('checkout')]
  15. class PaymentMethodRoute extends AbstractPaymentMethodRoute
  16. {
  17.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(private readonly SalesChannelRepository $paymentMethodsRepository)
  21.     {
  22.     }
  23.     public function getDecorated(): AbstractPaymentMethodRoute
  24.     {
  25.         throw new DecorationPatternException(self::class);
  26.     }
  27.     #[Route(path'/store-api/payment-method'name'store-api.payment.method'methods: ['GET''POST'], defaults: ['_entity' => 'payment_method'])]
  28.     public function load(Request $requestSalesChannelContext $contextCriteria $criteria): PaymentMethodRouteResponse
  29.     {
  30.         $criteria
  31.             ->addFilter(new EqualsFilter('active'true))
  32.             ->addSorting(new FieldSorting('position'))
  33.             ->addAssociation('media');
  34.         $result $this->paymentMethodsRepository->search($criteria$context);
  35.         /** @var PaymentMethodCollection $paymentMethods */
  36.         $paymentMethods $result->getEntities();
  37.         if ($request->query->getBoolean('onlyAvailable') || $request->request->getBoolean('onlyAvailable')) {
  38.             $paymentMethods $paymentMethods->filterByActiveRules($context);
  39.         }
  40.         $result->assign(['entities' => $paymentMethods'elements' => $paymentMethods'total' => $paymentMethods->count()]);
  41.         return new PaymentMethodRouteResponse($result);
  42.     }
  43. }