src/Controller/PaymentIntentionController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\PaymentIntention;
  4. use App\Form\PaymentIntentionType;
  5. use App\Repository\PaymentIntentionRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpClient\HttpClient;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. /**
  13.  * @Route("/admin/payment_intention")
  14.  */
  15. class PaymentIntentionController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/", name="app_payment_intention_index", methods={"GET"})
  19.      */
  20.     public function index(PaymentIntentionRepository $paymentIntentionRepository): Response
  21.     {
  22.         return $this->render('payment_intention/index.html.twig', [
  23.             'payment_intentions' => $paymentIntentionRepository->findAll(),
  24.         ]);
  25.     }
  26.     /**
  27.      * @Route("/paymen_json", name="app_payment_intention_index_json", methods={"GET"})
  28.      */
  29.     public function indexJson(PaymentIntentionRepository $paymentIntentionRepository): Response
  30.     {
  31.         $paymentIntention=$paymentIntentionRepository->findAll();
  32.         return  $this->json(["data"=>$paymentIntention]);
  33.     }
  34.     /**
  35.      * @Route("/{id}/process_payment_ajax", name="app_pago_ajax", methods={"POST"})
  36.      */
  37.     public function pago_resend(Request $requestPaymentIntention $paymentIntention)
  38.     {
  39.         $pago=(object)[
  40.             'id' => $paymentIntention->getId(),
  41.             'referencia' => $paymentIntention->getReference(),
  42.             'moneda' => $paymentIntention->getMoneda(),
  43.             'paymentStatus' => $paymentIntention->getPaymentStatus(),
  44.             'promociones' => $paymentIntention->getPromociones(),
  45.             'xmlRequest' => $paymentIntention->getXmlRequest(),
  46.             'originalXmlRequest' => $paymentIntention->getOriginalXmlRequest(),
  47.             'originalXmlResponse' => $paymentIntention->getOriginalXmlResponse(),
  48.             'responseReceivedAt' => $paymentIntention->getResponseReceivedAt(),
  49.             'createAt' => $paymentIntention->getCreateAt(),
  50.             'updateAt' => $paymentIntention->getUpdateAt(),
  51.             'amount' => $paymentIntention->getAmount(),
  52.             'costumerService' => $paymentIntention->getConsumerWebService()->getID(),
  53.         ];
  54.         $objeto = (object) [
  55.             'referencia' => $paymentIntention->getReference(),
  56.             'status' => $paymentIntention->getPaymentStatus(),
  57.             'pago' => $pago,
  58.             'response' => (array)simplexml_load_string($paymentIntention->getOriginalXmlResponse())
  59.         ];
  60.         $url=$paymentIntention->getConsumerWebService()->getWebhook();
  61.         $client HttpClient::create();
  62.         $response $client->request('POST'$url, [
  63.             'headers' => [
  64.                 'Content-Type' => 'application/json',
  65.             ],
  66.             'body' => json_encode($objeto), // Convierte el array en JSON automáticamente
  67.         ]);
  68.         return new JsonResponse(
  69.             [
  70.                 'data' => $objeto,
  71.             ],
  72.             JsonResponse::HTTP_ACCEPTED
  73.         );
  74.     }
  75.     /**
  76.      * @Route("/new", name="app_payment_intention_new", methods={"GET", "POST"})
  77.      */
  78.     public function new(Request $requestPaymentIntentionRepository $paymentIntentionRepository): Response
  79.     {
  80.         $paymentIntention = new PaymentIntention();
  81.         $form $this->createForm(PaymentIntentionType::class, $paymentIntention);
  82.         $form->handleRequest($request);
  83.         if ($form->isSubmitted() && $form->isValid()) {
  84.             $paymentIntentionRepository->add($paymentIntentiontrue);
  85.             return $this->redirectToRoute('app_payment_intention_index', [], Response::HTTP_SEE_OTHER);
  86.         }
  87.         return $this->renderForm('payment_intention/new.html.twig', [
  88.             'payment_intention' => $paymentIntention,
  89.             'form' => $form,
  90.         ]);
  91.     }
  92.     /**
  93.      * @Route("/{id}", name="app_payment_intention_show", methods={"GET"})
  94.      */
  95.     public function show(PaymentIntention $paymentIntention): Response
  96.     {
  97.         return $this->render('payment_intention/show.html.twig', [
  98.             'payment_intention' => $paymentIntention,
  99.         ]);
  100.     }
  101.     /**
  102.      * @Route("/{id}/edit", name="app_payment_intention_edit", methods={"GET", "POST"})
  103.      */
  104.     public function edit(Request $requestPaymentIntention $paymentIntentionPaymentIntentionRepository $paymentIntentionRepository): Response
  105.     {
  106.         $form $this->createForm(PaymentIntentionType::class, $paymentIntention);
  107.         $form->handleRequest($request);
  108.         if ($form->isSubmitted() && $form->isValid()) {
  109.             $paymentIntentionRepository->add($paymentIntentiontrue);
  110.             return $this->redirectToRoute('app_payment_intention_index', [], Response::HTTP_SEE_OTHER);
  111.         }
  112.         return $this->renderForm('payment_intention/edit.html.twig', [
  113.             'payment_intention' => $paymentIntention,
  114.             'form' => $form,
  115.         ]);
  116.     }
  117.     /**
  118.      * @Route("/{id}", name="app_payment_intention_delete", methods={"POST"})
  119.      */
  120.     public function delete(Request $requestPaymentIntention $paymentIntentionPaymentIntentionRepository $paymentIntentionRepository): Response
  121.     {
  122.         if ($this->isCsrfTokenValid('delete'.$paymentIntention->getId(), $request->request->get('_token'))) {
  123.             $paymentIntentionRepository->remove($paymentIntentiontrue);
  124.         }
  125.         return $this->redirectToRoute('app_payment_intention_index', [], Response::HTTP_SEE_OTHER);
  126.     }
  127. }