This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user