151 lines
4.4 KiB
PHP
151 lines
4.4 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 OrderHasBeenRefunded extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
/**
|
|
* Order
|
|
*
|
|
* @var \App\Models\Shop\Order
|
|
*/
|
|
private $order;
|
|
|
|
/**
|
|
* Transaction that was refund
|
|
*
|
|
* @var \App\Models\Payment\Transaction
|
|
*/
|
|
private $transaction;
|
|
|
|
/**
|
|
* IS the order completely refunded
|
|
*
|
|
* @var boolean
|
|
*/
|
|
private $completely;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*
|
|
* @param \App\Models\Shop\Order $order
|
|
* @param \App\Models\Payment\Transaction $transaction
|
|
* @param boolean $completely
|
|
* @return void
|
|
*/
|
|
public function __construct(Order $order, Transaction $transaction, bool $completely)
|
|
{
|
|
$this->order = $order;
|
|
$this->transaction = $transaction;
|
|
$this->completely = $completely;
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
$mailable = (new MailMessage());
|
|
|
|
if ($this->completely) {
|
|
$mailable->subject(
|
|
\trans('Remboursement complet de votre commande - :appname', [
|
|
'appname' => \config('app.name')
|
|
])
|
|
);
|
|
} else {
|
|
$mailable->subject(
|
|
\trans('Remboursement partiel de votre commande - :appname', [
|
|
'appname' => \config('app.name')
|
|
])
|
|
);
|
|
}
|
|
|
|
$mailable->greeting(trans('Votre commande avec pour référence :ref à fait l\'objet d\'un remboursement', [
|
|
'ref' => $this->order->reference
|
|
]));
|
|
|
|
if ($this->completely) {
|
|
$mailable->line(
|
|
\trans('Votre commande ne pouvant être honorée,
|
|
nous avons effectué un remboursement complet de votre commande.')
|
|
);
|
|
} else {
|
|
$mailable->line(
|
|
\trans('Une partie de votre commande ne pouvant être honorée,
|
|
nous avons effectué un remboursement partiel de votre commande.
|
|
Vous pourrez récupérer comme convenu le restant de votre commande.')
|
|
);
|
|
}
|
|
|
|
$mailable->line(
|
|
\trans('Si vous avez effectué le paiement sur notre plateforme, vous devriez
|
|
voir dans un delais, qui varier peut selon votre banque, un remboursement par le même
|
|
moyen de paiement que vous avez utilisé sur notre plateforme.')
|
|
);
|
|
|
|
$mailable->line(\trans(
|
|
'Vous pouvez retrouver les informations de votre commande depuis votre espace personel.
|
|
Vous trouverez également ci-joint votre facture d\'avoir.'
|
|
));
|
|
|
|
$mailable->line(\trans('Toute nos excuses pour la gêne occasionnée.'));
|
|
|
|
$title = trans('Commande du :date - :orderRef - :transRef', [
|
|
'date' => $this->transaction->created_at->isoFormat('DD\/MM\/YYYY'),
|
|
'orderRef' => $this->order->reference,
|
|
'transRef' => $this->transaction->reference,
|
|
]);
|
|
$mailable->attachData(
|
|
$this->transaction->generateInvoice($title)->output(),
|
|
$title . '.pdf',
|
|
[
|
|
'as' => $title . '.pdf',
|
|
'mime' => 'application/pdf',
|
|
]
|
|
);
|
|
|
|
return $mailable;
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
];
|
|
}
|
|
}
|