src/Customer/Controller/CustomerPaymentMethodsController.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Customer\Controller;
  3. use App\Customer\Entity\Customer;
  4. use App\Framework\Controller\APIController;
  5. use App\Payment\Service\PaymentService;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. #[Route(path'/api/customers/{id}/paymentMethods')]
  9. #[Security("(user == customer.getUser()) or (is_granted('ROLE_ADMIN') or is_granted('ROLE_CALLCENTER') or is_granted('ROLE_CHOFER'))")]
  10. class CustomerPaymentMethodsController extends APIController
  11. {
  12.     /**
  13.      * @return array<string, mixed>
  14.      */
  15.     #[Route(path''methods: ['GET'])]
  16.     public function paymentMethodsAction(Customer $customerPaymentService $paymentService): array
  17.     {
  18.         // Find the available payment methods for this customer
  19.         $methods $paymentService->getPaymentMethodsForCustomer($customer);
  20.         // If the request comes from an end user, return their saved methods.
  21.         $savedPaymentMethods = [];
  22.         if ($this->isGranted('ROLE_USER')) {
  23.             $savedPaymentMethods $paymentService->getSavedPaymentMethodsForCustomer($customer);
  24.         }
  25.         return [
  26.             'methods' => $methods,
  27.             'saved' => $savedPaymentMethods,
  28.         ];
  29.     }
  30. }