src/Controller/PaymentSimulatorController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\Model\PaymentSimulationModel;
  4. use App\Form\Type\PaymentSimulationType;
  5. use App\RequestManager\PaymentSimulatorRequestManager;
  6. use GuzzleHttp\Exception\GuzzleException;
  7. use Paynetics\Controller\AbstractWebController;
  8. use Paynetics\Exception\ApiException;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. /**
  12.  * Class GroupController
  13.  * @package App\Controller
  14.  */
  15. class PaymentSimulatorController extends AbstractWebController
  16. {
  17.     /**
  18.      * @required
  19.      */
  20.     public PaymentSimulatorRequestManager $requestManager;
  21.     public function index(Request $request): Response
  22.     {
  23.         $form $this->createForm(PaymentSimulationType::class, new PaymentSimulationModel());
  24.         $form->handleRequest($request);
  25.         if ($form->isSubmitted() && $form->isValid()) {
  26.             try {
  27.                 $this->requestManager->create($form->getData());
  28.                 $this->addFlash('success''Payment successfully send');
  29.             } catch (\Throwable) {
  30.                 $this->addFlash('error''Something went wrong');
  31.             }
  32.             return $this->redirectToRoute('index');
  33.         }
  34.         return $this->renderForm('payments/create.html.twig'compact('form'));
  35.     }
  36. }