findByConfirmationSegment($confirmation_id); if (!$booking) { return false; } // Configure $wp_query + virtual WP_Post so FSE block themes don't fall back to 404.html. $this->setupPageEnvironment('singular', [ 'title' => __('Booking Confirmation', 'yatra'), // Keep the virtual post ID at 0 (like the account/login/booking // handlers). Using the booking row id made get_queried_object_id() // collide with a real wp_posts row of the same id, so SEO plugins / // WordPress emitted THAT page's title, description and OG tags on the // confirmation page. The booking is read from the `yatra_booking` // global, so no queried-object id is needed here. 'object_id' => 0, 'post_type' => 'page', 'post_name' => $confirmation_id, ]); // Set up global booking object $this->setGlobal('yatra_booking', $booking); // Set up query vars for backward compatibility $this->setQueryVars([ 'yatra_booking_confirmation' => $confirmation_id, 'yatra_booking' => $booking, ]); // Ensure the payment gateways are registered before the template renders. // Gateways attach their confirmation-page hooks (e.g. Bank Transfer's // `yatra_booking_confirmation_after_details` renderer) in their // constructors, which only run once the registry is built. Without this, // the confirmation page fires the hook with no gateway listening, so the // bank-transfer account details never appear. if (class_exists('\\Yatra\\PaymentGateways\\PaymentGatewayRegistry')) { \Yatra\PaymentGateways\PaymentGatewayRegistry::getInstance(); } // Process a PayPal return before the template renders. PayPal redirects // the buyer back here with `?paypal=success` (a param only PayPal sets), // so this runs only on a genuine PayPal return and affects nothing else. // For Advanced mode it captures the approved order and confirms the // booking; for Simple mode it is a no-op (the IPN webhook confirms). // Idempotency is guaranteed by the gateway (paid-guard + transaction-id). if (isset($_GET['paypal']) && sanitize_key((string) $_GET['paypal']) === 'success' && class_exists('\\Yatra\\PaymentGateways\\PaymentGatewayRegistry')) { $paypal = \Yatra\PaymentGateways\PaymentGatewayRegistry::getInstance()->get('paypal'); if ($paypal && method_exists($paypal, 'handlePaymentReturn')) { try { $paypal->handlePaymentReturn($booking, $bookingRepo); $reloaded = $bookingRepo->findByConfirmationSegment($confirmation_id); if ($reloaded) { $booking = $reloaded; $this->setGlobal('yatra_booking', $booking); $this->setQueryVars([ 'yatra_booking_confirmation' => $confirmation_id, 'yatra_booking' => $booking, ]); } } catch (\Throwable $e) { // Best-effort: the page still renders; the webhook can reconcile. } } } return $this->selectTemplate('booking-confirmation', null, 'booking-confirmation'); } }