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