src/Controller/CcController.php line 37
<?php
namespace App\Controller;
use App\Entity\Payment;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class CcController extends BaseController
{
#[Route('/cc', name: 'app_cc')]
public function index(): Response
{
return $this->redirectToRoute('home');
}
#[Route('/cc/payment-success', name: 'payment_success')]
public function paymentSuccess(Request $request): Response
{
$p = $this->em->getRepository(Payment::class)->findOneBy(['guid' => $request->get('guid')]);
if ($p) {
return $this->render('cc/payment-success.html.twig', ['p' => $p]);
} else {
return $this->redirectToRoute('home');
}
}
#[Route('/cc/payment-not-success', name: 'payment_not_success')]
public function paymentNotSuccess(Request $request): Response
{
return $this->render('cc/payment-not-success.html.twig');
}
#[Route('/cc/payment', name: 'app_cc_payment')]
public function payment(Request $request): Response
{
$form = $this->createFormBuilder()
->add('name', TextType::class)
->add('email', TextType::class)
->add('mobile', TextType::class)
->add('address', TextType::class)
->add('city', TextType::class)
->add('state', TextType::class)
->add('country', TextType::class)
->add('zip', TextType::class)
->add('amount', NumberType::class)
->add('paymentFor', TextType::class)
->add('submit', SubmitType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$payment = new Payment();
$payment->setName($form->get('name')->getData())
->setEmail($form->get('email')->getData())
->setMobile($form->get('mobile')->getData())
->setAddress($form->get('address')->getData())
->setCity($form->get('city')->getData())
->setState($form->get('state')->getData())
->setCountry($form->get('country')->getData())
->setZip($form->get('zip')->getData())
->setAmount($form->get('amount')->getData())
->setPaymentFor($form->get('paymentFor')->getData())
->setStatus('watting')
->setGuid(uniqid())
->setIsSuccess(false)
->setCreatedOn($this->myDate());
$this->em->persist($payment);
$this->em->flush();
return $this->redirectToRoute('app_cc_payment_button', ['oid' => $payment->getId()]);
}
return $this->render('cc/payment.html.twig', [
'form' => $form->createView(),
]);
}
#[Route('/cc/payment-button/{oid}', name: 'app_cc_payment_button')]
public function paymentButton(Request $request): Response
{
$p = $this->em->getRepository(Payment::class)->findOneBy(['id' => $request->get('oid')]);
return $this->render('cc/btn.html.twig', ['p' => $p]);
}
}