2020-03-02 11:22:37 +01:00
|
|
|
<?php
|
2020-09-21 12:54:58 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-21 12:54:58 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-04 12:09:43 +01:00
|
|
|
namespace App\Notifications\Admin;
|
2020-03-02 11:22:37 +01:00
|
|
|
|
|
|
|
use App\Utils\Number;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
2020-03-11 01:38:11 +01:00
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2020-03-02 11:22:37 +01:00
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
2020-03-11 01:38:11 +01:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2021-02-18 11:33:54 +01:00
|
|
|
class NewPaymentNotification extends Notification
|
2020-03-02 11:22:37 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new notification instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected $payment;
|
|
|
|
|
|
|
|
protected $company;
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
protected $settings;
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
protected $is_system;
|
|
|
|
|
2020-04-01 10:54:22 +02:00
|
|
|
public $method;
|
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
public function __construct($payment, $company, $is_system = false, $settings = null)
|
2020-03-02 11:22:37 +01:00
|
|
|
{
|
|
|
|
$this->payment = $payment;
|
|
|
|
$this->company = $company;
|
|
|
|
$this->settings = $payment->client->getMergedSettings();
|
2020-03-03 10:44:26 +01:00
|
|
|
$this->is_system = $is_system;
|
2020-04-01 10:54:22 +02:00
|
|
|
$this->method = null;
|
2020-03-02 11:22:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function via($notifiable)
|
|
|
|
{
|
2020-04-01 10:54:22 +02:00
|
|
|
return $this->method ?: [];
|
2020-03-02 11:22:37 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-02 11:22:37 +01:00
|
|
|
/**
|
|
|
|
* Get the mail representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return MailMessage
|
2020-03-02 11:22:37 +01:00
|
|
|
*/
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
$logo = $this->company->present()->logo();
|
2020-03-03 10:44:26 +01:00
|
|
|
$amount = Number::formatMoney($this->payment->amount, $this->payment->client);
|
|
|
|
$invoice_texts = ctrans('texts.invoice_number_short');
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
foreach ($this->payment->invoices as $invoice) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoice_texts .= $invoice->number.',';
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
$invoice_texts = substr($invoice_texts, 0, -1);
|
2020-03-02 11:22:37 +01:00
|
|
|
|
|
|
|
return (new SlackMessage)
|
|
|
|
->success()
|
2020-03-03 10:44:26 +01:00
|
|
|
//->to("#devv2")
|
2020-09-06 11:38:10 +02:00
|
|
|
->from('System')
|
2020-03-02 11:22:37 +01:00
|
|
|
->image($logo)
|
2020-03-21 06:37:30 +01:00
|
|
|
->content(ctrans(
|
|
|
|
'texts.notification_payment_paid',
|
|
|
|
['amount' => $amount,
|
|
|
|
'client' => $this->payment->client->present()->name(),
|
2020-09-06 11:38:10 +02:00
|
|
|
'invoice' => $invoice_texts, ]
|
2020-03-21 06:37:30 +01:00
|
|
|
));
|
2020-03-02 11:22:37 +01:00
|
|
|
}
|
|
|
|
}
|