ctrlpanel/app/Notifications/InvoiceNotification.php

70 lines
1.8 KiB
PHP
Raw Normal View History

2021-11-27 01:47:36 +00:00
<?php
namespace App\Notifications;
2021-11-30 17:40:56 +00:00
use App\Models\Payment;
2021-11-30 17:18:15 +00:00
use App\Models\User;
2021-11-27 01:47:36 +00:00
use Illuminate\Bus\Queueable;
2021-11-30 13:09:13 +00:00
use Illuminate\Notifications\Messages\MailMessage;
2021-11-27 01:47:36 +00:00
use Illuminate\Notifications\Notification;
use LaravelDaily\Invoices\Invoice;
class InvoiceNotification extends Notification
{
use Queueable;
2021-11-30 17:40:56 +00:00
2021-11-27 01:47:36 +00:00
/**
* @var invoice
2021-11-30 17:18:15 +00:00
* * @var invoice
* * @var invoice
2021-11-27 01:47:36 +00:00
*/
private $invoice;
2021-11-30 17:18:15 +00:00
private $user;
private $payment;
2021-11-27 01:47:36 +00:00
/**
* Create a new notification instance.
*
* @param Invoice $invoice
*/
2021-11-30 17:18:15 +00:00
public function __construct(Invoice $invoice, User $user, Payment $payment)
2021-11-27 01:47:36 +00:00
{
$this->invoice = $invoice;
2021-11-30 17:18:15 +00:00
$this->user = $user;
$this->payment = $payment;
2021-11-27 01:47:36 +00:00
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
2021-11-30 13:09:13 +00:00
return ['mail'];
2021-11-27 01:47:36 +00:00
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
2021-11-30 13:09:13 +00:00
* @return MailMessage
2021-11-27 01:47:36 +00:00
*/
2021-11-30 13:09:13 +00:00
public function toMail($notifiable)
2021-11-27 01:47:36 +00:00
{
2021-11-30 13:09:13 +00:00
return (new MailMessage)
2021-11-30 17:18:15 +00:00
->subject('Your Payment was successful!')
->greeting('Hello,')
2021-12-02 11:29:48 +00:00
->line("Your payment was processed successfully!")
2021-11-30 17:40:56 +00:00
->line('Status: ' . $this->payment->status)
->line('Price: ' . $this->payment->formatToCurrency($this->payment->total_price))
->line('Type: ' . $this->payment->type)
->line('Amount: ' . $this->payment->amount)
2021-12-02 11:01:11 +00:00
->line('Balance: ' . number_format($this->user->credits,2))
2021-11-30 17:40:56 +00:00
->line('User ID: ' . $this->payment->user_id)
->attach(storage_path('app/invoice/' . $this->user->id . '/' . now()->format('Y') . '/' . $this->invoice->filename));
2021-11-27 01:47:36 +00:00
}
}