Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e4cdf8
commit ef48e0e
Showing
9 changed files
with
550 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
return [ | ||
'name' => 'Sendinblue integration', | ||
'description' => 'Allows to send E-mails with Sendinblue', | ||
'version' => '1.0', | ||
'author' => 'Dazzle', | ||
'services' => [ | ||
'other' => [ | ||
'mautic.transport.sendinblue_api' => [ | ||
'class' => \MauticPlugin\MauticSendinblueBundle\Swiftmailer\Transport\SendinblueApiTransport::class, | ||
'arguments' => [ | ||
'%mautic.mailer_api_key%', | ||
'translator', | ||
'mautic.transport.sendinblue_api.callback', | ||
], | ||
'tags' => [ | ||
'mautic.email_transport', | ||
], | ||
'tagArguments' => [ | ||
[ | ||
'transport_alias' => 'mautic.email.config.mailer_transport.sendinblue', | ||
'field_api_key' => true, | ||
], | ||
], | ||
], | ||
'mautic.transport.sendinblue_api.callback' => [ | ||
'class' => \MauticPlugin\MauticSendinblueBundle\Swiftmailer\Callback\SendinblueApiCallback::class, | ||
'arguments' => [ | ||
'mautic.email.model.transport_callback', | ||
'monolog.logger.mautic', | ||
], | ||
], | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\MauticSendinblueBundle; | ||
|
||
use Mautic\PluginBundle\Bundle\PluginBundleBase; | ||
|
||
class MauticSendinblueBundle extends PluginBundleBase | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\MauticSendinblueBundle\Swiftmailer\Callback; | ||
|
||
use Mautic\LeadBundle\Entity\DoNotContact; | ||
|
||
/** | ||
* Class CallbackEnum. | ||
*/ | ||
class CallbackEnum | ||
{ | ||
|
||
const ERROR = 'error'; | ||
const SOFT_BOUNCE = 'soft_bounce'; | ||
const HARD_BOUNCE = 'hard_bounce'; | ||
const INVALID_EMAIL = 'invalid_email'; | ||
const SPAM = 'spam'; | ||
const BLOCKED = 'blocked'; | ||
const UNSUBSCRIBED = 'unsubscribed'; | ||
|
||
/** | ||
* Checks if the event have to be processed. | ||
* | ||
* @param string $event | ||
* | ||
* @return bool | ||
*/ | ||
public static function shouldBeEventProcessed($event) | ||
{ | ||
return in_array($event, self::getSupportedEvents(), true); | ||
} | ||
|
||
/** | ||
* Converts an event name to DNC reason. | ||
* | ||
* @param $event | ||
* | ||
* @return string|null | ||
*/ | ||
public static function convertEventToDncReason($event) | ||
{ | ||
if (!self::shouldBeEventProcessed($event)) { | ||
return null; | ||
} | ||
|
||
$mapping = self::eventMappingToDncReason(); | ||
|
||
return $mapping[$event]; | ||
} | ||
|
||
/** | ||
* Returns an array of supported Sendinblue events. | ||
* | ||
* @return array | ||
*/ | ||
private static function getSupportedEvents() | ||
{ | ||
return [ | ||
self::ERROR, | ||
self::SOFT_BOUNCE, | ||
self::HARD_BOUNCE, | ||
self::INVALID_EMAIL, | ||
self::SPAM, | ||
self::BLOCKED, | ||
self::UNSUBSCRIBED, | ||
]; | ||
} | ||
|
||
/** | ||
* Mapping Sendinblue events and DNC reasons. | ||
* | ||
* @return array | ||
*/ | ||
private static function eventMappingToDncReason() | ||
{ | ||
return [ | ||
self::ERROR => DoNotContact::BOUNCED, | ||
self::SOFT_BOUNCE => DoNotContact::BOUNCED, | ||
self::HARD_BOUNCE => DoNotContact::BOUNCED, | ||
self::INVALID_EMAIL => DoNotContact::BOUNCED, | ||
self::SPAM => DoNotContact::BOUNCED, | ||
self::BLOCKED => DoNotContact::BOUNCED, | ||
self::UNSUBSCRIBED => DoNotContact::UNSUBSCRIBED, | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\MauticSendinblueBundle\Swiftmailer\Callback; | ||
|
||
use MauticPlugin\MauticSendinblueBundle\Swiftmailer\Exception\ResponseItemException; | ||
|
||
/** | ||
* Class ResponseItem. | ||
*/ | ||
class ResponseItem | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $email; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $reason; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $dncReason; | ||
|
||
/** | ||
* ResponseItem constructor. | ||
* | ||
* @param array $item | ||
* | ||
* @throws ResponseItemException | ||
*/ | ||
public function __construct(array $item) | ||
{ | ||
if (!isset($item['email']) || (isset($item['email']) && empty($item['email']))) { | ||
throw new ResponseItemException('Email must not be empty.'); | ||
} | ||
|
||
$this->email = is_array($item['email']) ? reset($item['email']) : $item['email']; | ||
$this->reason = isset($item['reason']) ? $item['reason'] : null; | ||
$this->dncReason = CallbackEnum::convertEventToDncReason($item['event']); | ||
} | ||
|
||
/** | ||
* Gets an email of the event. | ||
* | ||
* @return string | ||
*/ | ||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* Gets a reason of the event. | ||
* | ||
* @return string | ||
*/ | ||
public function getReason() | ||
{ | ||
return $this->reason; | ||
} | ||
|
||
/** | ||
* Gets DNC reason of the event. | ||
* | ||
* @return int | ||
*/ | ||
public function getDncReason() | ||
{ | ||
return $this->dncReason; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\MauticSendinblueBundle\Swiftmailer\Callback; | ||
|
||
use Mautic\EmailBundle\Model\TransportCallback; | ||
use MauticPlugin\MauticSendinblueBundle\Swiftmailer\Exception\ResponseItemException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Monolog\Logger; | ||
|
||
/** | ||
* Class SendinblueApiCallback. | ||
*/ | ||
class SendinblueApiCallback | ||
{ | ||
|
||
/** | ||
* @var TransportCallback | ||
*/ | ||
private $transportCallback; | ||
|
||
/** | ||
* @var Logger | ||
*/ | ||
protected $logger; | ||
|
||
/** | ||
* SendinblueApiCallback constructor. | ||
* | ||
* @param TransportCallback $transportCallback | ||
* @param Logger $logger | ||
*/ | ||
public function __construct(TransportCallback $transportCallback, Logger $logger) | ||
{ | ||
$this->transportCallback = $transportCallback; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* Processes Sendinblue API callback request. | ||
* | ||
* @param Request $request | ||
*/ | ||
public function processCallbackRequest(Request $request) | ||
{ | ||
$parameters = $request->request->all(); | ||
|
||
if (isset($parameters['event']) && CallbackEnum::shouldBeEventProcessed($parameters['event'])) { | ||
try { | ||
$item = new ResponseItem($parameters); | ||
$this->transportCallback->addFailureByAddress($item->getEmail(), $item->getReason(), $item->getDncReason()); | ||
} | ||
catch (ResponseItemException $e) { | ||
$this->logger->log('error', $e->getMessage()); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\MauticSendinblueBundle\Swiftmailer\Exception; | ||
|
||
use Exception; | ||
|
||
class ResponseItemException extends Exception | ||
{ | ||
} |
Oops, something went wrong.