← All changes
|
app/PaymentGateways/Gateways/PayPal/PayPalGateway.php
+11
-6
3.0.11
→
3.0.17
View file →
| @@ -197,9 +197,12 @@ | ||
| 197 | 197 | __('Booking #%s', 'yatra'), |
| 198 | 198 | $reference |
| 199 | 199 | ); |
| 200 | 200 | $returnUrl = $paymentData['return_url'] ?? yatra_get_booking_confirmation_url((string) $reference); |
| 201 | - $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)); | |
| 202 | 205 | |
| 203 | 206 | // PayPal Standard base URL |
| 204 | 207 | $isTestMode = \Yatra\Services\SettingsService::isPaymentTestMode(); |
| 205 | 208 | $paypalUrl = $isTestMode |
| @@ -255,9 +258,11 @@ | ||
| 255 | 258 | $currency = $paymentData['currency'] ?? 'USD'; |
| 256 | 259 | $bookingId = $paymentData['booking_id'] ?? 0; |
| 257 | 260 | $referenceForReturn = (string) ($paymentData['reference'] ?? $bookingId); |
| 258 | 261 | $returnUrl = $paymentData['return_url'] ?? yatra_get_booking_confirmation_url($referenceForReturn); |
| 259 | - $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)); | |
| 260 | 265 | $savePayment = !empty($paymentData['save_payment']); |
| 261 | 266 | |
| 262 | 267 | $orderData = [ |
| 263 | 268 | 'intent' => 'CAPTURE', |
| @@ -874,11 +879,11 @@ | ||
| 874 | 879 | $newAmountPaid = (float) ($booking->amount_paid ?? 0) + $amount; |
| 875 | 880 | $newAmountDue = max(0.0, $totalAmount - $newAmountPaid); |
| 876 | 881 | $paymentStatus = $newAmountDue <= 0.01 ? 'paid' : 'partial'; |
| 877 | 882 | |
| 878 | - // Only auto-confirm when the operator allows it (or fully paid). A | |
| 879 | - // deposit / partial payment must not confirm when "Auto-Confirm | |
| 880 | - // Bookings" is off — the operator confirms it manually. | |
| 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. | |
| 881 | 886 | $shouldConfirm = \yatra_should_confirm_booking_on_payment($newAmountDue <= 0.01, $bookingId); |
| 882 | 887 | |
| 883 | 888 | // Update booking payment status |
| 884 | 889 | $bookings_table = BookingsTable::getTableName(); |
| @@ -924,9 +929,9 @@ | ||
| 924 | 929 | 'payment_status' => $paymentStatus, |
| 925 | 930 | ]); |
| 926 | 931 | |
| 927 | 932 | if ($shouldConfirm) { |
| 928 | - \yatra_trigger_booking_confirmed($bookingId, $previousBookingStatus); | |
| 933 | + \yatra_trigger_booking_confirmed($bookingId, $previousBookingStatus, true); | |
| 929 | 934 | } |
| 930 | 935 | |
| 931 | 936 | // Fire action for other plugins/services |
| 932 | 937 | do_action('yatra_payment_completed', [ |