mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
74 lines
1.4 KiB
PHP
74 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Invitation;
|
|
use App\Ninja\Mailers\UserMailer;
|
|
use Carbon;
|
|
|
|
/**
|
|
* Class EmailService.
|
|
*/
|
|
class EmailService
|
|
{
|
|
/**
|
|
* @var UserMailer
|
|
*/
|
|
protected $userMailer;
|
|
|
|
/**
|
|
* EmailService constructor.
|
|
*
|
|
* @param UserMailer $userMailer
|
|
*/
|
|
public function __construct(UserMailer $userMailer)
|
|
{
|
|
$this->userMailer = $userMailer;
|
|
}
|
|
|
|
/**
|
|
* @param $messageId
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function markOpened($messageId)
|
|
{
|
|
/** @var \App\Models\Invitation $invitation */
|
|
$invitation = Invitation::whereMessageId($messageId)->first();
|
|
|
|
if (! $invitation) {
|
|
return false;
|
|
}
|
|
|
|
$invitation->opened_date = Carbon::now()->toDateTimeString();
|
|
$invitation->save();
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @param $messageId
|
|
* @param $error
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function markBounced($messageId, $error)
|
|
{
|
|
/** @var \App\Models\Invitation $invitation */
|
|
$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;
|
|
}
|
|
}
|