2015-10-11 16:41:09 +02:00
|
|
|
<?php namespace App\Services;
|
|
|
|
|
|
|
|
use Carbon;
|
|
|
|
use App\Models\Invitation;
|
|
|
|
use App\Ninja\Mailers\UserMailer;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* Class EmailService
|
|
|
|
*/
|
|
|
|
class EmailService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var UserMailer
|
|
|
|
*/
|
2015-10-11 16:41:09 +02:00
|
|
|
protected $userMailer;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* EmailService constructor.
|
|
|
|
*
|
|
|
|
* @param UserMailer $userMailer
|
|
|
|
*/
|
2015-10-11 16:41:09 +02:00
|
|
|
public function __construct(UserMailer $userMailer)
|
|
|
|
{
|
|
|
|
$this->userMailer = $userMailer;
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $messageId
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-10-11 16:41:09 +02:00
|
|
|
public function markOpened($messageId)
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/** @var \App\Models\Invitation $invitation */
|
|
|
|
$invitation = Invitation::whereMessageId($messageId)->first();
|
2015-10-11 16:41:09 +02:00
|
|
|
|
|
|
|
if (!$invitation) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$invitation->opened_date = Carbon::now()->toDateTimeString();
|
|
|
|
$invitation->save();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $messageId
|
|
|
|
* @param $error
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-10-11 16:41:09 +02:00
|
|
|
public function markBounced($messageId, $error)
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/** @var \App\Models\Invitation $invitation */
|
2015-10-11 16:41:09 +02:00
|
|
|
$invitation = Invitation::with('user', 'invoice', 'contact')
|
|
|
|
->whereMessageId($messageId)
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!$invitation) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$invitation->email_error = $error;
|
|
|
|
$invitation->save();
|
|
|
|
|
|
|
|
$this->userMailer->sendEmailBounced($invitation);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-30 17:05:31 +01:00
|
|
|
}
|