src/Controller/CcController.php line 37

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Payment;
  4. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  5. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class CcController extends BaseController
  11. {
  12.     #[Route('/cc'name'app_cc')]
  13.     public function index(): Response
  14.     {
  15.         return $this->redirectToRoute('home');
  16.     }
  17.     #[Route('/cc/payment-success'name'payment_success')]
  18.     public function paymentSuccess(Request $request): Response
  19.     {
  20.         $p $this->em->getRepository(Payment::class)->findOneBy(['guid' => $request->get('guid')]);
  21.         if ($p) {
  22.             return $this->render('cc/payment-success.html.twig', ['p' => $p]);
  23.         } else {
  24.             return $this->redirectToRoute('home');
  25.         }
  26.     }
  27.     #[Route('/cc/payment-not-success'name'payment_not_success')]
  28.     public function paymentNotSuccess(Request $request): Response
  29.     {
  30.         return $this->render('cc/payment-not-success.html.twig');
  31.     }
  32.     #[Route('/cc/payment'name'app_cc_payment')]
  33.     public function payment(Request $request): Response
  34.     {
  35.         $form $this->createFormBuilder()
  36.             ->add('name'TextType::class)
  37.             ->add('email'TextType::class)
  38.             ->add('mobile'TextType::class)
  39.             ->add('address'TextType::class)
  40.             ->add('city'TextType::class)
  41.             ->add('state'TextType::class)
  42.             ->add('country'TextType::class)
  43.             ->add('zip'TextType::class)
  44.             ->add('amount'NumberType::class)
  45.             ->add('paymentFor'TextType::class)
  46.             ->add('submit'SubmitType::class)
  47.             ->getForm();
  48.         $form->handleRequest($request);
  49.         if ($form->isSubmitted() && $form->isValid()) {
  50.             $payment = new Payment();
  51.             $payment->setName($form->get('name')->getData())
  52.                 ->setEmail($form->get('email')->getData())
  53.                 ->setMobile($form->get('mobile')->getData())
  54.                 ->setAddress($form->get('address')->getData())
  55.                 ->setCity($form->get('city')->getData())
  56.                 ->setState($form->get('state')->getData())
  57.                 ->setCountry($form->get('country')->getData())
  58.                 ->setZip($form->get('zip')->getData())
  59.                 ->setAmount($form->get('amount')->getData())
  60.                 ->setPaymentFor($form->get('paymentFor')->getData())
  61.                 ->setStatus('watting')
  62.                 ->setGuid(uniqid())
  63.                 ->setIsSuccess(false)
  64.                 ->setCreatedOn($this->myDate());
  65.             $this->em->persist($payment);
  66.             $this->em->flush();
  67.             return $this->redirectToRoute('app_cc_payment_button', ['oid' => $payment->getId()]);
  68.         }
  69.         return $this->render('cc/payment.html.twig', [
  70.             'form' => $form->createView(),
  71.         ]);
  72.     }
  73.     #[Route('/cc/payment-button/{oid}'name'app_cc_payment_button')]
  74.     public function paymentButton(Request $request): Response
  75.     {
  76.         $p $this->em->getRepository(Payment::class)->findOneBy(['id' => $request->get('oid')]);
  77.         return $this->render('cc/btn.html.twig', ['p' => $p]);
  78.     }
  79. }