src/Controller/Webhook/CustomerIoController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Webhook;
  3. use App\Traits\SentryNotifyTrait;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Evo\Infrastructure\MappingORM\CustomerIoEvent;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class CustomerIoController extends AbstractController
  10. {
  11.     use SentryNotifyTrait;
  12.     private Response $response;
  13.     private EntityManagerInterface $em;
  14.     public function __construct(EntityManagerInterface $em)
  15.     {
  16.         $this->response = new Response();
  17.         $this->em $em;
  18.     }
  19.     /**
  20.      * @Route("/customerio", name="app_webhook_customerio", methods={"POST"})
  21.      */
  22.     public function webhook()
  23.     {
  24.         $requestBody file_get_contents('php://input');
  25.         $customerIoData json_decode($requestBodynull512JSON_THROW_ON_ERROR);
  26.         if ($customerIoData && $customerIoData->data) {
  27.             $customerRecipient = isset($customerIoData->data->recipient) && $customerIoData->data->recipient ?: '';
  28.             $customerId $customerIoData->data->customer_id ?: '';
  29.             $customerIoEvent = new CustomerIoEvent();
  30.             $customerIoEvent->setCustomerId($customerId);
  31.             $customerIoEvent->setMetric($customerIoData->metric);
  32.             $customerIoEvent->setObjectType($customerIoData->object_type);
  33.             $customerIoEvent->setTimestamp($customerIoData->timestamp);
  34.             $customerIoEvent->setRecipient($customerRecipient);
  35.             $this->em->persist($customerIoEvent);
  36.             $this->em->flush();
  37.         }
  38.         $this->response->setStatusCode(200);
  39.         return $this->response->send();
  40.     }
  41. }