mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 06:24:30 -04:00
Support Slack notifications
This commit is contained in:
parent
a78b6b1c51
commit
d4a9d85fc2
76
app/Notifications/PaymentCreated.php
Normal file
76
app/Notifications/PaymentCreated.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
|
||||
class PaymentCreated extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
protected $payment;
|
||||
protected $invoice;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($payment, $invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
$this->payment = $payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['slack'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toSlack($notifiable)
|
||||
{
|
||||
$url = 'http://www.ninja.test/subscriptions/create';
|
||||
|
||||
return (new SlackMessage)
|
||||
->from(APP_NAME)
|
||||
->image('https://app.invoiceninja.com/favicon-v2.png')
|
||||
->content(trans('texts.received_new_payment'))
|
||||
->attachment(function ($attachment) {
|
||||
$invoiceName = $this->invoice->present()->titledName;
|
||||
$invoiceLink = $this->invoice->present()->multiAccountLink;
|
||||
$attachment->title($invoiceName, $invoiceLink)
|
||||
->fields([
|
||||
trans('texts.client') => $this->invoice->client->getDisplayName(),
|
||||
trans('texts.amount') => $this->payment->present()->amount,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddSlackNotifications extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function ($table) {
|
||||
$table->string('slack_webhook_url')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function ($table) {
|
||||
$table->dropColumn('slack_webhook_url');
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user