From bb2eea035a981db293d621d8f2b07c5c8bf87f0e Mon Sep 17 00:00:00 2001 From: Rowdy Klijnsmit Date: Mon, 5 Dec 2016 15:39:27 +0100 Subject: [PATCH] Added new event listeners for Zapier * Add updated quote listener * Add updated invoice listener * Add deleted invoice listener --- app/Http/routes.php | 8 ++++++- app/Listeners/SubscriptionListener.php | 30 ++++++++++++++++++++++++++ app/Providers/EventServiceProvider.php | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/Http/routes.php b/app/Http/routes.php index 157356357d1b..d228cec77c35 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -634,7 +634,13 @@ if (!defined('CONTACT_EMAIL')) { define('EVENT_CREATE_INVOICE', 2); define('EVENT_CREATE_QUOTE', 3); define('EVENT_CREATE_PAYMENT', 4); - define('EVENT_CREATE_VENDOR',5); + define('EVENT_CREATE_VENDOR', 5); + + // Added new events + define('EVENT_UPDATE_QUOTE', 6); + define('EVENT_DELETE_QUOTE', 7); + define('EVENT_UPDATE_INVOICE', 8); + define('EVENT_DELETE_INVOICE', 9); define('REQUESTED_PRO_PLAN', 'REQUESTED_PRO_PLAN'); define('DEMO_ACCOUNT_ID', 'DEMO_ACCOUNT_ID'); diff --git a/app/Listeners/SubscriptionListener.php b/app/Listeners/SubscriptionListener.php index 5b84413cb25a..3bf558a0a868 100644 --- a/app/Listeners/SubscriptionListener.php +++ b/app/Listeners/SubscriptionListener.php @@ -1,5 +1,8 @@ quote->account); + $this->checkSubscriptions(EVENT_UPDATE_QUOTE, $event->quote, $transformer, ENTITY_CLIENT); + } + + /** + * @param InvoiceWasUpdated $event + */ + public function updatedInvoice(InvoiceWasUpdated $event) + { + $transformer = new InvoiceTransformer($event->invoice->account); + $this->checkSubscriptions(EVENT_UPDATE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT); + } + + /** + * @param InvoiceWasDeleted $event + */ + public function deletedInvoice(InvoiceWasDeleted $event) + { + $transformer = new InvoiceTransformer($event->invoice->account); + $this->checkSubscriptions(EVENT_DELETE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT); } /** diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 0561a1a1f629..933a9f555c93 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -36,6 +36,7 @@ class EventServiceProvider extends ServiceProvider { 'App\Events\InvoiceWasUpdated' => [ 'App\Listeners\ActivityListener@updatedInvoice', 'App\Listeners\InvoiceListener@updatedInvoice', + 'App\Listeners\SubscriptionListener@updatedInvoice', ], 'App\Events\InvoiceWasArchived' => [ 'App\Listeners\ActivityListener@archivedInvoice', @@ -67,6 +68,7 @@ class EventServiceProvider extends ServiceProvider { ], 'App\Events\QuoteWasUpdated' => [ 'App\Listeners\ActivityListener@updatedQuote', + 'App\Listeners\SubscriptionListener@updatedQuote', ], 'App\Events\QuoteWasArchived' => [ 'App\Listeners\ActivityListener@archivedQuote',