PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.8
Yatra – Travel Booking & Tour Operator Software v3.0.8
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / app / Core / Handlers / BookingConfirmationPageHandler.php

BookingConfirmationPageHandler.php in Yatra – Travel Booking & Tour Operator Software 3.0.8, at app/Core/Handlers/BookingConfirmationPageHandler.php

90 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // Configure $wp_query + virtual WP_Post so FSE block themes don't fall back to 404.html.
34 $this->setupPageEnvironment('singular', [
35 'title' => __('Booking Confirmation', 'yatra'),
36 'object_id' => (int) ($booking->id ?? 0),
37 'post_type' => 'page',
38 'post_name' => $confirmation_id,
39 ]);
40
41 // Set up global booking object
42 $this->setGlobal('yatra_booking', $booking);
43
44 // Set up query vars for backward compatibility
45 $this->setQueryVars([
46 'yatra_booking_confirmation' => $confirmation_id,
47 'yatra_booking' => $booking,
48 ]);
49
50 // Ensure the payment gateways are registered before the template renders.
51 // Gateways attach their confirmation-page hooks (e.g. Bank Transfer's
52 // `yatra_booking_confirmation_after_details` renderer) in their
53 // constructors, which only run once the registry is built. Without this,
54 // the confirmation page fires the hook with no gateway listening, so the
55 // bank-transfer account details never appear.
56 if (class_exists('\\Yatra\\PaymentGateways\\PaymentGatewayRegistry')) {
57 \Yatra\PaymentGateways\PaymentGatewayRegistry::getInstance();
58 }
59
60 // Process a PayPal return before the template renders. PayPal redirects
61 // the buyer back here with `?paypal=success` (a param only PayPal sets),
62 // so this runs only on a genuine PayPal return and affects nothing else.
63 // For Advanced mode it captures the approved order and confirms the
64 // booking; for Simple mode it is a no-op (the IPN webhook confirms).
65 // Idempotency is guaranteed by the gateway (paid-guard + transaction-id).
66 if (isset($_GET['paypal']) && sanitize_key((string) $_GET['paypal']) === 'success'
67 && class_exists('\\Yatra\\PaymentGateways\\PaymentGatewayRegistry')) {
68 $paypal = \Yatra\PaymentGateways\PaymentGatewayRegistry::getInstance()->get('paypal');
69 if ($paypal && method_exists($paypal, 'handlePaymentReturn')) {
70 try {
71 $paypal->handlePaymentReturn($booking, $bookingRepo);
72 $reloaded = $bookingRepo->findByConfirmationSegment($confirmation_id);
73 if ($reloaded) {
74 $booking = $reloaded;
75 $this->setGlobal('yatra_booking', $booking);
76 $this->setQueryVars([
77 'yatra_booking_confirmation' => $confirmation_id,
78 'yatra_booking' => $booking,
79 ]);
80 }
81 } catch (\Throwable $e) {
82 // Best-effort: the page still renders; the webhook can reconcile.
83 }
84 }
85 }
86
87 return $this->selectTemplate('booking-confirmation', null, 'booking-confirmation');
88 }
89 }
90