Markeplace_Appointment_rescheduling
Markeplace Appointment Reschedulling
Whenever a customer utilizes the Marketplace (MP) interface to reschedule an appointment, it is essential for us to promptly notify SAAS of the customer's intention. Consequently, MP sends a request to SAAS, including the relevant details of the newly selected date and time for the replacement appointment. To provide a clearer understanding of the rescheduling process, let's outline the key entities involved below.
BookingRescheduleService
The primary service responsible for managing the rescheduling logic. It conducts a series of validations on the parameters to ensure the integrity of the params, old appointments to be removed, and new appointments with the updated date and time. When making a request, the payload includes the order_reference, which is the ID of an order containing one or more bookings. Each booking is identified by a bookingReference attribute, which is essential for maintaining the integrity and synchronization of SAAS and Marketplace bookings.
Using the order_reference, the service retrieves all the replacing_appointments that need to be rescheduled and applies the following validations:
- Time validation: The proposed new date and time must be in the future.
- Comparison of booking references with the params to ensure integrity.
- Check if all replacing appointments are reschedulable (in the correct state and not yet executed).
- Verify if the treatments of the replacing_appointments match the requested parameters.
The process continues with the creation of an Order object instance. To create the Order, it's essential to iterate through the booking parameters and create a hash that will be used by the SimpleBooking class to generate booking instances using the _map_bookings method. Here's an example of this hash:
{
service_id: 'vtg_6731',
booking_reference: 'bk_40016355',
price: 12.5,
slot_metadata: 'eyJtcCI6W3sidnQiOls0MTk5MDhdLCJtIjoyNTI5MTJ9XSwicyI6W3sidnQiOjQxOTkwOCwic20iOls1Mjg1Nyw1Mjg2OSw1Mjg3MF0sInciOltdfV19',
is_direct_booking: false,
customer: {
full_name: 'John Doe',
first_name: 'John',
last_name: 'Doe',
email: '[email protected],
phone: '+3918818818',
marketing_consent_given: true,
},
discount: {
amount: 12.5,
kind: nil
},
time: {
date: '22/02/2013',
start_time: '14:30'
}
}
For each booking, corresponding appointments are instantiated based on venue_treatment, staff_member, and promotion information. Some necessary details, such as treatment duration and customer attributes, are fetched from previous appointments, while others are parsed from an important attribute called slot_metadata (refer to the section for more information). The appointments are then validated to check the availability of staff members and workstations. If everything is set, these appointments are saved, and the old ones are deleted. If any of these appointments are eligible for promotions, they will be applied, including calculating discounts and other related actions.
At the end of the process, if no errors occurred during execution, the service responds with a truthy value and completes the rescheduling.
Booking Reschedule Request
The request is sent to the following endpoint in the Tw-integration app:
PUT: /{order_reference}/reschedule
{
"date": "2023-06-13",
"startTime": "17:00",
"bookings": [
{
"bookingReference": "bk_40016355",
"serviceId": "vtg_6731",
"serviceOptionIds": [
"419908-default"
],
"slotMetadata": "eyJtcCI6W3sidnQiOls
0MTk5MDhdLCJtIjoyNTI5MTJ9XSwicyI6W3sidnQiOjQxOTkwOCwic20iOls1Mjg1Nyw1Mjg2OSw1Mjg3MF0sInciOltdfV19"
},
{
"bookingReference": "bk_40016356",
"serviceId": "vtg_4",
"serviceOptionIds": [
"cf0dee038f9286d41415802a25138c803ab36a46c027ec2424787b90a0bdb3c3"
],
"slotMetadata": "eyJtcCI6W3sidnQiOls0MTk4MzVdLCJtIjoyNTI5MDR9XSwicyI6W3sidnQiOjQxOTgzNSwic20iOls1Mjg1N10sInciOltdfV19"
}
],
"format": "json",
"controller": "bookings",
"action": "reschedule",
"order_reference": "T465584363",
"booking": {
"date": "2023-06-13",
"startTime": "17:00",
"bookings": [
{
"bookingReference": "bk_40016355",
"serviceId": "vtg_6731",
"serviceOptionIds": [
"419908-default"
],
"slotMetadata": "eyJtcCI6W3sidnQiOls0MTk5MDhdLCJtIjoyNTI5MTJ9XSwicyI6W3sidnQiOjQxOTkwOCwic20iOls1Mjg1Nyw1Mjg2OSw1Mjg3MF0sInciOltdfV19"
},
{
"bookingReference": "bk_40016356",
"serviceId": "vtg_4",
"serviceOptionIds": [
"cf0dee038f9286d41415802a25138c803ab36a46c027ec2424787b90a0bdb3c3"
],
"slotMetadata": "eyJtcCI6W3sidnQiOls0MTk4MzVdLCJtIjoyNTI5MDR9XSwicyI6W3sidnQiOjQxOTgzNSwic20iOls1Mjg1N10sInciOltdfV19"
}
]
}
}
This request is processed by the BookingsController, which parses the parameters and invokes the Treatwell::BookingRescheduleService.
Order
Based on the parameters and the replacing_appointments retrieved using the order_reference, we map the bookings and instantiate the Order object. The Order object contains order items (OrderItem), with each item corresponding to a booking and potentially having an associated promotion. Most of the OrderItem information is extracted from the slot metadata, such as the treatment and suggested promotion. For each item, a cart is instantiated, which is required to perform promotion research using the MarketingPromotions::FrontendFinderService. Once the appropriate promotion is identified, each order item undergoes a transformation, becoming an Appointment that becomes part of the reschedule order as a whole.
SlotMetadata
Since we do not receive the exact start_time for each booking during rescheduling, we utilize service information parsed by TimeSlotMetadata to retrieve old appointments and infer, based on the venue treatment duration property, when one appointment follows another. Additional details such as user, API key, and payment information are obtained from previous appointments. Every time slot (e.g., 15 minutes) has a slot_metadata generated by the SAAS when querying availability. The slot_metadata is a base64-encoded hash containing information about the staff_member, venue_treatment, and promotions for that particular time slot. This approach ensures a more accurate correlation between availability and actual booking requests. The SAAS decodes the slot_metadata to extract important information used to fulfill the requirements for booking creation during the rescheduling process.