PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.17
Yatra – Travel Booking & Tour Operator Software v3.0.17
3.0.17 3.0.16 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 All 85 releases
← All changes | app/PaymentGateways/Gateways/PayPal/PayPalGateway.php +48 -11 3.0.7 → 3.0.17 View file →
@@ -17,8 +17,27 @@
17 17 protected string $icon = 'paypal.svg';
18 18 protected string $sandboxUrl = 'https://developer.paypal.com/tools/sandbox/';
19 19 protected array $supports = ['paypal', 'credit_card', 'refunds', 'recurring', 'tokenization'];
20 20
21 + /**
22 + * Translatable display title. The raw `$title` property can't carry a
23 + * `__()` call (PHP property defaults must be constant), so the customer-
24 + * facing label is translated here. An admin-set custom title (via gateway
25 + * config) still takes precedence in PaymentGatewayRegistry::getForCheckout().
26 + */
27 + public function getTitle(): string
28 + {
29 + return __('PayPal', 'yatra');
30 + }
31 +
32 + /**
33 + * Translatable description shown under the gateway option at checkout.
34 + */
35 + public function getDescription(): string
36 + {
37 + return __('Accept PayPal and credit card payments', 'yatra');
38 + }
39 +
21 40 public function getConfigFields(): array
22 41 {
23 42 return [
24 43 [
@@ -178,9 +197,12 @@
178 197 __('Booking #%s', 'yatra'),
179 198 $reference
180 199 );
181 200 $returnUrl = $paymentData['return_url'] ?? yatra_get_booking_confirmation_url((string) $reference);
182 - $cancelUrl = $paymentData['cancel_url'] ?? home_url('/book/?payment=cancelled&ref=' . $reference);
201 + // Cancel returns must land on the booking-confirmation page (a route that always
202 + // resolves). The legacy `home_url('/book/?...')` 404s whenever the booking base is
203 + // customised or a custom booking page is used — see RouteMatcher::matchBookingRoute().
204 + $cancelUrl = $paymentData['cancel_url'] ?? add_query_arg('payment', 'cancelled', yatra_get_booking_confirmation_url((string) $reference));
183 205
184 206 // PayPal Standard base URL
185 207 $isTestMode = \Yatra\Services\SettingsService::isPaymentTestMode();
186 208 $paypalUrl = $isTestMode
@@ -236,9 +258,11 @@
236 258 $currency = $paymentData['currency'] ?? 'USD';
237 259 $bookingId = $paymentData['booking_id'] ?? 0;
238 260 $referenceForReturn = (string) ($paymentData['reference'] ?? $bookingId);
239 261 $returnUrl = $paymentData['return_url'] ?? yatra_get_booking_confirmation_url($referenceForReturn);
240 - $cancelUrl = $paymentData['cancel_url'] ?? home_url('/book/?payment=cancelled');
262 + // Cancel returns must land on the booking-confirmation page (always resolvable);
263 + // the legacy `home_url('/book/?...')` 404s under a custom booking base/page.
264 + $cancelUrl = $paymentData['cancel_url'] ?? add_query_arg('payment', 'cancelled', yatra_get_booking_confirmation_url($referenceForReturn));
241 265 $savePayment = !empty($paymentData['save_payment']);
242 266
243 267 $orderData = [
244 268 'intent' => 'CAPTURE',
@@ -855,21 +879,32 @@
855 879 $newAmountPaid = (float) ($booking->amount_paid ?? 0) + $amount;
856 880 $newAmountDue = max(0.0, $totalAmount - $newAmountPaid);
857 881 $paymentStatus = $newAmountDue <= 0.01 ? 'paid' : 'partial';
858 882
883 + // Only auto-confirm when "Auto-Confirm Bookings" is on; otherwise the
884 + // booking stays pending for the operator to confirm manually, regardless
885 + // of a successful (full or partial) payment.
886 + $shouldConfirm = \yatra_should_confirm_booking_on_payment($newAmountDue <= 0.01, $bookingId);
887 +
859 888 // Update booking payment status
860 889 $bookings_table = BookingsTable::getTableName();
890 + $bookingUpdate = [
891 + 'payment_status' => $paymentStatus,
892 + 'amount_paid' => $newAmountPaid,
893 + 'amount_due' => $newAmountDue,
894 + ];
895 + $bookingUpdateFormat = ['%s', '%f', '%f'];
896 + if ($shouldConfirm) {
897 + $bookingUpdate['status'] = 'confirmed';
898 + $bookingUpdate['confirmed_at'] = current_time('mysql');
899 + $bookingUpdateFormat[] = '%s';
900 + $bookingUpdateFormat[] = '%s';
901 + }
861 902 $wpdb->update(
862 903 $bookings_table,
863 - [
864 - 'payment_status' => $paymentStatus,
865 - 'amount_paid' => $newAmountPaid,
866 - 'amount_due' => $newAmountDue,
867 - 'status' => 'confirmed',
868 - 'confirmed_at' => current_time('mysql'),
869 - ],
904 + $bookingUpdate,
870 905 ['id' => $bookingId],
871 - ['%s', '%f', '%f', '%s', '%s'],
906 + $bookingUpdateFormat,
872 907 ['%d']
873 908 );
874 909
875 910 // Record the payment (note: column is `gateway`, not `payment_gateway`).
@@ -893,9 +928,11 @@
893 928 'amount' => $amount,
894 929 'payment_status' => $paymentStatus,
895 930 ]);
896 931
897 - \yatra_trigger_booking_confirmed($bookingId, $previousBookingStatus);
932 + if ($shouldConfirm) {
933 + \yatra_trigger_booking_confirmed($bookingId, $previousBookingStatus, true);
934 + }
898 935
899 936 // Fire action for other plugins/services
900 937 do_action('yatra_payment_completed', [
901 938 'booking_id' => $bookingId,