mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Add webhooks for sent events
This commit is contained in:
parent
6b1c9b59b8
commit
19b1cbb858
@ -11,15 +11,16 @@
|
||||
|
||||
namespace App\Listeners\Mail;
|
||||
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Webhook;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\PurchaseOrderInvitation;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Events\MessageSent;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Symfony\Component\Mime\MessageConverter;
|
||||
|
||||
class MailSentListener implements ShouldQueue
|
||||
@ -41,30 +42,31 @@ class MailSentListener implements ShouldQueue
|
||||
*/
|
||||
public function handle(MessageSent $event)
|
||||
{
|
||||
|
||||
if (!Ninja::isHosted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message_id = $event->sent->getMessageId();
|
||||
|
||||
try {
|
||||
$message_id = $event->sent->getMessageId();
|
||||
|
||||
$message = MessageConverter::toEmail($event->sent->getOriginalMessage());
|
||||
$message = MessageConverter::toEmail($event->sent->getOriginalMessage());
|
||||
|
||||
if (!$message->getHeaders()->get('x-invitation')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$invitation_key = $message->getHeaders()->get('x-invitation')->getValue();
|
||||
|
||||
if ($message_id && $invitation_key) {
|
||||
$invitation = $this->discoverInvitation($invitation_key);
|
||||
|
||||
if (!$invitation) {
|
||||
if (!$message->getHeaders()->get('x-invitation')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$invitation->message_id = $message_id;
|
||||
$invitation->save();
|
||||
$invitation_key = $message->getHeaders()->get('x-invitation')->getValue();
|
||||
|
||||
if ($message_id && $invitation_key) {
|
||||
$invitation = $this->discoverInvitation($invitation_key);
|
||||
|
||||
if (!$invitation) {
|
||||
return;
|
||||
}
|
||||
|
||||
$invitation->message_id = $message_id;
|
||||
$invitation->save();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
nlog("Mail Sent Listener Exception");
|
||||
nlog($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,14 +76,18 @@ class MailSentListener implements ShouldQueue
|
||||
|
||||
foreach (MultiDB::$dbs as $db) {
|
||||
if ($invitation = InvoiceInvitation::on($db)->where('key', $key)->first()) {
|
||||
$invitation->invoice->sendEvent(Webhook::EVENT_SENT_INVOICE, "client");
|
||||
return $invitation;
|
||||
} elseif ($invitation = QuoteInvitation::on($db)->where('key', $key)->first()) {
|
||||
$invitation->quote->sendEvent(Webhook::EVENT_SENT_QUOTE, "client");
|
||||
return $invitation;
|
||||
} elseif ($invitation = RecurringInvoiceInvitation::on($db)->where('key', $key)->first()) {
|
||||
return $invitation;
|
||||
} elseif ($invitation = CreditInvitation::on($db)->where('key', $key)->first()) {
|
||||
$invitation->credit->sendEvent(Webhook::EVENT_SENT_CREDIT, "client");
|
||||
return $invitation;
|
||||
} elseif ($invitation = PurchaseOrderInvitation::on($db)->where('key', $key)->first()) {
|
||||
$invitation->purchase_order->sendEvent(Webhook::EVENT_SENT_PURCHASE_ORDER, "vendor");
|
||||
return $invitation;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user