-
app/Notifications/ReservationPaymentSuccesful.php
Open in GitHubuse App\Models\Reservation; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; class ReservationPaymentSuccesful extends Notification { use Queueable; private Reservation $reservation; public function __construct(Reservation $reservation) { $this->reservation = $reservation; } public function via($notifiable) { return ['mail']; } public function toMail($notifiable) { $amount = number_format($this->reservation->paid_amount / 100, 2); return (new MailMessage) ->from('noreply@parkingsystem.com', 'Parking system name') ->subject("Reservation {$this->reservation->id} paid successfully") ->line("{$amount}USD paid for Reservation #{$this->reservation->id} ({$this->reservation->start->format('d-m-Y H:i')} - {$this->reservation->end->format('d-m-Y H:i')}) has been paid successfully") ->line('Thank you for using our parking!'); } // }
-
app/Http/Controllers/WebhookController.php
Open in GitHubuse App\Models\Reservation; use App\Notifications\ReservationPaymentSuccesful; use Illuminate\Http\JsonResponse; use Illuminate\Support\Arr; use Laravel\Cashier\Http\Controllers\WebhookController as CashierController; class WebhookController extends CashierController { public function handleCheckoutSessionCompleted(array $payload): JsonResponse { $reservation = Reservation::findOrFail(Arr::get($payload, 'data.object.metadata.reservationId')); $reservation->update([ 'paid_at' => Arr::get($payload, 'created'), 'paid_amount' => Arr::get($payload, 'data.object.amount_total'), ]); $reservation->user->notify(new ReservationPaymentSuccesful($reservation)); return response()->json('', 200); } }