When a Paybox callback confirms payment on an order with status 4 (Annulé), the payment is still recorded but the order status is no longer forced to « Préparation ». Instead, an alert email is sent to ``commande@jardinenvie.com`` warning that a refund is likely needed. New ``AlertePaiementAnnule`` mailable with DB template providing order ref, amount, customer info and payment reference. New method ``OrderMails::sendCancelledOrderPaymentAlert()`` handles the dispatch.
64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Mail\Acheminement;
|
|
use App\Mail\AlertePaiementAnnule;
|
|
use App\Mail\ConfirmationCommande;
|
|
use App\Mail\Preparation;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class OrderMails
|
|
{
|
|
public static function testSend($id)
|
|
{
|
|
self::sendPreparation($id);
|
|
}
|
|
|
|
public static function sendOrderConfirmed($orderId)
|
|
{
|
|
$order = Orders::get($orderId, ['customer', 'delivery_address']);
|
|
$mail = new ConfirmationCommande($order);
|
|
|
|
return Mail::to($order->customer->email)->send($mail);
|
|
}
|
|
|
|
public static function sendPreparation($orderId)
|
|
{
|
|
$order = Orders::get($orderId, ['customer', 'delivery_address']);
|
|
$mail = new Preparation($order);
|
|
|
|
return Mail::to($order->customer->email)->send($mail);
|
|
}
|
|
|
|
public static function sendShipping($orderId)
|
|
{
|
|
$order = Orders::get($orderId, ['customer', 'delivery_address']);
|
|
$mail = new Acheminement($order);
|
|
|
|
return Mail::to($order->customer->email)->send($mail);
|
|
}
|
|
|
|
public static function sendCancelledOrderPaymentAlert($orderId, $reference)
|
|
{
|
|
$order = Orders::get($orderId, ['customer']);
|
|
|
|
try {
|
|
Mail::to('commande@jardinenvie.com')
|
|
->send(new AlertePaiementAnnule($order, $reference));
|
|
Log::info('Cancelled order payment alert sent', [
|
|
'order_id' => $orderId,
|
|
'order_ref' => $order->ref,
|
|
'reference' => $reference,
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
Log::error('Failed to send cancelled order payment alert', [
|
|
'order_id' => $orderId,
|
|
'order_ref' => $order->ref,
|
|
'exception' => $e->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
}
|