UoaWDCC / uasc-web

Project with the University of Auckland Snowsports Club Website & Booking System. Established in 2023.
https://uasc.co.nz
6 stars 2 forks source link

530 expire checkout sessions last spot #556

Closed AzizPatel786 closed 4 months ago

github-actions[bot] commented 4 months ago

Visit the preview URL for this PR (updated for commit 11ed293):

https://uasc-ceebc--pr556-530-expire-checkout-6ndmlu9a.web.app

(expires Thu, 11 Jul 2024 22:01:16 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 36296ceaed1d43e92e7d5e81a72a7bd987560bfa

bcho892 commented 4 months ago

Ok, I think I should give some background on how all the dates work on stripe:

We have booking_slots which refer to the date and has a max_bookings. The way we calculate the availability is:

  1. check how many slots there are in the bookings collection - which refers to individual bookings made, no date data is stored in there, instead it has a field that refers to an id of a booking_slot
  2. the available slots for a booking_slot is: the max_bookings minus the amount of bookings pointing to a booking_slot
  3. in case of displaying availability to the user we also minus off the amount of checkout sessions that have that booking_slot's id in its metadata

The way we use this with stripe is when we create a checkout session we add an array of dates pointing to the booking_slot id (serialised as a string with JSON.stringify) to the metadata.

You will have to get the checkout session and JSON.parse the metadata to find the relevant checkout session ids that include the now fully booked dates.

bcho892 commented 4 months ago

Good job,pretty much the right logic,