← All changes
|
app/PaymentGateways/Gateways/PayPal/PayPalGateway.php
+29
-11
3.0.9
→
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,21 +879,32 @@ | ||
| 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 | |
| 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 | + | |
| 878 | 888 | // Update booking payment status |
| 879 | 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 | + } | |
| 880 | 902 | $wpdb->update( |
| 881 | 903 | $bookings_table, |
| 882 | - [ | |
| 883 | - 'payment_status' => $paymentStatus, | |
| 884 | - 'amount_paid' => $newAmountPaid, | |
| 885 | - 'amount_due' => $newAmountDue, | |
| 886 | - 'status' => 'confirmed', | |
| 887 | - 'confirmed_at' => current_time('mysql'), | |
| 888 | - ], | |
| 904 | + $bookingUpdate, | |
| 889 | 905 | ['id' => $bookingId], |
| 890 | - ['%s', '%f', '%f', '%s', '%s'], | |
| 906 | + $bookingUpdateFormat, | |
| 891 | 907 | ['%d'] |
| 892 | 908 | ); |
| 893 | 909 | |
| 894 | 910 | // Record the payment (note: column is `gateway`, not `payment_gateway`). |
| @@ -912,9 +928,11 @@ | ||
| 912 | 928 | 'amount' => $amount, |
| 913 | 929 | 'payment_status' => $paymentStatus, |
| 914 | 930 | ]); |
| 915 | 931 | |
| 916 | - \yatra_trigger_booking_confirmed($bookingId, $previousBookingStatus); | |
| 932 | + if ($shouldConfirm) { | |
| 933 | + \yatra_trigger_booking_confirmed($bookingId, $previousBookingStatus, true); | |
| 934 | + } | |
| 917 | 935 | |
| 918 | 936 | // Fire action for other plugins/services |
| 919 | 937 | do_action('yatra_payment_completed', [ |
| 920 | 938 | 'booking_id' => $bookingId, |