| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Core\Handlers; |
| 6 |
|
| 7 |
use Yatra\Repositories\BookingRepository; |
| 8 |
|
| 9 |
/** |
| 10 |
* Checkout Page Handler |
| 11 |
* |
| 12 |
* Handles remaining checkout page requests |
| 13 |
*/ |
| 14 |
class CheckoutPageHandler extends BasePageHandler |
| 15 |
{ |
| 16 |
/** |
| 17 |
* Handle checkout 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 |
$token = $route_data['token']; |
| 25 |
|
| 26 |
// Validate checkout token |
| 27 |
$bookingRepo = new BookingRepository(); |
| 28 |
$booking = $bookingRepo->findByCheckoutToken($token); |
| 29 |
|
| 30 |
if (!$booking) { |
| 31 |
wp_die(__('Invalid checkout link.', 'yatra')); |
| 32 |
} |
| 33 |
|
| 34 |
// Configure $wp_query + virtual WP_Post so FSE block themes don't fall back to 404.html. |
| 35 |
$this->setupPageEnvironment('singular', [ |
| 36 |
'title' => __('Checkout', 'yatra'), |
| 37 |
// Keep the virtual post ID at 0 (like the account/login/booking |
| 38 |
// handlers). Using the booking row id made get_queried_object_id() |
| 39 |
// collide with a real wp_posts row of the same id, so SEO plugins / |
| 40 |
// WordPress emitted THAT page's SEO on this page. The booking is read |
| 41 |
// from the `yatra_booking` global, so no queried-object id is needed. |
| 42 |
'object_id' => 0, |
| 43 |
'post_type' => 'page', |
| 44 |
'post_name' => $token, |
| 45 |
]); |
| 46 |
|
| 47 |
// Set up global booking object |
| 48 |
$this->setGlobal('yatra_booking', $booking); |
| 49 |
|
| 50 |
// Set up query vars for backward compatibility |
| 51 |
$this->setQueryVars([ |
| 52 |
'yatra_remaining_checkout' => $token, |
| 53 |
'yatra_booking' => $booking, |
| 54 |
]); |
| 55 |
|
| 56 |
return $this->selectTemplate('checkout', null, 'checkout'); |
| 57 |
} |
| 58 |
} |
| 59 |
|