ldc-boutique-cnc/app/Notifications/Order/OrderIsPayed.php
2023-05-02 10:55:02 +02:00

104 lines
2.9 KiB
PHP

<?php
namespace App\Notifications\Order;
use App\Models\Payment\Transaction;
use App\Models\Shop\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class OrderIsPayed extends Notification
{
use Queueable;
/**
* Order
*
* @var \App\Models\Shop\Order
*/
private $order;
/**
* Order
*
* @var \App\Models\Payment\Transaction
*/
private $transaction;
/**
* Create a new notification instance.
*
* @param \App\Models\Shop\Order $order
* @param \App\Models\Payment\Transaction $transaction
* @return void
*/
public function __construct(Order $order, Transaction $transaction)
{
$this->order = $order;
$this->transaction = $transaction;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
public function via($notifiable)
{
// phpcs:enable
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
public function toMail($notifiable)
{
// phpcs:enable
$title = trans('Commande du :date - :orderRef - :transRef', [
'date' => $this->transaction->created_at->isoFormat('DD\/MM\/YYYY'),
'orderRef' => $this->order->reference,
'transRef' => $this->transaction->reference,
]);
return (new MailMessage())
->subject(\trans('Nous avons bien reçu votre paiement - :appname', ['appname' => \config('app.name')]))
->greeting(trans('Votre commande avec pour référence :ref à été payée', [
'ref' => $this->order->reference
]))
->line(\trans(
'Vous pouvez retrouver les informations la concernant, ainsi que le créneau de collecte
qui vous est réservé, depuis votre espace personel.'
))->attachData(
$this->transaction->generateInvoice($title)->output(),
$title . '.pdf',
[
'as' => $title . '.pdf',
'mime' => 'application/pdf',
]
);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
public function toArray($notifiable)
{
// phpcs:enable
return [
'order_id' => $this->order->id
];
}
}