This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<x-mail::message>
|
||||
# New EV Booking ( {{ $booking->ref_no }} )
|
||||
A new EV booking was created at {{ $booking->created_at }}.
|
||||
|
||||
**Booking Summary**
|
||||
- **Route:** {{ $booking->route->name ?? 'N/A' }}
|
||||
- **Seat Options:** {{ $booking->vehicleOptions->map(fn($b) => "{$b->passenger_count} x {$b->vehicle_option->value}")->implode(', ') }}
|
||||
- **Pickup Location:** {{ $booking->pickup_address ?? 'N/A' }}
|
||||
- **Dropoff Location:** {{ $booking->dropoff_address ?? 'N/A' }}
|
||||
- **Travel Date:** {{ $booking->travel_date ?? 'N/A' }}
|
||||
- **Total Price:** {{ $booking->price ?? 'N/A' }}
|
||||
|
||||
{{-- @if(!empty($booking->notes))
|
||||
**Notes:**<br>
|
||||
{{ $booking->notes }}
|
||||
@endif --}}
|
||||
|
||||
Payment Method: {{ ($payment->gateway ?? 'N/A') }}
|
||||
<br>
|
||||
Contact Info: {{ ($booking->passenger_name ?? '') }} {{ $booking->passenger_phone ?? '' }}
|
||||
<br>
|
||||
Channel: {{ $booking->created_by_channel ?? '-' }}
|
||||
|
||||
<x-mail::button :url="$url">
|
||||
View Booking
|
||||
</x-mail::button>
|
||||
|
||||
Auto generated from<br>
|
||||
{{ config('app.name') }}
|
||||
</x-mail::message>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Modules\Booking\Filament\Resources\Bookings\BookingResource;
|
||||
use Modules\Booking\Models\Booking;
|
||||
use Modules\Payment\Models\Payment;
|
||||
|
||||
class NewBookingAlert extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public Booking $booking;
|
||||
|
||||
public string $url;
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(public Payment $payment)
|
||||
{
|
||||
$this->booking = $payment->booking;
|
||||
$this->url = BookingResource::getUrl('view', ['record' => $this->booking]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'FamousLY4 New Booking Alert',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'payment::mails.new-booking-alert',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Observers;
|
||||
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Modules\Payment\Enums\PaymentStatus;
|
||||
use Modules\Payment\Mail\NewBookingAlert;
|
||||
use Modules\Payment\Models\Payment;
|
||||
|
||||
class PaymentObserver
|
||||
{
|
||||
public function created(Payment $payment): void
|
||||
{
|
||||
if ($payment->status === PaymentStatus::Failed) return;
|
||||
|
||||
try {
|
||||
$admin_emails = config('booking.admin_emails');
|
||||
|
||||
Mail::bcc($admin_emails)->queue(new NewBookingAlert($payment));
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception or handle it as needed
|
||||
\Log::error('Failed to send NewBookingAlert email: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function updated(Payment $payment): void
|
||||
{
|
||||
// Handle the event when a payment is updated for a booking
|
||||
}
|
||||
|
||||
public function deleted(Payment $payment): void
|
||||
{
|
||||
// Handle the event when a payment is deleted for a booking
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ use Modules\Payment\Factories\PaymentGatewayFactory;
|
||||
use Modules\Payment\Gateways\KbzMiniAppGateway;
|
||||
use Modules\Payment\Listeners\MarkBookingPaid;
|
||||
use Modules\Payment\Listeners\MarkBookingRefunded;
|
||||
use Modules\Payment\Models\Payment;
|
||||
use Modules\Payment\Observers\PaymentObserver;
|
||||
|
||||
class PaymentServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -28,5 +30,7 @@ class PaymentServiceProvider extends ServiceProvider
|
||||
{
|
||||
Event::listen(PaymentCompleted::class, MarkBookingPaid::class);
|
||||
Event::listen(RefundProcessed::class, MarkBookingRefunded::class);
|
||||
|
||||
Payment::observe(PaymentObserver::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Routing\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -91,4 +92,11 @@ class EvRoute extends Model
|
||||
{
|
||||
return $this->hasMany(RoutePricing::class, 'ev_route_id');
|
||||
}
|
||||
|
||||
public function name(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn (): string => $this->fromDestination->name.' → '.$this->toDestination->name,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,4 +29,6 @@ return [
|
||||
|
||||
'front_seat_max_per_booking' => env('BOOKING_FRONT_SEAT_MAX_PER_BOOKING', 1),
|
||||
|
||||
// comma-separated list of admin emails to notify on booking events
|
||||
'admin_emails' => explode(',', env('BOOKING_ADMIN_EMAILS', 'admin@example.com')),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user