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-supported payment methods, along with Wix Pricing Plans.

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.

Part 1: Book an appointment

  1. Use queryServices() and pass {"type": "APPOINTMENT"} as a filter to retrieve all appointment-based services.
  2. Display all services to the customer and save the ID of the chosen service.
  3. Run queryAvailability(). Make sure to provide the relevant serviceId, startDate and endDate as filters.
  4. Display the available time slots to the customer and let them select their preferred slot.
  5. Invoke createBooking(). 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

  1. Run createCheckout(). Make sure to provide the Wix Bookings app ID as catalogReference.appId and the relevant booking ID as catalogReference.catalogItemId. Save the checkout ID.
  2. Redirect the customer to the checkout page with navigateToCheckoutPage(). Make sure to pass checkoutId.
  3. Once the customer completes the checkout, Wix eCommerce automatically creates an order and the customer is charged.

Alternatively, you could follow these steps 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() and pass {"type": "CLASS"} as a filter to retrieve all classes.
  2. Display all classes to the customer and save the ID of the chosen service.
  3. Run queryAvailability(). Make sure to provide the relevant serviceId, startDate and endDate as filters.
  4. Display the retrieved class sessions to the customer and let them select their preferred session. Make sure to save the corresponding sessionId.
  5. Invoke createBooking() 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.
  2. Once the customer completes the checkout, use confirmOrDeclineBooking(). Set options.paymentStatus to PAID to update the booking status to CONFIRMED.
  3. Run createOrder() with your custom payment details.

Alternatively, you could follow these steps 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() and pass {"type": "COURSE"} as a filter to retrieve all courses.
  2. Display all courses to the customer and save the ID of the chosen service and its defaultCapacity.
  3. Retrieve all bookings for this service with queryExtendedBookings(). Make sure to provide bookedEntity.item.schedule.serviceId as a filter.
  4. 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.
  5. Subtract the total number of participants already booked from the service's defaultCapacity. This gives you the number of remaining spots for the course.
  6. Let the customer choose how many participants they want to book. Make sure the intended numberOfParticipants doesn't exceed the number of remaining places.
  7. Invoke createBooking() 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 or 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.

Was this helpful?
Yes
No