> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt ## Resource: Bookings ## Article: Sample Flows ## Article Link: https://dev.wix.com/docs/velo/apis/wix-bookings-v2/bookings/sample-flows.md ## Article Content: # Bookings: Sample Use Cases and Flows This article shares basic flows your code could support. You're certainly not limited to these use cases, but they can be a helpful jumping-off point for your planning. Your code could add bookings to the business calendar. These bookings can be for all types of services: appointment-based, classes, and courses. You can also use all [Wix eCommerce](https://dev.wix.com/docs/velo/api-reference/wix-ecom-backend/introduction.md)-supported payment methods, along with [Wix Pricing Plans](https://dev.wix.com/docs/velo/api-reference/wix-pricing-plans-v2/introduction.md). ## Book an appointment Your code could display available time slots for appointment-based services to customers, let them choose a slot, create the related booking, and handle the payment process using [Wix eCommerce](https://dev.wix.com/docs/velo/api-reference/wix-ecom-backend/introduction.md). ### Part 1: Book an appointment 1. Use [queryServices()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/services/query-services.md) and pass `{"type": "APPOINTMENT"}` as a filter to retrieve all appointment-based services. 1. Display all services to the customer and save the ID of the chosen service. 1. Run [queryAvailability()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/availability-calendar/query-availability.md). Make sure to provide the relevant `serviceId`, `startDate` and `endDate` as filters. 1. Display the available time slots to the customer and let them select their preferred `slot`. 1. Invoke [createBooking()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/bookings/create-booking.md). Pass `startDate`, `endDate`, `resource` and `location` from the selected slot in `booking.bookedEntity.slot`. If the slot's availability hasn't changed since running queryAvailability(), the function succeeds and the status of the booking is `CREATED`. ### Part 2: Handle the payment process with [Wix eCommerce](https://dev.wix.com/docs/velo/api-reference/wix-ecom-backend/introduction.md) 1. Run [createCheckout()](https://dev.wix.com/docs/velo/api-reference/wix-ecom-backend/checkout/create-checkout.md). Make sure to provide the [Wix Bookings app ID](https://dev.wix.com/docs/velo/articles/api-overview/about-apps-made-by-wix.md) as `catalogReference.appId` and the relevant booking ID as `catalogReference.catalogItemId`. Save the checkout ID. 1. Redirect the customer to the checkout page with [navigateToCheckoutPage()](https://dev.wix.com/docs/velo/api-reference/wix-ecom-frontend/navigate-to-checkout-page.md). Make sure to pass `checkoutId`. 1. Once the customer completes the checkout, Wix eCommerce automatically creates an [order](https://dev.wix.com/docs/velo/api-reference/wix-ecom-backend/orders/introduction.md) and the customer is charged. Alternatively, you could follow [these steps](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/bookings/sample-flows.md#api-reference_wix-bookings-v2_bookings_part-2-handle-the-payment-process-with-a-custom-checkout) to handle the payment process with a custom checkout. ## Book a class session Your code could display available class sessions to customers, let them choose a session, create the booking, and handle the payment process with a custom checkout. ### Part 1: Book a class session 1. Use [queryServices()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/services/query-services.md) and pass `{"type": "CLASS"}` as a filter to retrieve all classes. 1. Display all classes to the customer and save the ID of the chosen service. 1. Run [queryAvailability()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/availability-calendar/query-availability.md). Make sure to provide the relevant `serviceId`, `startDate` and `endDate` as filters. 1. Display the retrieved class sessions to the customer and let them select their preferred session. Make sure to save the corresponding `sessionId`. 1. Invoke [createBooking()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/bookings/create-booking.md) and pass the relevant `sessionId` in `booking.bookedEntity.slot.sessionId`. If the class session's availability hasn't changed since running queryAvailability(), the function succeeds and the status of the booking is `CREATED`. ### Part 2: Handle the payment process with a custom checkout 1. Implement your custom checkout and display the checkout page to the customer. 1. Once the customer completes the checkout, use [confirmOrDeclineBooking()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/bookings/confirm-or-decline-booking.md). Set `options.paymentStatus` to `PAID` to update the booking status to `CONFIRMED`. 1. Run [createOrder()](https://dev.wix.com/docs/velo/api-reference/wix-ecom-backend/orders/create-order.md) with your custom payment details. Alternatively, you could follow [these steps](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/bookings/sample-flows.md#api-reference_wix-bookings-v2_bookings_part-2-handle-the-payment-process-with-wix-ecommerce) to handle the payment process with Wix eCommerce. ## Book a course Your code could display available courses to customers, let them choose a service, and create the booking. To book a course: 1. Use [queryServices()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/services/query-services.md) and pass `{"type": "COURSE"}` as a filter to retrieve all courses. 1. Display all courses to the customer and save the ID of the chosen service and its `defaultCapacity`. 1. Retrieve all bookings for this service with [queryExtendedBookings()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/extended-bookings/query-extended-bookings.md). Make sure to provide `bookedEntity.item.schedule.serviceId` as a filter. 1. Sum up the values for `attendance.numberOfAttendees` from all returned extended bookings. This lets you know how many people have already booked a place in the course. 1. Subtract the total number of participants already booked from the service's `defaultCapacity`. This gives you the number of remaining spots for the course. 1. Let the customer choose how many participants they want to book. Make sure the intended `numberOfParticipants` doesn't exceed the number of remaining places. 1. Invoke [createBooking()](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/bookings/create-booking.md) and pass the relevant schedule ID as `booking.bookedEntity.scheduleId`. If the course's availability hasn't changed since running queryExtendedBookings(), the function succeeds and the status of the booking is `CREATED`. Then, you could [handle the payment process with Wix eCommerce](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/bookings/sample-flows.md#api-reference_wix-bookings-v2_bookings_part-2-handle-the-payment-process-with-wix-ecommerce) or [with a custom checkout](https://dev.wix.com/docs/velo/api-reference/wix-bookings-v2/bookings/sample-flows.md#api-reference_wix-bookings-v2_bookings_part-2-handle-the-payment-process-with-a-custom-checkout).
__Important:__ Running createBooking() can fail if the service is no longer available. You can ensure success, for example if you want to create a booking on behalf of the business owner. Then, run createBooking() with `options.flowControlSettings.skipAvailabilityValidation` set to `true`. Using other `flowControlSettings` lets you override the maximum number of participants per session, or allow unsupported payment methods for the service.