diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index b76e09ede7ec..144834898480 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -25,6 +25,7 @@ use App\Models\GatewayType; use App\Models\Invoice; use App\Models\RecurringInvoice; use App\Models\Subscription; +use App\Notifications\Ninja\NewAccountNotification; use App\Repositories\SubscriptionRepository; use App\Utils\Ninja; use App\Utils\Traits\MakesHash; @@ -165,6 +166,9 @@ class NinjaPlanController extends Controller ->increment() ->queue(); + $ninja_company = Company::on('db-ninja-01')->find(config('ninja.ninja_default_company_id')); + $ninja_company->notification(new NewAccountNotification($account, $client))->ninja(); + return $this->render('plan.trial_confirmed', $data); } diff --git a/app/Notifications/Ninja/NewAccountNotification.php b/app/Notifications/Ninja/NewAccountNotification.php new file mode 100644 index 000000000000..52648d36066f --- /dev/null +++ b/app/Notifications/Ninja/NewAccountNotification.php @@ -0,0 +1,93 @@ +account = $account; + $this->client = $client; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['slack']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } + + public function toSlack($notifiable) + { + $content = "New Trial Started\n"; + $content = "{$this->client->name}\n"; + $content = "Account key: {$this->account->key}\n"; + $content = "Users: {$this->account->users()->pluck('email')}\n"; + $content = "Contacts: {$this->client->contacts()->pluck('email')}\n"; + + + return (new SlackMessage) + ->success() + ->from(ctrans('texts.notification_bot')) + ->image('https://app.invoiceninja.com/favicon.png') + ->content($content); + } +} diff --git a/app/Notifications/Ninja/SpamNotification.php b/app/Notifications/Ninja/SpamNotification.php new file mode 100644 index 000000000000..6c94a33849ac --- /dev/null +++ b/app/Notifications/Ninja/SpamNotification.php @@ -0,0 +1,111 @@ +spam_list = $spam_list; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['slack']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } + + public function toSlack($notifiable) + { + $content = ''; + + foreach($this->spam_list as $spam_list) + { + + if(array_key_exists('companies', $spam_list)) + { + $content .= " Companies \n"; + + foreach($spam_list['companies'] as $company) + { + $content .= "{$company['name']} - c_key={$company['company_key']} - a_key={$company['account_key']} - {$company['owner']} \n"; + } + } + + + if(array_key_exists('users', $spam_list)) + { + + $content .= ' Users \n'; + + foreach($spam_list['users'] as $user) + { + $content .= "{$user['email']} - a_key={$user['account_key']} - created={$user['created']} \n"; + } + + } + + } + + return (new SlackMessage) + ->success() + ->from(ctrans('texts.notification_bot')) + ->image('https://app.invoiceninja.com/favicon.png') + ->content($content); + } +}