Skip to content

Maithili fix overlapping dates create payment intent#2155

Open
maithili20 wants to merge 5 commits intodevelopmentfrom
maithili_fix_overlapping_dates_create_payment_intent
Open

Maithili fix overlapping dates create payment intent#2155
maithili20 wants to merge 5 commits intodevelopmentfrom
maithili_fix_overlapping_dates_create_payment_intent

Conversation

@maithili20
Copy link
Copy Markdown
Contributor

@maithili20 maithili20 commented Apr 7, 2026

Description

This PR fixes bugs in #1808
Payment Allowed for Unavailable (Overlapping) Booking Dates
There is an inconsistency in the booking flow where the system allows users to make a payment for dates that are already booked, but later prevents the actual booking.

Fixes # (bug list priority high/medium/low x.y.z)
Or Implements # (WBS)
Actual Result
Payment is successfully processed for overlapping dates.
Booking creation fails with error:
"Selected dates are unavailable. Please choose different dates."
Expected Result
The system should validate date availability before creating a payment intent.
Payment should be blocked if the selected dates overlap with an existing booking.

Related PRS (if any):

This is only Backend PR

Main changes explained:

  • modified bookingsController.js to fix the logic for overlapping dates and improve the code quality
  • introduced a new mode bookinghold.js which craetes a new collection in db that is used for checking hold on booking
  • added route for bookinghold in bookingRouter.js

How to test:

  1. Checkout the current branch.
  2. Run npm install (Ignore the deprecated warning for @paypal/checkout-server-sdk).
  3. Configure Environment Variables (.env):
    PayPal: Create a Sandbox App in the PayPal Developer Dashboard to generate your credentials. Add them to your .env:
    PAYPAL_CLIENT_ID=your_sandbox_client_id
    PAYPAL_CLIENT_SECRET=your_sandbox_secret
    Email: To test email notifications, configure the sender credentials.
    EMAIL_USER=your_email@gmail.com
    EMAIL_PASS=your_app_password
    Note: Do not use your standard login password. You must generate an App Password (if using Gmail, go to Google Account > Security > 2-Step Verification > App Passwords).
    Run the backend server (npm start).

Use Postman to test the flow:
Step 1: Generate Payment Intent

POST http://localhost:4500/api/lbdashboard/bookings/create-payment-intent
Body: { "listingId": "681fdf0e9b28a081622ba775", "startDate": "2026-05-03", "endDate": "2026-05-15", "currency": "USD" }
Expected: Returns a PayPal orderId.

Step 2: Create Booking (Happy Path)
POST http://localhost:4500/api/lbdashboard/bookings/book
Body: Use the orderId from Step 1. {
"listingId": "681fdf0e9b28a081622ba775",
"startDate": "2026-05-03",
"endDate": "2026-05-15",
"paypalOrderId": "order_id"
}
Expected: Returns 201 Created and triggers email notifications.

Step 3: Test Error Handling

  1. Create a payment intent as shown above. You will get orderId and verify the record is present in bookingholds in mongodb
Screenshot 2026-03-27 at 6 34 27 PM
  1. Now with the same user attempt to create another payment intent for overlapping dates using /bookings/create-payment-intent endpoint (Should work fine. expiresAt date in mongodb bookingholds should be updated to current time + 15mins )
Screenshot 2026-03-27 at 6 55 03 PM
  1. Create a booking . Verify that the document in bookingholds is deleted as the hold is now over and you will see successful API response
Screenshot 2026-03-27 at 6 56 04 PM
  1. Try booking a date range that is already booked (Should return "Selected dates are unavailable. Please choose different dates.).
Screenshot 2026-03-27 at 6 56 45 PM
  1. Repeat the step 1 of creating a payment intent. verify the result. Do not create a booking. Now login using another user. and create the payment intent for overapping dates. You should see an error message "Someone is currently in the booking process for this unit. Choose another one or check back in 15 minutes to see if it becomes available.",
Screenshot 2026-03-27 at 6 41 15 PM
  1. If the booking is already completed for selected dates. creating payment intent should give you "Selected dates are unavailable. Please choose different dates."
Screenshot 2026-04-07 at 3 37 09 PM

@maithili20 maithili20 added the High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible label Apr 8, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 9, 2026

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant