| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Core\Handlers; |
| 6 |
|
| 7 |
use Yatra\Repositories\BookingRepository; |
| 8 |
|
| 9 |
/** |
| 10 |
* Booking Confirmation Page Handler |
| 11 |
* |
| 12 |
* Handles booking confirmation page requests |
| 13 |
*/ |
| 14 |
class BookingConfirmationPageHandler extends BasePageHandler |
| 15 |
{ |
| 16 |
/** |
| 17 |
* Handle booking confirmation page request |
| 18 |
* |
| 19 |
* @param array $route_data Route data from RouteMatcher |
| 20 |
* @return bool True if handled successfully |
| 21 |
*/ |
| 22 |
public function handle(array $route_data): bool |
| 23 |
{ |
| 24 |
$confirmation_id = (string) ($route_data['confirmation_id'] ?? ''); |
| 25 |
|
| 26 |
$bookingRepo = new BookingRepository(); |
| 27 |
$booking = $bookingRepo->findByConfirmationSegment($confirmation_id); |
| 28 |
|
| 29 |
if (!$booking) { |
| 30 |
return false; |
| 31 |
} |
| 32 |
|
| 33 |
// Prevent 404 handling |
| 34 |
$this->prevent404(); |
| 35 |
|
| 36 |
// Load trip attributes for booking confirmation display |
| 37 |
if ($booking && !empty($booking->trip_id)) { |
| 38 |
try { |
| 39 |
$singleTripController = new \Yatra\Controllers\SingleTripController(); |
| 40 |
// Use reflection to access private method |
| 41 |
$reflection = new \ReflectionClass($singleTripController); |
| 42 |
$method = $reflection->getMethod('getTripAttributes'); |
| 43 |
$method->setAccessible(true); |
| 44 |
$attributes = $method->invoke($singleTripController, (int) $booking->trip_id); |
| 45 |
|
| 46 |
// Create a simple list of attribute names for tag display |
| 47 |
$booking->trip_attributes_list = array_map(function($attr) { |
| 48 |
return $attr['name']; |
| 49 |
}, $attributes); |
| 50 |
} catch (\Throwable $e) { |
| 51 |
$booking->trip_attributes_list = []; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
// Set up global booking object |
| 56 |
$this->setGlobal('yatra_booking', $booking); |
| 57 |
|
| 58 |
// Set up query vars for backward compatibility |
| 59 |
$this->setQueryVars([ |
| 60 |
'yatra_booking_confirmation' => $confirmation_id, |
| 61 |
'yatra_booking' => $booking, |
| 62 |
]); |
| 63 |
|
| 64 |
// Load the booking confirmation template |
| 65 |
$template_path = YATRA_PLUGIN_PATH . 'templates/booking-confirmation.php'; |
| 66 |
|
| 67 |
if (!file_exists($template_path)) { |
| 68 |
$this->logError("Booking confirmation template not found: {$template_path}"); |
| 69 |
return false; |
| 70 |
} |
| 71 |
|
| 72 |
include $template_path; |
| 73 |
$this->exit(); |
| 74 |
|
| 75 |
return true; |
| 76 |
} |
| 77 |
} |
| 78 |
|