diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index f4eec6c9fd..65dfe48865 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -1067,6 +1067,7 @@ class AccountController extends BaseController $user->notify_viewed = Input::get('notify_viewed'); $user->notify_paid = Input::get('notify_paid'); $user->notify_approved = Input::get('notify_approved'); + $user->slack_webhook_url = Input::get('slack_webhook_url'); $user->save(); $account = $user->account; diff --git a/app/Listeners/NotificationListener.php b/app/Listeners/NotificationListener.php index 089e455056..7640c3a320 100644 --- a/app/Listeners/NotificationListener.php +++ b/app/Listeners/NotificationListener.php @@ -10,6 +10,7 @@ use App\Events\QuoteInvitationWasApproved; use App\Events\PaymentWasCreated; use App\Services\PushService; use App\Jobs\SendNotificationEmail; +use App\Notifications\PaymentCreated; /** * Class NotificationListener @@ -47,14 +48,17 @@ class NotificationListener * @param $type * @param null $payment */ - private function sendEmails($invoice, $type, $payment = null, $notes = false) + private function sendNotifications($invoice, $type, $payment = null, $notes = false) { foreach ($invoice->account->users as $user) { - if ($user->{"notify_{$type}"}) - { + if ($user->{"notify_{$type}"}) { dispatch(new SendNotificationEmail($user, $invoice, $type, $payment, $notes)); } + + if ($payment && $user->slack_webhook_url) { + $user->notify(new PaymentCreated($payment, $invoice)); + } } } @@ -63,7 +67,7 @@ class NotificationListener */ public function emailedInvoice(InvoiceWasEmailed $event) { - $this->sendEmails($event->invoice, 'sent', null, $event->notes); + $this->sendNotifications($event->invoice, 'sent', null, $event->notes); $this->pushService->sendNotification($event->invoice, 'sent'); } @@ -72,7 +76,7 @@ class NotificationListener */ public function emailedQuote(QuoteWasEmailed $event) { - $this->sendEmails($event->quote, 'sent', null, $event->notes); + $this->sendNotifications($event->quote, 'sent', null, $event->notes); $this->pushService->sendNotification($event->quote, 'sent'); } @@ -85,7 +89,7 @@ class NotificationListener return; } - $this->sendEmails($event->invoice, 'viewed'); + $this->sendNotifications($event->invoice, 'viewed'); $this->pushService->sendNotification($event->invoice, 'viewed'); } @@ -98,7 +102,7 @@ class NotificationListener return; } - $this->sendEmails($event->quote, 'viewed'); + $this->sendNotifications($event->quote, 'viewed'); $this->pushService->sendNotification($event->quote, 'viewed'); } @@ -107,7 +111,7 @@ class NotificationListener */ public function approvedQuote(QuoteInvitationWasApproved $event) { - $this->sendEmails($event->quote, 'approved'); + $this->sendNotifications($event->quote, 'approved'); $this->pushService->sendNotification($event->quote, 'approved'); } @@ -122,7 +126,7 @@ class NotificationListener } $this->contactMailer->sendPaymentConfirmation($event->payment); - $this->sendEmails($event->payment->invoice, 'paid', $event->payment); + $this->sendNotifications($event->payment->invoice, 'paid', $event->payment); $this->pushService->sendNotification($event->payment->invoice, 'paid'); } diff --git a/app/Models/User.php b/app/Models/User.php index 6162bffef2..34514cbe5d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -70,6 +70,7 @@ class User extends Authenticatable 'google_2fa_secret', 'google_2fa_phone', 'remember_2fa_token', + 'slack_webhook_url', ]; /** @@ -446,6 +447,11 @@ class User extends Authenticatable //$this->notify(new ResetPasswordNotification($token)); app('App\Ninja\Mailers\UserMailer')->sendPasswordReset($this, $token); } + + public function routeNotificationForSlack() + { + return $this->slack_webhook_url; + } } User::created(function ($user) diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 3eb0139e8e..e45838a760 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2767,6 +2767,9 @@ $LANG = array( 'group' => 'Group', 'subgroup' => 'Subgroup', 'unset' => 'Unset', + 'received_new_payment' => 'You\'ve received a new payment!', + 'slack_webhook_help' => 'Receive payment notifications using Slack :link.', + 'incoming_webhooks' => 'incoming webhooks', ); diff --git a/resources/views/accounts/notifications.blade.php b/resources/views/accounts/notifications.blade.php index 69942a915b..2aef1bcec9 100644 --- a/resources/views/accounts/notifications.blade.php +++ b/resources/views/accounts/notifications.blade.php @@ -5,11 +5,29 @@ @include('accounts.nav', ['selected' => ACCOUNT_NOTIFICATIONS]) - {!! Former::open()->addClass('warn-on-exit') !!} + {!! Former::open() + ->addClass('warn-on-exit') + ->rules([ + 'slack_webhook_url' => 'url', + ]) !!} {{ Former::populate($account) }} + {{ Former::populateField('slack_webhook_url', auth()->user()->slack_webhook_url) }} @include('accounts.partials.notifications') +
+
+

Slack

+
+
+ + {!! Former::text('slack_webhook_url') + ->label('webhook_url') + ->help(trans('texts.slack_webhook_help', ['link' => link_to('https://my.slack.com/services/new/incoming-webhook/', trans('texts.incoming_webhooks'), ['target' => '_blank'])])) !!} + +
+
+

{!! trans('texts.google_analytics') !!}

@@ -22,39 +40,6 @@
-
-
-

{!! trans('texts.facebook_and_twitter') !!}

-
-
- - -
- -
- -
- - -
   - - - - -
{{ trans('texts.facebook_and_twitter_help') }}
- -
-
-
-
- -
{!! Button::success(trans('texts.save')) ->submit()->large()