Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Melcus/parking-system

10 stars
2 code files
View Melcus/parking-system on GitHub

app/Notifications/ReservationPaymentSuccesful.php

Open in GitHub
use 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('[email protected]', '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 GitHub
use 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);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.