2020-03-03 10:44:26 +01:00
|
|
|
<?php
|
|
|
|
|
2020-03-04 12:09:43 +01:00
|
|
|
namespace App\Notifications\Admin;
|
2020-03-03 10:44:26 +01:00
|
|
|
|
|
|
|
use App\Mail\Signup\NewSignup;
|
|
|
|
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-03 10:44:26 +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-03 10:44:26 +01:00
|
|
|
|
|
|
|
class NewPartialPaymentNotification extends Notification implements ShouldQueue
|
|
|
|
{
|
2020-03-11 01:38:11 +01:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
2020-03-03 10:44:26 +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-03 10:44:26 +01:00
|
|
|
|
|
|
|
protected $is_system;
|
|
|
|
|
|
|
|
public function __construct($payment, $company, $is_system = false, $settings = null)
|
|
|
|
{
|
|
|
|
$this->payment = $payment;
|
|
|
|
$this->company = $company;
|
|
|
|
$this->settings = $payment->client->getMergedSettings();
|
|
|
|
$this->is_system = $is_system;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function via($notifiable)
|
|
|
|
{
|
|
|
|
return $this->is_system ? ['slack'] : ['mail'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mail representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
|
|
*/
|
|
|
|
public function toMail($notifiable)
|
|
|
|
{
|
2020-05-26 10:20:50 +02:00
|
|
|
//@TODO THESE ARE @DEPRECATED NOW we are now using app/Mail/Admin/*
|
|
|
|
|
|
|
|
|
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-03-03 10:44:26 +01:00
|
|
|
$invoice_texts .= $invoice->number . ',';
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-03 10:44:26 +01:00
|
|
|
|
|
|
|
$invoice_texts = substr($invoice_texts, 0, -1);
|
|
|
|
|
|
|
|
$data = [
|
2020-03-21 06:37:30 +01:00
|
|
|
'title' => ctrans(
|
|
|
|
'texts.notification_partial_payment_paid_subject',
|
|
|
|
['client' => $this->payment->client->present()->name()]
|
|
|
|
),
|
|
|
|
'message' => ctrans(
|
|
|
|
'texts.notification_partial_payment_paid',
|
|
|
|
['amount' => $amount,
|
|
|
|
'client' => $this->payment->client->present()->name(),
|
2020-03-03 10:44:26 +01:00
|
|
|
'invoice' => $invoice_texts,
|
2020-03-21 06:37:30 +01:00
|
|
|
]
|
|
|
|
),
|
2020-07-14 11:55:28 +02:00
|
|
|
'url' => config('ninja.app_url') . 'payments/' . $this->payment->hashed_id,
|
2020-03-03 10:44:26 +01:00
|
|
|
'button' => ctrans('texts.view_payment'),
|
|
|
|
'signature' => $this->settings->email_signature,
|
|
|
|
'logo' => $this->company->present()->logo(),
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
return (new MailMessage)
|
2020-03-21 06:37:30 +01:00
|
|
|
->subject(
|
|
|
|
ctrans(
|
2020-03-26 04:23:57 +01:00
|
|
|
'texts.notification_partial_payment_paid_subject',
|
|
|
|
['client' => $this->payment->client->present()->name()]
|
|
|
|
)
|
2020-05-06 13:49:42 +02:00
|
|
|
)->markdown('email.admin.generic', $data)
|
|
|
|
->withSwiftMessage(function ($message) {
|
|
|
|
$message->getHeaders()->addTextHeader('Tag', $this->company->company_key);
|
|
|
|
});
|
2020-03-03 10:44:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
$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-03-03 10:44:26 +01:00
|
|
|
$invoice_texts .= $invoice->number . ',';
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-03 10:44:26 +01:00
|
|
|
|
|
|
|
$invoice_texts = substr($invoice_texts, 0, -1);
|
|
|
|
|
|
|
|
return (new SlackMessage)
|
|
|
|
->success()
|
|
|
|
//->to("#devv2")
|
|
|
|
->from("System")
|
|
|
|
->image($logo)
|
2020-03-21 06:37:30 +01:00
|
|
|
->content(ctrans(
|
|
|
|
'texts.notification_payment_paid',
|
|
|
|
['amount' => $amount,
|
|
|
|
'client' => $this->payment->client->present()->name(),
|
|
|
|
'invoice' => $invoice_texts]
|
|
|
|
));
|
2020-03-03 10:44:26 +01:00
|
|
|
}
|
|
|
|
}
|