<?php
namespace App\Controller\AppBundle\Controller\Webhooks;
use App\Controller\AppBundle\Entity\PolisInformation;
use App\Entity\Offerte;
use App\Entity\OfferteActivity;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class WebhookSendInBlueController extends AbstractController
{
#[Route('/sendinbluehook', name:"loginTest", methods: ['POST'])]
public function webhook(Request $request, EntityManagerInterface $em) {
$act = new OfferteActivity();
$output = $request->getContent();
$output = json_decode($output);
$act->setTimestamp(new \DateTime());
$act->setEmail($output->email);
$act->setEvent($output->event);
if (isset($output->tag)) {
$act->setTag(str_replace(']', '', str_replace('[', '', str_replace('"', '', $output->tag))));
} else {
$act->setTag('');
}
$em->persist($act);
$em->flush();
if ($this->isError($output->event, $output->email)) {
/** @var Offerte $offerte */
$offerte = $em->getRepository(Offerte::class)->findOneBy(array('offerte_id' => explode("-", $act->getTag())[1]));
$offerte->mailError();
}
return $this->json(['success' => 'true']);
}
public function isError($event, $email) {
$endsWith = [
'internetverzekeren.nl',
'kraemer.nl',
'optima.nl',
'amstelgeld.nl'
];
foreach ($endsWith as $domain) {
if (self::endsWith($email, $domain)) {
return false;
}
}
return (in_array($event,
[
'hard_bounce',
'soft_bounce',
'invalid_email',
'deferred',
'blocked',
'error',
]
));
}
static function endsWith($haystack, $needle) {
return substr_compare($haystack, $needle, -strlen($needle)) === 0;
}
}