src/Payment/Controller/PaymentMPNotificationController.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Payment\Controller;
  3. use App\Framework\Controller\APIController;
  4. use App\Payment\Service\MercadoPagoNotificationService;
  5. use Psr\Log\LoggerInterface;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. #[Route(path'/api/payments/mp_notification')]
  9. class PaymentMPNotificationController extends APIController
  10. {
  11.     #[Route(path''methods: ['POST'])]
  12.     public function notifyPaymentAction(
  13.         MercadoPagoNotificationService $mpNotificationService,
  14.         LoggerInterface $logger
  15.     ): JsonResponse {
  16.         $body $this->getRequestBody();
  17.         $result false;
  18.         // MercadoPago insists on sending us IPN notifications even when disabled...
  19.         if (!array_key_exists('type'$body)) {
  20.             return new JsonResponse(null200);
  21.         }
  22.         if ($body['type'] === 'payment' && $body['action'] === 'payment.created') {
  23.             $result $mpNotificationService->notifyMercadoPointPaymentCreated($body['data']['id']);
  24.         } elseif ($body['type'] === 'payment' && $body['action'] === 'payment.updated') {
  25.             $result $mpNotificationService->notifyMercadoPagoPaymentUpdated($body['data']['id']);
  26.         }
  27.         return new JsonResponse(null$result 201 200);
  28.     }
  29. }