src/Controller/AppBundle/Controller/Webhooks/WebhookSendInBlueController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller\AppBundle\Controller\Webhooks;
  3. use App\Controller\AppBundle\Entity\PolisInformation;
  4. use App\Entity\Offerte;
  5. use App\Entity\OfferteActivity;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class WebhookSendInBlueController extends AbstractController
  11. {
  12.     #[Route('/sendinbluehook'name:"loginTest"methods: ['POST'])]
  13.     public function webhook(Request $requestEntityManagerInterface $em) {
  14.         $act = new OfferteActivity();
  15.         $output $request->getContent();
  16.         $output json_decode($output);
  17.         $act->setTimestamp(new \DateTime());
  18.         $act->setEmail($output->email);
  19.         $act->setEvent($output->event);
  20.         if (isset($output->tag)) {
  21.             $act->setTag(str_replace(']'''str_replace('['''str_replace('"'''$output->tag))));
  22.         } else {
  23.             $act->setTag('');
  24.         }
  25.         $em->persist($act);
  26.         $em->flush();
  27.         if ($this->isError($output->event$output->email)) {
  28.             /** @var Offerte $offerte */
  29.             $offerte $em->getRepository(Offerte::class)->findOneBy(array('offerte_id' => explode("-"$act->getTag())[1]));
  30.             $offerte->mailError();
  31.         }
  32.         return $this->json(['success' => 'true']);
  33.     }
  34.     public function isError($event$email) {
  35.         $endsWith = [
  36.             'internetverzekeren.nl',
  37.             'kraemer.nl',
  38.             'optima.nl',
  39.             'amstelgeld.nl'
  40.         ];
  41.         foreach ($endsWith as $domain) {
  42.             if (self::endsWith($email$domain)) {
  43.                 return false;
  44.             }
  45.         }
  46.         return (in_array($event,
  47.                 [
  48.                     'hard_bounce',
  49.                     'soft_bounce',
  50.                     'invalid_email',
  51.                     'deferred',
  52.                     'blocked',
  53.                     'error',
  54.                 ]
  55.             ));
  56.     }
  57.     static function endsWith($haystack$needle) {
  58.         return substr_compare($haystack$needle, -strlen($needle)) === 0;
  59.     }
  60. }