InvoiceNotification.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Notifications;
  3. use App\Models\Payment;
  4. use App\Models\User;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Notifications\Messages\MailMessage;
  7. use Illuminate\Notifications\Notification;
  8. use LaravelDaily\Invoices\Invoice;
  9. class InvoiceNotification extends Notification
  10. {
  11. use Queueable;
  12. /**
  13. * @var invoice
  14. * * @var invoice
  15. * * @var invoice
  16. */
  17. private $invoice;
  18. private $user;
  19. private $payment;
  20. /**
  21. * Create a new notification instance.
  22. *
  23. * @param Invoice $invoice
  24. */
  25. public function __construct(Invoice $invoice, User $user, Payment $payment)
  26. {
  27. $this->invoice = $invoice;
  28. $this->user = $user;
  29. $this->payment = $payment;
  30. }
  31. /**
  32. * Get the notification's delivery channels.
  33. *
  34. * @param mixed $notifiable
  35. * @return array
  36. */
  37. public function via($notifiable)
  38. {
  39. return ['mail'];
  40. }
  41. /**
  42. * Get the array representation of the notification.
  43. *
  44. * @param mixed $notifiable
  45. * @return MailMessage
  46. */
  47. public function toMail($notifiable)
  48. {
  49. return (new MailMessage)
  50. ->subject(__('Your Payment was successful!'))
  51. ->greeting(__('Hello').',')
  52. ->line(__('Your payment was processed successfully!'))
  53. ->line(__('Status').': '.$this->payment->status)
  54. ->line(__('Price').': '.$this->payment->formatToCurrency($this->payment->total_price))
  55. ->line(__('Type').': '.$this->payment->type)
  56. ->line(__('Amount').': '.$this->payment->amount)
  57. ->line(__('Balance').': '.number_format($this->user->credits, 2))
  58. ->line(__('User ID').': '.$this->payment->user_id)
  59. ->attach(storage_path('app/invoice/'.$this->user->id.'/'.now()->format('Y').'/'.$this->invoice->filename));
  60. }
  61. }